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