Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
contextmenu.c
Go to the documentation of this file.
1
//--------------------------------------------------------------------------
2
class
ContextMenu
extends
ScriptedWidgetEventHandler
3
{
4
protected
static
ref
ContextMenu
m_ContextMenuInstance
;
5
6
Widget
m_context_menu_root_widget
;
7
private
Widget
m_context_menu_panel_widget
;
8
private
ref
array<ref CallQueueContext>
m_commands
;
9
private
int
m_max_item_width
;
10
private
int
m_count
;
11
private
bool
m_builtIn
=
false
;
12
const
int
ITEMS_COUNT
= 27;
13
14
//--------------------------------------------------------------------------
15
void
ContextMenu
()
16
{
17
m_commands
=
new
array<ref CallQueueContext>
;
18
m_count
= 0;
19
}
20
//--------------------------------------------------------------------------
21
void
~ContextMenu
()
22
{
23
Clear
();
24
25
delete
m_context_menu_root_widget
;
26
}
27
//--------------------------------------------------------------------------
28
void
Init
(
Widget
layoutRoot,
bool
builtIn =
false
)
29
{
30
m_builtIn
= builtIn;
31
if
(!
m_context_menu_root_widget
)
32
{
33
m_context_menu_root_widget
=
g_Game
.GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout"
, layoutRoot);
34
m_context_menu_panel_widget
=
m_context_menu_root_widget
.FindAnyWidget(
"PanelWidget"
);
35
m_context_menu_root_widget
.Show(
false
);
36
m_context_menu_root_widget
.SetHandler(
this
);
37
}
38
}
39
40
//--------------------------------------------------------------------------
41
void
Show
(
int
x
,
int
y
)
42
{
43
if
(
m_count
== 0)
return
;
44
int
screen_w, screen_h;
45
float
w, h;
46
float
sx, sy;
47
int
offset_x;
// = -20;
48
int
offset_y;
// = -10;
49
50
GetScreenSize
(screen_w, screen_h);
51
52
// align buttons
53
float
button_height_percent = 0.02;
// button height is 4% of screen height
54
float
button_height = screen_h * button_height_percent;
55
56
for
(
int
i = 0; i <
m_count
; i++)
57
{
58
ButtonWidget menu_button = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
String
(
"Button"
+ (i+1).
ToString
() ) ) );
59
if
(menu_button)
60
{
61
menu_button.SetSize(0.90, button_height);
62
menu_button.Show(
true
);
63
}
64
}
65
66
67
AutoHeightSpacer
spacer;
68
m_context_menu_panel_widget
.GetScript(spacer);
69
if
( spacer )
70
{
71
spacer.
Update
();
72
}
73
74
m_context_menu_root_widget
.GetSize(w, h);
75
m_context_menu_panel_widget
.GetSize(sx, sy);
76
m_context_menu_root_widget
.SetSize(w, sy);
77
78
// set position
79
m_context_menu_root_widget
.GetScreenSize(w,h);
80
screen_w -= 10;
81
screen_h -= 10;
82
83
int
right_edge =
x
+ w - offset_x;
84
if
(right_edge > screen_w)
85
{
86
x
= screen_w - w - offset_x;
87
}
88
else
89
{
90
x
=
x
+ offset_x;
91
}
92
93
int
bottom_edge =
y
+ h - offset_y;
94
if
(bottom_edge > screen_h)
95
{
96
y
=
y
- h - offset_y;
97
}
98
else
99
{
100
y
=
y
+ offset_y;
101
}
102
103
m_context_menu_root_widget
.SetPos(
x
,
y
);
104
m_context_menu_root_widget
.Show(
true
);
105
}
106
//--------------------------------------------------------------------------
107
void
SetSize
(
float
x
,
float
y
)
108
{
109
m_context_menu_root_widget
.SetSize(
x
,
y
);
110
}
111
112
//--------------------------------------------------------------------------
113
void
ShowBackdrop
(
bool
show)
114
{
115
if
(show ==
true
)
116
{
117
m_context_menu_root_widget
.FindAnyWidget(
"BackdropImageWidget"
).Show(
true
);
118
}
119
else
120
{
121
m_context_menu_root_widget
.FindAnyWidget(
"BackdropImageWidget"
).Show(
false
);
122
}
123
}
124
125
//--------------------------------------------------------------------------
126
void
Hide
()
127
{
128
m_context_menu_root_widget
.Show(
false
);
129
130
Clear
();
131
}
132
133
//--------------------------------------------------------------------------
134
bool
IsVisible
()
135
{
136
return
m_context_menu_root_widget
.IsVisible();
137
}
138
139
//--------------------------------------------------------------------------
140
override
bool
OnMouseLeave
(
Widget
w,
Widget
enterW,
int
x
,
int
y
)
141
{
142
super.OnMouseLeave(w, enterW,
x
,
y
);
143
144
if
( !
m_builtIn
&& enterW &&
m_context_menu_panel_widget
&& enterW !=
m_context_menu_panel_widget
&& enterW.GetParent() !=
m_context_menu_panel_widget
)
145
{
146
Hide
();
147
return
true
;
148
}
149
return
false
;
150
}
151
152
//--------------------------------------------------------------------------
153
override
bool
OnMouseButtonDown
(
Widget
w,
int
x
,
int
y
,
int
button)
154
{
155
super.OnMouseButtonDown(w,
x
,
y
, button);
156
157
if
(button ==
MouseState
.LEFT && w.GetUserID() > -1 && w.GetUserID() <
m_commands
.Count())
158
{
159
CallQueueContext
ctx =
m_commands
.Get(w.GetUserID());
160
161
int
actionId =
Param3<EntityAI, int, int>
.Cast(ctx.
m_params
).param2;
162
if
(actionId ==
EActions
.DELETE)
163
Hide
();
164
165
UIScriptedMenu
menu =
g_Game
.GetUIManager().GetMenu();
166
if
(menu)
167
g_Game
.GetCallQueue(
CALL_CATEGORY_GUI
).Call(menu.
Refresh
);
168
169
ctx.
Call
();
170
171
return
true
;
172
}
173
174
return
false
;
175
}
176
177
//--------------------------------------------------------------------------
178
void
Add
(
string
label,
Class
obj,
string
fn_name,
Param
params)
179
{
180
AddEx
(label, FadeColors.LIGHT_GREY, obj, fn_name, params);
181
}
182
183
void
AddEx
(
string
label,
int
labelColor,
Class
obj,
string
funcName,
Param
params)
184
{
185
int
count =
Count
();
186
ButtonWidget menuButton = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
string
.Format(
"Button%1"
, count + 1)));
187
if
(menuButton)
188
{
189
label.
ToUpper
();
190
menuButton.SetText(label);
191
menuButton.SetTextColor(labelColor);
192
menuButton.Show(
true
);
193
194
if
(funcName ==
""
)
195
{
196
menuButton.SetFlags(menuButton.GetFlags() |
WidgetFlags
.IGNOREPOINTER);
197
}
198
else
199
{
200
menuButton.ClearFlags(
WidgetFlags
.IGNOREPOINTER);
201
}
202
203
int
itemWidth = label.
Length
();
204
if
(
m_max_item_width
< itemWidth)
205
m_max_item_width
= itemWidth;
206
}
207
208
m_count
++;
209
m_commands
.Insert(
new
CallQueueContext
(obj, funcName, params));
210
}
211
212
//--------------------------------------------------------------------------
213
void
Remove
(
int
index)
214
{
215
if
(index <
m_commands
.Count())
216
{
217
m_commands
.RemoveOrdered(index);
218
ButtonWidget menu_button = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
String
(
"Button"
+ ( index + 1 ).
ToString
() ) ) );
219
menu_button.Show(
false
);
220
menu_button.SetText(
""
);
221
m_count
--;
222
}
223
}
224
225
//--------------------------------------------------------------------------
226
int
Count
()
227
{
228
return
m_commands
.Count();
229
}
230
231
//--------------------------------------------------------------------------
232
void
Clear
()
233
{
234
int
i;
235
236
m_commands
.Clear();
237
238
if
(!
m_context_menu_panel_widget
)
239
return
;
240
Widget
child =
m_context_menu_panel_widget
.GetChildren();
241
while
(child)
242
{
243
ButtonWidget button = ButtonWidget.Cast(child);
244
if
(button)
245
{
246
button.Show(
false
);
247
}
248
child = child.GetSibling();
249
250
251
}
252
m_count
= 0;
253
m_max_item_width
= 0;
254
}
255
256
void
BuildContextMenu
(notnull
EntityAI
entity, notnull
Widget
rootWidget,
Class
target)
257
{
258
Clear
();
259
260
TSelectableActionInfoArrayEx customActions =
new
TSelectableActionInfoArrayEx();
261
entity.GetDebugActions(customActions);
262
263
int
actionsCount = customActions.Count();
264
for
(
int
i = 0; i < customActions.Count(); i++)
265
{
266
TSelectableActionInfoWithColor
actionInfo =
TSelectableActionInfoWithColor
.Cast(customActions.Get(i));
267
if
(actionInfo)
268
{
269
int
actionId = actionInfo.param2;
270
int
textColor = actionInfo.param4;
271
string
actionText = actionInfo.param3;
272
273
if
(actionId ==
EActions
.SEPARATOR)
274
AddEx
(actionText, textColor, null,
""
, null);
275
else
276
AddEx
(actionText, textColor, target,
"OnSelectAction"
,
new
Param3<EntityAI, int, int>
(entity, actionId, textColor));
277
}
278
}
279
}
280
281
//--------------------------------------------------------------------------
282
static
void
DisplayContextMenu
(
int
x
,
int
y
, notnull
EntityAI
entity, notnull
Widget
rootWidget,
Class
target)
283
{
284
m_ContextMenuInstance
=
new
ContextMenu
();
285
if
(
m_ContextMenuInstance
)
286
{
287
m_ContextMenuInstance
.Init(rootWidget);
288
m_ContextMenuInstance
.BuildContextMenu(entity, rootWidget, target);
289
290
m_ContextMenuInstance
.SetSize(1,1);
291
m_ContextMenuInstance
.Show(
x
,
y
);
292
}
293
}
294
295
};
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition
entityai.c:104
AutoHeightSpacer
Definition
autoheightspacer.c:3
AutoHeightSpacer::Update
void Update()
Definition
autoheightspacer.c:11
CallQueueContext
Definition
tools.c:16
CallQueueContext::Call
void Call()
Definition
tools.c:30
CallQueueContext::m_params
ref Param m_params
Definition
tools.c:19
Class
Super root of all classes in Enforce script.
Definition
enscript.c:11
EntityAI
Definition
inventoryitem.c:2
Param3
Definition
entityai.c:102
Param
Base Param Class with no parameters.
Definition
param.c:12
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition
enwidgets.c:657
ScriptedWidgetEventHandler::m_commands
ref array< ref CallQueueContext > m_commands
Definition
contextmenu.c:6
ScriptedWidgetEventHandler::Count
int Count()
Definition
contextmenu.c:202
ScriptedWidgetEventHandler::Hide
void Hide()
Definition
contextmenu.c:126
ScriptedWidgetEventHandler::m_context_menu_root_widget
Widget m_context_menu_root_widget
Definition
contextmenu.c:4
ScriptedWidgetEventHandler::m_context_menu_panel_widget
Widget m_context_menu_panel_widget
Definition
contextmenu.c:5
ScriptedWidgetEventHandler::Init
void Init(Widget layoutRoot, bool builtIn=false)
Definition
contextmenu.c:28
ScriptedWidgetEventHandler::BuildContextMenu
void BuildContextMenu(notnull EntityAI entity, notnull Widget rootWidget, Class target)
Definition
contextmenu.c:256
ScriptedWidgetEventHandler::OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition
contextmenu.c:140
ScriptedWidgetEventHandler::Remove
void Remove(int index)
Definition
contextmenu.c:213
ScriptedWidgetEventHandler::Show
void Show(int x, int y)
Definition
contextmenu.c:41
ScriptedWidgetEventHandler::Add
void Add(string label, Class obj, string fn_name, Param params)
Definition
contextmenu.c:178
ScriptedWidgetEventHandler::DisplayContextMenu
static void DisplayContextMenu(int x, int y, notnull EntityAI entity, notnull Widget rootWidget, Class target)
Definition
contextmenu.c:282
ScriptedWidgetEventHandler::m_ContextMenuInstance
static ref ContextMenu m_ContextMenuInstance
Definition
contextmenu.c:4
ScriptedWidgetEventHandler::SetSize
void SetSize(float x, float y)
Definition
contextmenu.c:107
ScriptedWidgetEventHandler::m_builtIn
bool m_builtIn
Definition
contextmenu.c:11
ScriptedWidgetEventHandler::AddEx
void AddEx(string label, int labelColor, Class obj, string funcName, Param params)
Definition
contextmenu.c:166
ScriptedWidgetEventHandler::ContextMenu
void ContextMenu()
Definition
contextmenu.c:11
ScriptedWidgetEventHandler::m_max_item_width
int m_max_item_width
Definition
contextmenu.c:7
ScriptedWidgetEventHandler::Clear
void Clear()
Definition
contextmenu.c:208
ScriptedWidgetEventHandler::ShowBackdrop
void ShowBackdrop(bool show)
Definition
contextmenu.c:113
ScriptedWidgetEventHandler::OnMouseButtonDown
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition
contextmenu.c:153
ScriptedWidgetEventHandler::~ContextMenu
void ~ContextMenu()
Definition
contextmenu.c:21
ScriptedWidgetEventHandler::ITEMS_COUNT
const int ITEMS_COUNT
Definition
contextmenu.c:9
ScriptedWidgetEventHandler::m_count
int m_count
Definition
contextmenu.c:8
ScriptedWidgetEventHandler::IsVisible
bool IsVisible()
Definition
contextmenu.c:134
UIScriptedMenu
Xbox menu.
Definition
dayzgame.c:64
UIScriptedMenu::Refresh
override void Refresh()
Definition
chatinputmenu.c:70
Widget
Definition
enwidgets.c:190
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
EActions
EActions
Definition
eactions.c:2
ToString
proto string ToString()
String
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition
enscript.c:339
MouseState
MouseState
Definition
ensystem.c:311
GetScreenSize
proto void GetScreenSize(out int x, out int y)
string::ToUpper
proto int ToUpper()
Changes string to uppercase.
string::Length
proto native int Length()
Returns length of string.
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition
tools.c:9
WidgetFlags
WidgetFlags
Definition
enwidgets.c:58
x
Icon x
y
Icon y
Games
Dayz
scripts
4_world
classes
contextmenu.c
Generated by
1.17.0