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{
7 private int m_max_item_width;
8 private int m_count;
9 const int ITEMS_COUNT = 27;
10 //--------------------------------------------------------------------------
12 {
14 m_count = 0;
15 }
16 //--------------------------------------------------------------------------
18 {
19 Clear();
20
22 }
23 //--------------------------------------------------------------------------
24 void Init(Widget layoutRoot)
25 {
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");
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
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 //--------------------------------------------------------------------------
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;
228 }
229};
void Call()
Definition tools.c:30
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:24
void Show(int x, int y)
Definition contextmenu.c:36
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.
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
Icon x
Icon y