Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapToolMenuUI.c
Go to the documentation of this file.
1 class SCR_MapToolEntry : Managed
3 {
4  protected bool m_bToolActive;
5  protected bool m_bIsEnabled = true;
6  protected bool m_bIsVisible = true;
7 
8  bool m_bButtonSoundsDisabled;
9  int m_iSortPriority;
10  ResourceName m_sImageSet;
11  string m_sIconQuad;
12  SCR_ToolMenuButtonComponent m_ButtonComp;
13  SCR_MapToolMenuUI m_OwnerMenu;
14 
15  ref ScriptInvoker m_OnClick = new ScriptInvoker();
16  static protected ref ScriptInvoker<SCR_MapToolEntry> s_OnEntryToggled = new ScriptInvoker();
17 
18  //------------------------------------------------------------------------------------------------
20  static ScriptInvoker GetOnEntryToggledInvoker()
21  {
22  return s_OnEntryToggled;
23  }
24 
25  //------------------------------------------------------------------------------------------------
27  void SetActive(bool toolActive)
28  {
29  m_bToolActive = toolActive;
30  UpdateVisual();
31  }
32 
33  //------------------------------------------------------------------------------------------------
35  bool IsEntryActive()
36  {
37  return m_bToolActive;
38  }
39 
40  //------------------------------------------------------------------------------------------------
42  void SetEnabled(bool isEnabled)
43  {
44  m_bIsEnabled = isEnabled;
45  UpdateVisual();
46  }
47 
48  //------------------------------------------------------------------------------------------------
50  bool IsEntryEnabled()
51  {
52  return m_bIsEnabled;
53  }
54 
55  //------------------------------------------------------------------------------------------------
57  void SetVisible(bool state)
58  {
59  m_bIsVisible = state;
60  UpdateVisual();
61  }
62 
63  //------------------------------------------------------------------------------------------------
65  void SetButtonSoundsDisabled(bool state)
66  {
68  }
69 
70  //------------------------------------------------------------------------------------------------
72  void UpdateVisual()
73  {
74  if (!m_ButtonComp) // handler might not be updated yet when the set is attempted
75  return;
76 
77  if (m_bToolActive)
78  SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
79  else
80  SetColor(Color.FromInt(UIColors.DARK_GREY.PackToInt()));
81 
82  if (m_bIsEnabled)
83  SetBorderColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
84  else
85  SetBorderColor(Color.FromInt(UIColors.DARK_GREY.PackToInt()));
86 
87  m_ButtonComp.GetRootWidget().SetVisible(m_bIsVisible);
88  }
89 
90  //------------------------------------------------------------------------------------------------
93  protected void SetColor(Color color)
94  {
95  m_ButtonComp.m_wImage.SetColor(color);
96  }
97 
98  //------------------------------------------------------------------------------------------------
101  protected void SetBorderColor(Color color)
102  {
103  m_ButtonComp.m_wBorder.SetColor(color);
104  }
105 
106  //------------------------------------------------------------------------------------------------
108  string GetImageSet()
109  {
110  return m_sIconQuad;
111  }
112 
113  //------------------------------------------------------------------------------------------------
115  protected void OnClick()
116  {
118  {
119  if (m_bToolActive)
120  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_HIDE);
121  else
122  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_GADGET_SHOW);
123  }
124 
125  s_OnEntryToggled.Invoke(this);
126 
127  if (!GetGame().GetInputManager().IsUsingMouseAndKeyboard())
128  m_OwnerMenu.SetToolMenuFocused(false);
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  // constructor
137  void SCR_MapToolEntry(SCR_MapToolMenuUI menu, ResourceName imageset, string icon, int sortPriority = 0)
138  {
139  m_OwnerMenu = menu;
140  m_sImageSet = imageset;
141  m_sIconQuad = icon;
142 
143  if (sortPriority > 0)
144  m_iSortPriority = sortPriority;
145  else
146  m_iSortPriority = 0;
147 
148  m_OnClick.Insert(OnClick);
149  }
150 }
151 
154 {
155  [Attribute("{2EFEA2AF1F38E7F0}UI/Textures/Icons/icons_wrapperUI-64.imageset", UIWidgets.ResourceNamePicker, "Menu icons imageset", "imageset")]
156  ResourceName m_sToolMenuIcons;
157 
158  [Attribute("{47C1A2A23B9CAC97}UI/layouts/Map/MapToolButton.layout", UIWidgets.ResourceNamePicker, "Entry button prefab", "layout")]
159  ResourceName m_sButtonResource;
160 
161  [Attribute("ToolMenu", UIWidgets.EditBox, desc: "Root frame widget name")]
163 
164  [Attribute("ToolMenuHoriz", UIWidgets.EditBox, desc: "Tool menu widget name")]
166 
167  [Attribute("ToolMenuButton", UIWidgets.EditBox, desc: "Default name for generated button widgets")]
169 
170  static ResourceName s_sToolMenuIcons;
171 
172  protected bool m_bIsVisible;
173  protected bool m_bIsMenuFocused;
174  protected Widget m_wToolMenuRoot;
175  protected Widget m_wToolMenuBar;
177 
178  protected ref array<ref SCR_MapToolEntry> m_aMenuEntries = {};
179 
180  //------------------------------------------------------------------------------------------------
183  {
184  return m_sButtonDefaultName;
185  }
186 
187  //------------------------------------------------------------------------------------------------
189  array<ref SCR_MapToolEntry> GetMenuEntries()
190  {
191  return m_aMenuEntries;
192  }
193 
194  //------------------------------------------------------------------------------------------------
199  SCR_MapToolEntry RegisterToolMenuEntry(ResourceName imageset, string icon, int sortPriority)
200  {
201  SCR_MapToolEntry entry = new SCR_MapToolEntry(this, imageset, icon, sortPriority);
202  m_aMenuEntries.Insert(entry);
203 
204  return entry;
205  }
206 
207  //------------------------------------------------------------------------------------------------
211  {
212  m_aMenuEntries.Insert(customEntry);
213  }
214 
215  //------------------------------------------------------------------------------------------------
217  protected void PopulateToolMenu()
218  {
219  Widget button;
220  SCR_ToolMenuButtonComponent buttonComp;
221 
222  bool sorted = false;
223  int count = m_aMenuEntries.Count() - 1;
224 
225  if (count < 2)
226  return;
227 
228  while (!sorted) // sort by prio
229  {
230  sorted = true;
231 
232  for (int i = 0; i < count; i++)
233  {
235  {
236  m_aMenuEntries.SwapItems(i, i+1);
237  sorted = false;
238  }
239  }
240  }
241 
242  foreach (int i, SCR_MapToolEntry entry : m_aMenuEntries) // use the cached entry data to create layouts and find button handlers
243  {
244  button = GetGame().GetWorkspace().CreateWidgets(m_sButtonResource, m_wToolMenuBar);
245  button.SetName(m_sButtonDefaultName + i);
246 
247  buttonComp = SCR_ToolMenuButtonComponent.Cast(button.FindHandler(SCR_ToolMenuButtonComponent));
248  if (buttonComp)
249  {
250  buttonComp.m_OnClicked = entry.m_OnClick;
251  buttonComp.SetImage(entry.m_sImageSet, entry.m_sIconQuad);
252 
253  entry.m_ButtonComp = buttonComp;
254 
255  entry.UpdateVisual();
256  }
257  }
258 
259  SetUIVisible(true);
260  }
261 
262  //------------------------------------------------------------------------------------------------
264  protected void OnFocusToolMenu(float value, EActionTrigger reason)
265  {
266  SetToolMenuFocused(!m_wToolMenuBar.IsEnabled());
267  }
268 
269  //------------------------------------------------------------------------------------------------
270  protected void OnFreeCursor(float value, EActionTrigger reason)
271  {
272  SetToolMenuFocused(false);
273  }
274 
275  //------------------------------------------------------------------------------------------------
276  protected void OnMapPan(float x, float y, bool adjusted)
277  {
278  SetToolMenuFocused(false);
279  }
280 
281  //------------------------------------------------------------------------------------------------
284  protected void SetUIVisible(bool state)
285  {
286  m_bIsVisible = state;
287  m_wToolMenuRoot.SetVisible(state);
288  }
289 
290  //------------------------------------------------------------------------------------------------
293  void SetToolMenuFocused(bool state)
294  {
295  if (state == m_bIsMenuFocused || m_aMenuEntries.IsEmpty())
296  return;
297 
298  if (state)
299  {
300  if (!m_CursorModule.HandleSubMenu(true))
301  return;
302 
303  m_wToolMenuBar.SetEnabled(true);
304  GetGame().GetWorkspace().SetFocusedWidget(m_aMenuEntries[0].m_ButtonComp.GetRootWidget());
305  m_bIsMenuFocused = true;
306  }
307  else // Disable tool menu besides root, so its buttons arent being focused when unwanted
308  {
309  m_wToolMenuBar.SetEnabled(false);
310  GetGame().GetWorkspace().SetFocusedWidget(null);
311  m_CursorModule.HandleSubMenu(false);
312  m_bIsMenuFocused = false;
313  }
314  }
315 
316  //------------------------------------------------------------------------------------------------
317  override event bool OnMouseEnter(Widget w, int x, int y)
318  {
319  if (m_wToolMenuRoot && w == m_wToolMenuRoot && !m_wToolMenuBar.IsEnabled()) // menu is disabled
320  {
321  if (m_CursorModule.HandleSubMenu(true))
322  m_wToolMenuBar.SetEnabled(true);
323  }
324 
325  GetGame().GetWorkspace().SetFocusedWidget(w);
326 
327  return true;
328  }
329 
330  //------------------------------------------------------------------------------------------------
331  override event bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
332  {
333  if (RenderTargetWidget.Cast(enterW) && w.IsEnabled()) // disable menu
334  {
335  m_wToolMenuBar.SetEnabled(false);
336  m_CursorModule.HandleSubMenu(false);
337 
338  GetGame().GetWorkspace().SetFocusedWidget(null);
339  }
340 
341  return true;
342  }
343 
344  //------------------------------------------------------------------------------------------------
345  override void OnMapOpen(MapConfiguration config)
346  {
348 
349  m_wToolMenuRoot = m_MapEntity.GetMapMenuRoot().FindAnyWidget(m_sToolMenuRootName);
350  if (m_wToolMenuRoot)
352 
353  m_wToolMenuRoot.AddHandler(this);
354 
355  InputManager inputMgr = GetGame().GetInputManager();
356  if (inputMgr)
357  {
358  inputMgr.AddActionListener("MapToolMenuFocus", EActionTrigger.DOWN, OnFocusToolMenu);
359  inputMgr.AddActionListener("MapGamepadCursorX", EActionTrigger.DOWN, OnFreeCursor);
360  inputMgr.AddActionListener("MapGamepadCursorY", EActionTrigger.DOWN, OnFreeCursor);
361  }
362 
363  m_MapEntity.GetOnMapPan().Insert(OnMapPan);
364 
366 
367  m_wToolMenuBar.SetEnabled(false); // by default not interactable unless enabled by entering with mouse/activating through input
368  }
369 
370  //------------------------------------------------------------------------------------------------
371  override void OnMapClose(MapConfiguration config)
372  {
373  if (m_wToolMenuRoot)
374  m_wToolMenuRoot.RemoveHandler(this);
375 
376  InputManager inputMgr = GetGame().GetInputManager();
377  if (inputMgr)
378  {
379  inputMgr.RemoveActionListener("MapToolMenuFocus", EActionTrigger.DOWN, OnFocusToolMenu);
380  inputMgr.RemoveActionListener("MapGamepadCursorX", EActionTrigger.DOWN, OnFreeCursor);
381  inputMgr.RemoveActionListener("MapGamepadCursorY", EActionTrigger.DOWN, OnFreeCursor);
382  }
383 
384  m_MapEntity.GetOnMapPan().Remove(OnMapPan);
385  }
386 
387  //------------------------------------------------------------------------------------------------
388  // constructor
390  {
391  s_sToolMenuIcons = m_sToolMenuIcons;
392  }
393 }
OnMouseEnter
override event bool OnMouseEnter(Widget w, int x, int y)
Definition: SCR_MapToolMenuUI.c:317
RegisterToolMenuEntry
SCR_MapToolEntry RegisterToolMenuEntry(ResourceName imageset, string icon, int sortPriority)
Definition: SCR_MapToolMenuUI.c:199
m_wToolMenuBar
protected Widget m_wToolMenuBar
Definition: SCR_MapToolMenuUI.c:175
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
SCR_ToolMenuButtonComponent
Definition: SCR_ToolMenuButtonComponent.c:1
OnMapOpen
override void OnMapOpen(MapConfiguration config)
Definition: SCR_MapToolMenuUI.c:345
m_bToolActive
protected bool m_bToolActive
Definition: SCR_MapToolMenuUI.c:2
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnFocusToolMenu
protected void OnFocusToolMenu(float value, EActionTrigger reason)
Focus menu event when using controller.
Definition: SCR_MapToolMenuUI.c:264
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
PopulateToolMenu
protected void PopulateToolMenu()
Build entries.
Definition: SCR_MapToolMenuUI.c:217
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapToolMenuUI.c:4
m_bButtonSoundsDisabled
bool m_bButtonSoundsDisabled
Definition: SCR_MapToolMenuUI.c:6
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
SCR_MapToolEntry
void SCR_MapToolEntry(SCR_MapToolMenuUI menu, ResourceName imageset, string icon, int sortPriority=0)
Definition: SCR_MapToolMenuUI.c:135
SCR_MapCursorModule
Map cursor behavior and mode setup.
Definition: SCR_MapCursorModule.c:39
m_wToolMenuRoot
protected Widget m_wToolMenuRoot
Definition: SCR_MapToolMenuUI.c:174
GetMenuEntries
array< ref SCR_MapToolEntry > GetMenuEntries()
Definition: SCR_MapToolMenuUI.c:189
m_sImageSet
ResourceName m_sImageSet
Definition: SCR_MapToolMenuUI.c:8
OnMouseLeave
override event bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: SCR_MapToolMenuUI.c:331
UIColors
Definition: Constants.c:16
m_sIconQuad
string m_sIconQuad
Definition: SCR_MapToolMenuUI.c:9
m_iSortPriority
int m_iSortPriority
Definition: SCR_MapToolMenuUI.c:7
m_ButtonComp
SCR_ToolMenuButtonComponent m_ButtonComp
Definition: SCR_MapToolMenuUI.c:10
SetUIVisible
protected void SetUIVisible(bool state)
Definition: SCR_MapToolMenuUI.c:284
SetToolMenuFocused
void SetToolMenuFocused(bool state)
Definition: SCR_MapToolMenuUI.c:293
m_bIsEnabled
protected bool m_bIsEnabled
Definition: SCR_BaseSupportStationComponent.c:97
RegisterEntryCustom
void RegisterEntryCustom(SCR_MapToolEntry customEntry)
Definition: SCR_MapToolMenuUI.c:210
m_sButtonResource
ResourceName m_sButtonResource
Definition: SCR_MapToolMenuUI.c:159
OnFreeCursor
protected void OnFreeCursor(float value, EActionTrigger reason)
Definition: SCR_MapToolMenuUI.c:270
m_bIsMenuFocused
protected bool m_bIsMenuFocused
Definition: SCR_MapToolMenuUI.c:173
m_aMenuEntries
protected ref array< ref SCR_MapToolEntry > m_aMenuEntries
Definition: SCR_MapToolMenuUI.c:178
m_CursorModule
SCR_MapCursorModule m_CursorModule
Definition: SCR_MapToolMenuUI.c:176
Attribute
SCR_MapToolEntry Managed Attribute("{2EFEA2AF1F38E7F0}UI/Textures/Icons/icons_wrapperUI-64.imageset", UIWidgets.ResourceNamePicker, "Menu icons imageset", "imageset")] ResourceName m_sToolMenuIcons
Map tool menu.
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
OnMapClose
override void OnMapClose(MapConfiguration config)
Definition: SCR_MapToolMenuUI.c:371
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapRTWBaseUI.c:29
OnMapPan
protected void OnMapPan(float x, float y, bool adjusted)
Definition: SCR_MapToolMenuUI.c:276
GetDefaultButtonName
string GetDefaultButtonName()
Returns default button name. Bear in mind that actual buttons have added index number to its end in P...
Definition: SCR_MapToolMenuUI.c:182
m_sButtonDefaultName
string m_sButtonDefaultName
Definition: SCR_MapToolMenuUI.c:168
m_OwnerMenu
SCR_MapToolMenuUI m_OwnerMenu
Definition: SCR_MapToolMenuUI.c:11
m_sToolBarName
string m_sToolBarName
Definition: SCR_MapToolMenuUI.c:165
m_sToolMenuRootName
string m_sToolMenuRootName
Definition: SCR_MapToolMenuUI.c:162
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389
m_OnClick
ref ScriptInvoker m_OnClick
Definition: SCR_MapToolMenuUI.c:13