Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapToolMenuUI.c
Go to the documentation of this file.
2class SCR_MapToolEntry : Managed
4 protected bool m_bToolActive;
5 protected bool m_bIsEnabled = true;
6 protected bool m_bIsVisible = true;
7 protected bool m_bIsExclusiveEntry = false;
15
19
20 //------------------------------------------------------------------------------------------------
23 {
24 return s_OnEntryToggled;
25 }
26
27 //------------------------------------------------------------------------------------------------
29 {
32
34 }
35
36 //------------------------------------------------------------------------------------------------
38 {
41 }
42
43 //------------------------------------------------------------------------------------------------
45 void SetActive(bool toolActive)
46 {
47 m_bToolActive = toolActive;
49 }
50
51 //------------------------------------------------------------------------------------------------
54 {
55 return m_bToolActive;
56 }
57
58 //------------------------------------------------------------------------------------------------
60 void SetEnabled(bool isEnabled)
61 {
62 m_bIsEnabled = isEnabled;
64 }
65
66 //------------------------------------------------------------------------------------------------
69 {
70 return m_bIsEnabled;
71 }
72
73 //------------------------------------------------------------------------------------------------
75 void SetVisible(bool state)
76 {
77 m_bIsVisible = state;
79 }
80
81 //------------------------------------------------------------------------------------------------
83 void SetButtonSoundsDisabled(bool state)
84 {
86 }
87
88 //------------------------------------------------------------------------------------------------
91 {
92 if (!m_ButtonComp) // handler might not be updated yet when the set is attempted
93 return;
94
95 if (m_bToolActive)
96 {
97 SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
98 SetBackgroundColor(Color.FromInt(UIColors.CONTRAST_DEFAULT.PackToInt()));
99 }
100 else
101 {
102 SetColor(Color.FromInt(UIColors.WHITE_DISABLED.PackToInt()));
103 SetBackgroundColor(Color.FromInt(Color.Black.PackToInt()));
104 }
105
106 if (m_bIsEnabled)
107 SetBorderColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
108 else
109 SetBorderColor(Color.FromInt(UIColors.IDLE_DISABLED.PackToInt()));
110
111 m_ButtonComp.GetRootWidget().SetVisible(m_bIsVisible);
112 }
114 //------------------------------------------------------------------------------------------------
117 protected void SetColor(notnull Color color)
118 {
119 m_ButtonComp.m_wImage.SetColor(color);
120 }
122 //------------------------------------------------------------------------------------------------
125 protected void SetBorderColor(notnull Color color)
126 {
127 m_ButtonComp.m_wBorder.SetColor(color);
128 }
130 //------------------------------------------------------------------------------------------------
133 protected void SetBackgroundColor(notnull Color color)
134 {
135 m_ButtonComp.SetBackgroundColor(color);
137
138 //------------------------------------------------------------------------------------------------
140 string GetImageSet()
141 {
142 return m_sIconQuad;
144
145 //------------------------------------------------------------------------------------------------
147 protected void OnClick()
148 {
150 {
151 if (m_bToolActive)
152 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_HIDE);
153 else
154 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_SHOW);
155 }
156
157 s_OnEntryToggled.Invoke(this);
158 m_OwnerMenu.DisableInactiveMapUIEntries(this);
159
160 if (!GetGame().GetInputManager().IsUsingMouseAndKeyboard())
161 m_OwnerMenu.SetToolMenuFocused(false);
162 }
163
164 //------------------------------------------------------------------------------------------------
166 {
167 return m_bIsExclusiveEntry;
168 }
169
170 //------------------------------------------------------------------------------------------------
171 // constructor
173 //! \param[in] imageset
174 //! \param[in] icon
175 //! \param[in] sortPriority
176 //! \param[in] isExclusive
177 void SCR_MapToolEntry(SCR_MapToolMenuUI menu, ResourceName imageset, string icon, int sortPriority = 0, bool isExclusive = 0)
178 {
179 m_OwnerMenu = menu;
180 m_sImageSet = imageset;
181 m_sIconQuad = icon;
182 m_bIsExclusiveEntry = isExclusive;
183
184 if (sortPriority > 0)
185 m_iSortPriority = sortPriority;
186 else
187 m_iSortPriority = 0;
188
189 m_OnClick.Insert(OnClick);
190 }
191}
192
195{
196 [Attribute("{2EFEA2AF1F38E7F0}UI/Textures/Icons/icons_wrapperUI-64.imageset", UIWidgets.ResourceNamePicker, "Menu icons imageset", "imageset")]
197 protected ResourceName m_sToolMenuIcons;
198
199 [Attribute("{47C1A2A23B9CAC97}UI/layouts/Map/MapToolButton.layout", UIWidgets.ResourceNamePicker, "Entry button prefab", "layout")]
201
202 [Attribute("ToolMenu", UIWidgets.EditBox, desc: "Root frame widget name")]
203 protected string m_sToolMenuRootName;
204
205 [Attribute("ToolMenuHoriz", UIWidgets.EditBox, desc: "Tool menu widget name")]
206 protected string m_sToolBarName;
207
208 [Attribute("ToolMenuButton", UIWidgets.EditBox, desc: "Default name for generated button widgets")]
209 protected string m_sButtonDefaultName;
210
211 [Attribute("MenuBackground", UIWidgets.EditBox, desc: "Tool menu background widget name")]
212 protected string m_sBackgroundName;
213
214 static ResourceName s_sToolMenuIcons;
215
216 protected bool m_bIsVisible;
217 protected bool m_bIsMenuFocused;
221 protected SCR_MapCursorModule m_CursorModule;
222
223 protected ref array<ref SCR_MapToolEntry> m_aMenuEntries = {};
224
225 //------------------------------------------------------------------------------------------------
228 {
230 }
231
232 //------------------------------------------------------------------------------------------------
234 array<ref SCR_MapToolEntry> GetMenuEntries()
235 {
236 return m_aMenuEntries;
237 }
238
239 //------------------------------------------------------------------------------------------------
245 SCR_MapToolEntry RegisterToolMenuEntry(ResourceName imageset, string icon, int sortPriority, bool isExclusive = false)
246 {
247 SCR_MapToolEntry entry = new SCR_MapToolEntry(this, imageset, icon, sortPriority, isExclusive);
248 m_aMenuEntries.Insert(entry);
249
250 if (!m_wToolMenuRoot)
251 m_wToolMenuRoot = m_MapEntity.GetMapMenuRoot().FindAnyWidget(m_sToolMenuRootName);
252
253 if (m_wToolMenuRoot)
254 {
256
257 if (!m_wBackground)
259 }
260
261 return entry;
262 }
263
264 //------------------------------------------------------------------------------------------------
268 {
269 m_aMenuEntries.Insert(customEntry);
270 }
271
272 //------------------------------------------------------------------------------------------------
276 {
277 // We only want to disable other entries when active entry is exclusive
278 if (!activeEntry.IsExclusiveEntry())
279 return;
280
281 foreach (SCR_MapToolEntry entry : m_aMenuEntries)
282 {
283 // We only disable exclusive entries other than active entry
284 if (entry == activeEntry || !entry.IsExclusiveEntry())
285 continue;
286
287 entry.OnDisableMapUIComponent();
288 }
289 }
290
291 //------------------------------------------------------------------------------------------------
293 protected void PopulateToolMenu()
294 {
295 Widget button;
297
298 bool sorted = false;
299 int count = m_aMenuEntries.Count() - 1;
300
301 while (!sorted) // sort by prio
302 {
303 sorted = true;
304
305 for (int i = 0; i < count; i++)
306 {
308 {
309 m_aMenuEntries.SwapItems(i, i + 1);
310 sorted = false;
311 }
312 }
313 }
314
315 foreach (int i, SCR_MapToolEntry entry : m_aMenuEntries) // use the cached entry data to create layouts and find button handlers
316 {
317 button = GetGame().GetWorkspace().CreateWidgets(m_sButtonResource, m_wToolMenuBar);
318 button.SetName(m_sButtonDefaultName + i);
319
320 buttonComp = SCR_ToolMenuButtonComponent.Cast(button.FindHandler(SCR_ToolMenuButtonComponent));
321 if (buttonComp)
322 {
323 buttonComp.m_OnClicked = entry.m_OnClick;
324 buttonComp.SetImage(entry.m_sImageSet, entry.m_sIconQuad);
325
326 entry.m_ButtonComp = buttonComp;
327
328 entry.UpdateVisual();
329 }
330 }
331
332 SetUIVisible(true);
333 }
334
335 //------------------------------------------------------------------------------------------------
337 protected void OnFocusToolMenu(float value, EActionTrigger reason)
338 {
340 }
341
342 //------------------------------------------------------------------------------------------------
343 protected void OnFreeCursor(float value, EActionTrigger reason)
344 {
345 SetToolMenuFocused(false);
346 }
347
348 //------------------------------------------------------------------------------------------------
349 protected void OnMapPan(float x, float y, bool adjusted)
350 {
351 SetToolMenuFocused(false);
352 }
353
354 //------------------------------------------------------------------------------------------------
357 protected void SetUIVisible(bool state)
358 {
359 m_bIsVisible = state;
360 m_wToolMenuRoot.SetVisible(state);
361 }
362
363 //------------------------------------------------------------------------------------------------
366 void SetToolMenuFocused(bool state)
367 {
368 if (state == m_bIsMenuFocused || m_aMenuEntries.IsEmpty())
369 return;
370
371 if (state)
372 {
373 if (!m_CursorModule.HandleSubMenu(true))
374 return;
375
376 m_wToolMenuBar.SetEnabled(true);
377 GetGame().GetWorkspace().SetFocusedWidget(m_aMenuEntries[0].m_ButtonComp.GetRootWidget());
378 m_bIsMenuFocused = true;
379 }
380 else // Disable tool menu besides root, so its buttons arent being focused when unwanted
381 {
382 m_wToolMenuBar.SetEnabled(false);
383 GetGame().GetWorkspace().SetFocusedWidget(null);
384 m_CursorModule.HandleSubMenu(false);
385 m_bIsMenuFocused = false;
386 }
387 }
388
389 //------------------------------------------------------------------------------------------------
390 override event bool OnMouseEnter(Widget w, int x, int y)
391 {
392 if (m_wToolMenuRoot && w == m_wToolMenuRoot && !m_wToolMenuBar.IsEnabled()) // menu is disabled
393 SetToolMenuFocused(true);
394
395 GetGame().GetWorkspace().SetFocusedWidget(w);
396
397 return true;
398 }
399
400 //------------------------------------------------------------------------------------------------
401 override event bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
402 {
403 Widget parent = enterW;
404 while (parent)
405 {
406 if (parent == m_wToolMenuRoot)
407 break;
408
409 parent = parent.GetParent();
410 }
411
412 if (parent != m_wToolMenuRoot && w.IsEnabled()) // disable menu
413 SetToolMenuFocused(false);
414
415 return true;
416 }
417
418 //------------------------------------------------------------------------------------------------
419 override void OnMapOpen(MapConfiguration config)
420 {
421 m_CursorModule = SCR_MapCursorModule.Cast(m_MapEntity.GetMapModule(SCR_MapCursorModule));
422
423 if (!m_wToolMenuRoot)
424 m_wToolMenuRoot = m_MapEntity.GetMapMenuRoot().FindAnyWidget(m_sToolMenuRootName);
425
426 if (!m_wToolMenuBar)
428
429 m_wToolMenuRoot.AddHandler(this);
430
431 InputManager inputMgr = GetGame().GetInputManager();
432 if (inputMgr)
433 {
434 inputMgr.AddActionListener("MapToolMenuFocus", EActionTrigger.DOWN, OnFocusToolMenu);
435 inputMgr.AddActionListener("MapGamepadCursorX", EActionTrigger.DOWN, OnFreeCursor);
436 inputMgr.AddActionListener("MapGamepadCursorY", EActionTrigger.DOWN, OnFreeCursor);
437 }
438
439 m_MapEntity.GetOnMapPan().Insert(OnMapPan);
440
442
443 m_wToolMenuBar.SetEnabled(false); // by default not interactable unless enabled by entering with mouse/activating through input
444 }
445
446 //------------------------------------------------------------------------------------------------
447 override void OnMapClose(MapConfiguration config)
448 {
449 if (m_wToolMenuRoot)
450 m_wToolMenuRoot.RemoveHandler(this);
451
452 InputManager inputMgr = GetGame().GetInputManager();
453 if (inputMgr)
454 {
455 inputMgr.RemoveActionListener("MapToolMenuFocus", EActionTrigger.DOWN, OnFocusToolMenu);
456 inputMgr.RemoveActionListener("MapGamepadCursorX", EActionTrigger.DOWN, OnFreeCursor);
457 inputMgr.RemoveActionListener("MapGamepadCursorY", EActionTrigger.DOWN, OnFreeCursor);
458 }
459
460 m_MapEntity.GetOnMapPan().Remove(OnMapPan);
461 }
462
463 //------------------------------------------------------------------------------------------------
465 {
466 return m_bIsMenuFocused;
467 }
468
469 //------------------------------------------------------------------------------------------------
472 {
473 if (!m_wBackground)
474 {
475 m_wToolMenuRoot = m_MapEntity.GetMapMenuRoot().FindAnyWidget(m_sToolMenuRootName);
477 }
478
479 return m_wBackground;
480 }
481
482 //------------------------------------------------------------------------------------------------
483 // constructor
485 {
486 s_sToolMenuIcons = m_sToolMenuIcons;
487 }
488}
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnMouseEnter(Widget w, int x, int y)
SCR_MapCursorModule m_CursorModule
void OnMapPan(float x, float y, bool adjustedPan)
SCR_MapEntity m_MapEntity
bool m_bIsVisible
void SetToolMenuFocused(bool state)
ResourceName m_sButtonResource
void PopulateToolMenu()
Build entries.
bool IsFocused()
bool m_bIsMenuFocused
SCR_MapToolEntry RegisterToolMenuEntry(ResourceName imageset, string icon, int sortPriority, bool isExclusive=false)
ref array< ref SCR_MapToolEntry > m_aMenuEntries
void DisableInactiveMapUIEntries(notnull SCR_MapToolEntry activeEntry)
void SCR_MapToolMenuUI()
Widget m_wToolMenuRoot
Widget GetBackgroundWidget()
string m_sButtonDefaultName
int m_iSortPriority
Widget m_wToolMenuBar
SCR_ToolMenuButtonComponent m_ButtonComp
Widget m_wBackground
void SetUIVisible(bool state)
void RegisterEntryCustom(SCR_MapToolEntry customEntry)
string m_sBackgroundName
string GetDefaultButtonName()
Returns default button name. Bear in mind that actual buttons have added index number to its end in P...
SCR_MapToolMenuUI m_OwnerMenu
ref ScriptInvokerVoid m_OnDisableMapUIComponent
void OnFocusToolMenu(float value, EActionTrigger reason)
Focus menu event when using controller.
void OnFreeCursor(float value, EActionTrigger reason)
array< ref SCR_MapToolEntry > GetMenuEntries()
string m_sToolBarName
string m_sToolMenuRootName
void SCR_MapToolEntry(SCR_MapToolMenuUI menu, ResourceName imageset, string icon, int sortPriority=0, bool isExclusive=0)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition Color.c:13
Input management system for user interactions.
Map tool menu entry data class.
void SetBorderColor(notnull Color color)
bool IsEntryEnabled()
Whether entry can be activated.
void SCR_MapToolEntry(SCR_MapToolMenuUI menu, ResourceName imageset, string icon, int sortPriority=0, bool isExclusive=0)
string m_sIconQuad
bool m_bIsVisible
void SetVisible(bool state)
Visibility, determines whether the entry is visible with the menu.
ref ScriptInvoker< SCR_MapToolEntry > s_OnEntryToggled
static ScriptInvoker GetOnEntryToggledInvoker()
ref ScriptInvokerVoid m_OnDisableMapUIComponent
int m_iSortPriority
bool m_bIsExclusiveEntry
bool IsExclusiveEntry()
void SetColor(notnull Color color)
void SetEnabled(bool isEnabled)
Disabled behavior, ON/OFF determines whether can be activated (clicked).
string GetImageSet()
void SetActive(bool toolActive)
Activation behavior, ON/OFF if entry is active (visual distinction).
bool m_bToolActive
ref ScriptInvoker m_OnClick
void SetButtonSoundsDisabled(bool state)
Enable button sounds.
void OnDisableMapUIComponent()
void OnClick()
On click callback.
ResourceName m_sImageSet
bool m_bButtonSoundsDisabled
void UpdateVisual()
Update visual based on current state.
SCR_ToolMenuButtonComponent m_ButtonComp
ScriptInvokerVoid GetOnDisableMapUIInvoker()
bool m_bIsEnabled
SCR_MapToolMenuUI m_OwnerMenu
bool IsEntryActive()
void SetBackgroundColor(notnull Color color)
void OnMapOpen(MapConfiguration config)
void OnMapClose(MapConfiguration config)
SCR_FieldOfViewSettings Attribute
EActionTrigger
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134