Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
contextmenu.c
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2class 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 //--------------------------------------------------------------------------
13 {
15 m_count = 0;
16 }
17 //--------------------------------------------------------------------------
19 {
20 Clear();
21
23 }
24 //--------------------------------------------------------------------------
25 void Init(Widget layoutRoot)
26 {
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");
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
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 //--------------------------------------------------------------------------
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;
236 }
237};
void Call()
Definition tools.c:30
ref Param m_params
Definition tools.c:19
Super root of all classes in Enforce script.
Definition enscript.c:11
Base Param Class with no parameters.
Definition param.c:12
map: item x vector(index, width, height)
Definition enwidgets.c:657
ref array< ref CallQueueContext > m_commands
Definition contextmenu.c:6
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void Init(Widget layoutRoot)
Definition contextmenu.c:25
void Show(int x, int y)
Definition contextmenu.c:37
void Add(string label, Class obj, string fn_name, Param params)
void AddEx(string label, int labelColor, Class obj, string funcName, Param params)
void ShowBackdrop(bool show)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Xbox menu.
Definition dayzgame.c:64
override void Refresh()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
EActions
Definition eactions.c:2
proto string ToString()
DayZGame GetGame()
Definition gameplay.c:636
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition enscript.c:339
MouseState
Definition ensystem.c:311
proto void GetScreenSize(out int x, out int y)
proto int ToUpper()
Changes string to uppercase.
proto native int Length()
Returns length of string.
const int CALL_CATEGORY_GUI
Definition tools.c:9
WidgetFlags
Definition enwidgets.c:58
WorkspaceWidget Widget
Defined in code.
Icon x
Icon y