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
private
Widget
m_context_menu_root_widget;
5
private
Widget
m_context_menu_panel_widget;
6
private
ref array<ref CallQueueContext> m_commands;
7
private
int
m_max_item_width;
8
private
int
m_count;
9
const
int
ITEMS_COUNT = 27;
10
11
//--------------------------------------------------------------------------
12
void
ContextMenu
()
13
{
14
m_commands
=
new
array<ref CallQueueContext>
;
15
m_count
= 0;
16
}
17
//--------------------------------------------------------------------------
18
void
~ContextMenu
()
19
{
20
Clear
();
21
22
delete
m_context_menu_root_widget
;
23
}
24
//--------------------------------------------------------------------------
25
void
Init
(
Widget
layoutRoot)
26
{
27
if
(!
m_context_menu_root_widget
)
28
{
29
m_context_menu_root_widget
=
GetGame
().GetWorkspace().CreateWidgets(
"gui/layouts/day_z_inventory_context_menu.layout"
, layoutRoot);
30
m_context_menu_panel_widget
=
m_context_menu_root_widget
.FindAnyWidget(
"PanelWidget"
);
31
m_context_menu_root_widget
.Show(
false
);
32
m_context_menu_root_widget
.SetHandler(
this
);
33
}
34
}
35
36
//--------------------------------------------------------------------------
37
void
Show
(
int
x
,
int
y
)
38
{
39
if
(
m_count
== 0)
return
;
40
int
screen_w, screen_h;
41
float
w, h;
42
float
sx, sy;
43
int
offset_x;
// = -20;
44
int
offset_y;
// = -10;
45
46
GetScreenSize
(screen_w, screen_h);
47
48
// align buttons
49
float
button_height_percent = 0.02;
// button height is 4% of screen height
50
float
button_height = screen_h * button_height_percent;
51
52
for
(
int
i = 0; i <
m_count
; i++)
53
{
54
ButtonWidget menu_button = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
String
(
"Button"
+ (i+1).
ToString
() ) ) );
55
if
(menu_button)
56
{
57
menu_button.SetSize(0.90, button_height);
58
menu_button.Show(
true
);
59
}
60
}
61
62
63
AutoHeightSpacer
spacer;
64
m_context_menu_panel_widget
.GetScript(spacer);
65
if
( spacer )
66
{
67
spacer.
Update
();
68
}
69
70
m_context_menu_root_widget
.GetSize(w, h);
71
m_context_menu_panel_widget
.GetSize(sx, sy);
72
m_context_menu_root_widget
.SetSize(w, sy);
73
74
// set position
75
m_context_menu_root_widget
.GetScreenSize(w,h);
76
screen_w -= 10;
77
screen_h -= 10;
78
79
int
right_edge =
x
+ w - offset_x;
80
if
(right_edge > screen_w)
81
{
82
x
= screen_w - w - offset_x;
83
}
84
else
85
{
86
x
=
x
+ offset_x;
87
}
88
89
int
bottom_edge =
y
+ h - offset_y;
90
if
(bottom_edge > screen_h)
91
{
92
y
=
y
- h - offset_y;
93
}
94
else
95
{
96
y
=
y
+ offset_y;
97
}
98
99
m_context_menu_root_widget
.SetPos(
x
,
y
);
100
m_context_menu_root_widget
.Show(
true
);
101
}
102
103
//--------------------------------------------------------------------------
104
void
ShowBackdrop
(
bool
show)
105
{
106
if
(show ==
true
)
107
{
108
m_context_menu_root_widget
.FindAnyWidget(
"BackdropImageWidget"
).Show(
true
);
109
}
110
else
111
{
112
m_context_menu_root_widget
.FindAnyWidget(
"BackdropImageWidget"
).Show(
false
);
113
}
114
}
115
116
//--------------------------------------------------------------------------
117
void
Hide
()
118
{
119
m_context_menu_root_widget
.Show(
false
);
120
121
Clear
();
122
}
123
124
//--------------------------------------------------------------------------
125
bool
IsVisible
()
126
{
127
return
m_context_menu_root_widget
.IsVisible();
128
}
129
130
//--------------------------------------------------------------------------
131
override
bool
OnMouseLeave
(
Widget
w,
Widget
enterW,
int
x
,
int
y
)
132
{
133
super.OnMouseLeave(w, enterW,
x
,
y
);
134
135
if
( enterW &&
m_context_menu_panel_widget
&& enterW !=
m_context_menu_panel_widget
&& enterW.GetParent() !=
m_context_menu_panel_widget
)
136
{
137
Hide
();
138
return
true
;
139
}
140
return
false
;
141
}
142
143
//--------------------------------------------------------------------------
144
override
bool
OnMouseButtonDown
(
Widget
w,
int
x
,
int
y
,
int
button)
145
{
146
super.OnMouseButtonDown(w,
x
,
y
, button);
147
148
if
(button ==
MouseState
.LEFT && w.GetUserID() > -1 && w.GetUserID() <
m_commands
.Count())
149
{
150
CallQueueContext
ctx =
m_commands
.Get(w.GetUserID());
151
152
int
actionId =
Param3<ItemBase, int, int>
.Cast(ctx.
m_params
).param2;
153
if
(actionId ==
EActions
.DELETE)
154
Hide
();
155
156
UIScriptedMenu
menu =
GetGame
().GetUIManager().GetMenu();
157
if
(menu)
158
GetGame
().GetCallQueue(
CALL_CATEGORY_GUI
).Call(menu.
Refresh
);
159
160
ctx.
Call
();
161
162
return
true
;
163
}
164
165
return
false
;
166
}
167
168
//--------------------------------------------------------------------------
169
void
Add
(
string
label,
Class
obj,
string
fn_name,
Param
params)
170
{
171
AddEx
(label, FadeColors.LIGHT_GREY, obj, fn_name, params);
172
}
173
174
void
AddEx
(
string
label,
int
labelColor,
Class
obj,
string
funcName,
Param
params)
175
{
176
int
count =
Count
();
177
ButtonWidget menuButton = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
string
.Format(
"Button%1"
, count + 1)));
178
if
(menuButton)
179
{
180
label.
ToUpper
();
181
menuButton.SetText(label);
182
menuButton.SetTextColor(labelColor);
183
menuButton.Show(
true
);
184
if
(!funcName)
185
menuButton.SetFlags(menuButton.GetFlags() |
WidgetFlags
.IGNOREPOINTER);
186
187
int
itemWidth = label.
Length
();
188
if
(
m_max_item_width
< itemWidth)
189
m_max_item_width
= itemWidth;
190
}
191
192
m_count
++;
193
m_commands
.Insert(
new
CallQueueContext
(obj, funcName, params));
194
}
195
196
//--------------------------------------------------------------------------
197
void
Remove
(
int
index)
198
{
199
if
(index <
m_commands
.Count())
200
{
201
m_commands
.RemoveOrdered(index);
202
ButtonWidget menu_button = ButtonWidget.Cast(
m_context_menu_root_widget
.FindAnyWidget(
String
(
"Button"
+ ( index + 1 ).
ToString
() ) ) );
203
menu_button.Show(
false
);
204
menu_button.SetText(
""
);
205
m_count
--;
206
}
207
}
208
209
//--------------------------------------------------------------------------
210
int
Count
()
211
{
212
return
m_commands
.Count();
213
}
214
215
//--------------------------------------------------------------------------
216
void
Clear
()
217
{
218
int
i;
219
220
m_commands
.Clear();
221
222
Widget
child =
m_context_menu_panel_widget
.GetChildren();
223
while
(child)
224
{
225
ButtonWidget button = ButtonWidget.Cast(child);
226
if
(button)
227
{
228
button.Show(
false
);
229
}
230
child = child.GetSibling();
231
232
233
}
234
m_count
= 0;
235
m_max_item_width
= 0;
236
}
237
};
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
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:117
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::OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition
contextmenu.c:131
ScriptedWidgetEventHandler::Remove
void Remove(int index)
Definition
contextmenu.c:197
ScriptedWidgetEventHandler::Init
void Init(Widget layoutRoot)
Definition
contextmenu.c:25
ScriptedWidgetEventHandler::Show
void Show(int x, int y)
Definition
contextmenu.c:37
ScriptedWidgetEventHandler::Add
void Add(string label, Class obj, string fn_name, Param params)
Definition
contextmenu.c:169
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:12
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:104
ScriptedWidgetEventHandler::OnMouseButtonDown
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition
contextmenu.c:144
ScriptedWidgetEventHandler::~ContextMenu
void ~ContextMenu()
Definition
contextmenu.c:18
ScriptedWidgetEventHandler::m_count
int m_count
Definition
contextmenu.c:8
ScriptedWidgetEventHandler::IsVisible
bool IsVisible()
Definition
contextmenu.c:125
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
EActions
EActions
Definition
eactions.c:2
ToString
proto string ToString()
GetGame
DayZGame GetGame()
Definition
gameplay.c:636
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
Widget
WorkspaceWidget Widget
Defined in code.
x
Icon x
y
Icon y
Games
Dayz
scripts
5_mission
gui
contextmenu.c
Generated by
1.17.0