DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ContextMenu.c
См. документацию.
1//--------------------------------------------------------------------------
2class ContextMenu extends ScriptedWidgetEventHandler
3{
4 protected static ref ContextMenu m_ContextMenuInstance;
5
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 //--------------------------------------------------------------------------
16 {
18 m_count = 0;
19 }
20 //--------------------------------------------------------------------------
22 {
23 Clear();
24
26 }
27 //--------------------------------------------------------------------------
28 void Init(Widget layoutRoot, bool builtIn = false)
29 {
30 m_builtIn = builtIn;
32 {
33 m_context_menu_root_widget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_inventory_context_menu.layout", layoutRoot);
34 m_context_menu_panel_widget = m_context_menu_root_widget.FindAnyWidget("PanelWidget");
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
105 }
106 //--------------------------------------------------------------------------
107 void SetSize(float x, float y)
108 {
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 //--------------------------------------------------------------------------
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
166 if (menu)
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
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;
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 {
286 {
287 m_ContextMenuInstance.Init(rootWidget);
288 m_ContextMenuInstance.BuildContextMenu(entity, rootWidget, target);
289
290 m_ContextMenuInstance.SetSize(1,1);
292 }
293 }
294
295};
Param4< int, int, string, int > TSelectableActionInfoWithColor
Определения EntityAI.c:97
EActions
Определения EActions.c:2
proto string ToString()
Icon x
Icon y
void Update()
Определения AutoHeightSpacer.c:11
proto native UIManager GetUIManager()
override ScriptCallQueue GetCallQueue(int call_category)
Определения DayZGame.c:1187
proto native WorkspaceWidget GetWorkspace()
ref Param m_params
Определения tools.c:19
void Call()
Определения tools.c:30
Определения tools.c:16
Super root of all classes in Enforce script.
Определения EnScript.c:11
Определения Building.c:6
Определения EntityAI.c:95
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Определения param.c:12
proto void Call(func fn, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
void ShowBackdrop(bool show)
Определения ContextMenu.c:113
Widget m_context_menu_root_widget
Определения ContextMenu.c:6
void BuildContextMenu(notnull EntityAI entity, notnull Widget rootWidget, Class target)
Определения ContextMenu.c:256
void Hide()
Определения ContextMenu.c:126
bool m_builtIn
Определения ContextMenu.c:11
void ~ContextMenu()
Определения ContextMenu.c:21
int m_max_item_width
Определения ContextMenu.c:9
int m_count
Определения ContextMenu.c:10
void Clear()
Определения ContextMenu.c:232
static void DisplayContextMenu(int x, int y, notnull EntityAI entity, notnull Widget rootWidget, Class target)
Определения ContextMenu.c:282
void SetSize(float x, float y)
Определения ContextMenu.c:107
const int ITEMS_COUNT
Определения ContextMenu.c:12
static ref ContextMenu m_ContextMenuInstance
Определения ContextMenu.c:4
int Count()
Определения ContextMenu.c:226
void AddEx(string label, int labelColor, Class obj, string funcName, Param params)
Определения ContextMenu.c:183
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения ContextMenu.c:140
void Add(string label, Class obj, string fn_name, Param params)
Определения ContextMenu.c:178
void Show(int x, int y)
Определения ContextMenu.c:41
Widget m_context_menu_panel_widget
Определения ContextMenu.c:7
bool IsVisible()
Определения ContextMenu.c:134
void Init(Widget layoutRoot, bool builtIn=false)
Определения ContextMenu.c:28
void Remove(int index)
Определения ContextMenu.c:213
ref array< ref CallQueueContext > m_commands
Определения ContextMenu.c:8
void ContextMenu()
Определения ContextMenu.c:15
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Определения ContextMenu.c:153
map: item x vector(index, width, height)
Определения EnWidgets.c:651
proto native UIScriptedMenu GetMenu()
Returns most-top open menu.
override void Refresh()
Определения ChatInputMenu.c:70
Определения DayZGame.c:64
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Определения EnScript.c:339
MouseState
Определения EnSystem.c:311
proto void GetScreenSize(out int x, out int y)
proto native int Length()
Returns length of string.
proto int ToUpper()
Changes string to uppercase. Returns length.
const int CALL_CATEGORY_GUI
Определения tools.c:9
WidgetFlags
Определения EnWidgets.c:58
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.