Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RespawnMenuWidgetComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_RespawnMenuWidgetHandler : ScriptedWidgetComponent
3 {
4  [Attribute("DeployMenuRight", desc: "Input Action to listen to")]
5  protected string m_sRightMenuAction;
6 
7  [Attribute("DeployMenuLeft", desc: "Input Action to listen to")]
8  protected string m_sToolMenuAction;
9 
10  [Attribute("ExpandButton", desc: "Widget to be initially focused")]
11  protected string m_sDefaultButtonName;
12 
13  [Attribute("ToolMenu")]
14  protected string m_sMapToolMenu;
15 
16  [Attribute("Selectors")]
17  protected string m_sSelectorsWidgetName;
18 
19  [Attribute("ControlHints")]
20  protected string m_sControlHintsWidgetName;
21 
22  protected Widget m_wOwner;
23  protected Widget m_wRoot;
24  protected Widget m_wDefaultFocusWidget;
25  protected Widget m_wDpadActionWidgetRightMenu;
26  protected Widget m_wDpadActionWidgetToolMenu;
27  protected Widget m_wMapToolWidget;
28  protected Widget m_wLoadoutSelector;
29  protected SCR_ButtonBaseComponent m_LoadoutSelectorBtnLeft, m_LoadoutSelectorBtnRight;
30  protected SCR_MapToolMenuUI m_MapToolMenuUI;
31  protected SCR_DeployMenuMain m_DeployMenu;
32 
33  protected ref array<SCR_DeployRequestUIBaseComponent> m_aSelectors = {};
34 
35  //------------------------------------------------------------------------------------------------
36  protected void OnLoadoudSelectorBtnFocused(Widget w)
37  {
38  Widget focusTo = m_wOwner.FindAnyWidget("ExpandButton");
39  if (!focusTo)
40  return;
41 
42  GetGame().GetWorkspace().SetFocusedWidget(focusTo);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  protected SCR_DeployRequestUIBaseComponent GetOpenedSelector()
47  {
48  foreach(SCR_DeployRequestUIBaseComponent selector : m_aSelectors)
49  {
50  if (selector.IsExpanded())
51  return selector;
52  }
53 
54  return null;
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  protected void SetupSelectors()
59  {
60  Widget selectorsWidget = m_wOwner.FindAnyWidget(m_sSelectorsWidgetName);
61  if (!selectorsWidget)
62  {
63  Print("SCR_RespawnMenuWidgetComponent: Couldn't set up selectors in the respawn menu widget component because the widget with name " + m_sSelectorsWidgetName + " was not found", LogLevel.WARNING);
64  return;
65  }
66 
67  SCR_DeployRequestUIBaseComponent deployReqComponent;
68  Widget selector = selectorsWidget.GetChildren();
69  while (selector)
70  {
71  deployReqComponent = SCR_DeployRequestUIBaseComponent.Cast(selector.FindHandler(SCR_DeployRequestUIBaseComponent));
72  if (deployReqComponent)
73  m_aSelectors.Insert(deployReqComponent);
74 
75  selector = selector.GetSibling();
76  }
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  protected void ShowControlHints(Widget w, bool show)
81  {
82  Widget hintsWidget = w.GetParent().FindAnyWidget(m_sControlHintsWidgetName);
83  if (!hintsWidget)
84  return;
85 
86  hintsWidget.SetVisible(show);
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  protected void ShowDpadWidgets(bool show)
91  {
92  if (m_wDpadActionWidgetRightMenu)
93  m_wDpadActionWidgetRightMenu.SetVisible(show);
94 
95  if (m_wDpadActionWidgetToolMenu)
96  m_wDpadActionWidgetToolMenu.SetVisible(show);
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  void EnableWidget(notnull Widget w, bool enable)
101  {
102  w.SetEnabled(enable);
103  Widget child = w.GetChildren();
104  while (child)
105  {
106  EnableWidget(child, enable);
107  child = child.GetSibling();
108  }
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  protected void OnInputDeviceIsGamepad(bool isGamepad)
113  {
114  SCR_LoadoutGallery gallery = SCR_LoadoutGallery.Cast(m_wLoadoutSelector.FindHandler(SCR_LoadoutGallery));
115  if (!gallery)
116  return;
117 
118  m_LoadoutSelectorBtnLeft.m_OnFocus.Remove(OnLoadoudSelectorBtnFocused);
119  m_LoadoutSelectorBtnRight.m_OnFocus.Remove(OnLoadoudSelectorBtnFocused);
120 
121  //Disable all widgets and have them enabled through DPAD interactions, if on gamepad.
122  if (isGamepad)
123  {
124  gallery.EnablePagingInputListeners(false);
125  gallery.SetGalleryFocused(false);
126  gallery.GetOnFocusChange().Insert(gallery.EnablePagingInputListeners);
127 
128  m_LoadoutSelectorBtnLeft.m_OnFocus.Insert(OnLoadoudSelectorBtnFocused);
129  m_LoadoutSelectorBtnRight.m_OnFocus.Insert(OnLoadoudSelectorBtnFocused);
130 
131  EnableWidget(m_wMapToolWidget, !isGamepad);
132  return;
133  }
134 
135  gallery.GetOnFocusChange().Remove(gallery.EnablePagingInputListeners);
136  gallery.EnablePagingInputListeners(true);
137 
138  GetGame().GetWorkspace().SetFocusedWidget(null);
139  EnableWidget(m_wMapToolWidget, true);
140  ShowControlHints(m_wOwner, false);
141  ShowControlHints(m_wMapToolWidget, false);
142 
143  if (m_DeployMenu)
144  m_DeployMenu.AllowMapContext(true);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void SetupMap()
149  {
150  if (!m_DeployMenu)
151  m_DeployMenu = SCR_DeployMenuMain.GetDeployMenu();
152 
153  m_wMapToolWidget = m_wRoot.FindAnyWidget(m_sMapToolMenu);
154  if (!m_wMapToolWidget)
155  return;
156 
157  Widget widget = m_wRoot.FindAnyWidget("LoadoutSelector");
158  if (!widget)
159  return;
160 
161  m_wLoadoutSelector = widget.FindAnyWidget("Selector");
162 
163  m_wDpadActionWidgetToolMenu = m_wMapToolWidget.FindAnyWidget("Action");
164  m_MapToolMenuUI = SCR_MapToolMenuUI.Cast(SCR_MapEntity.GetMapInstance().GetMapUIComponent(SCR_MapToolMenuUI));
165 
166  widget = m_wRoot.FindAnyWidget("PagingLeft");
167  if (widget)
168  m_LoadoutSelectorBtnLeft = SCR_ButtonBaseComponent.Cast(widget.FindHandler(SCR_PagingButtonComponent));
169 
170  widget = m_wRoot.FindAnyWidget("PagingRight");
171  if (widget)
172  m_LoadoutSelectorBtnRight = SCR_ButtonBaseComponent.Cast(widget.FindHandler(SCR_PagingButtonComponent));
173 
174  OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
175  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
176  SetupSelectors();
177  AddActionListeners();
178  }
179 
180  //------------------------------------------------------------------------------------------------
181  override void HandlerAttached(Widget w)
182  {
183  if (SCR_Global.IsEditMode())
184  return;
185 
186  m_wOwner = w;
187  m_wRoot = SCR_WidgetHelper.GetRootWidget(m_wOwner);
188  m_wDpadActionWidgetRightMenu = w.FindAnyWidget("Action");
189  m_wDefaultFocusWidget = m_wOwner.FindAnyWidget(m_sDefaultButtonName);
190 
191  //Delayed caching of other widgets, as they are initialised later
192  GetGame().GetCallqueue().CallLater(SetupMap, 1000);
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  override void HandlerDeattached(Widget w)
197  {
198  if (SCR_Global.IsEditMode())
199  return;
200 
201  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  protected void AddActionListeners()
206  {
207  GetGame().GetInputManager().AddActionListener(m_sRightMenuAction, EActionTrigger.DOWN, SetFocusRightMenu);
208  GetGame().GetInputManager().AddActionListener(m_sToolMenuAction, EActionTrigger.DOWN, SetFocusToolMenu);
209 
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  protected void RemoveActionListeners()
214  {
215  GetGame().GetInputManager().RemoveActionListener(m_sRightMenuAction, EActionTrigger.DOWN, SetFocusRightMenu);
216  GetGame().GetInputManager().RemoveActionListener(m_sToolMenuAction, EActionTrigger.DOWN, SetFocusToolMenu);
217 
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  protected void SetFocusRightMenu()
222  {
223  if (!m_wDefaultFocusWidget)
224  return;
225 
226  ShowDpadWidgets(false);
227  ShowControlHints(m_wOwner, true);
228 
229  GetGame().GetWorkspace().SetFocusedWidget(m_wDefaultFocusWidget);
230 
231  RemoveActionListeners();
232  GetGame().GetInputManager().AddActionListener("MenuBack", EActionTrigger.DOWN, DisableFocusRightMenu);
233 
234  if (m_DeployMenu)
235  m_DeployMenu.AllowMapContext(false);
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  protected void SetFocusToolMenu()
240  {
241  if (!m_MapToolMenuUI)
242  return;
243 
244  EnableWidget(m_wMapToolWidget, true);
245  ShowControlHints(m_wMapToolWidget, true);
246  m_MapToolMenuUI.SetToolMenuFocused(true);
247  ShowDpadWidgets(false);
248 
249  RemoveActionListeners();
250  GetGame().GetInputManager().AddActionListener("MenuBack", EActionTrigger.DOWN, DisableFocusToolMenu);
251 
252  if (m_DeployMenu)
253  m_DeployMenu.AllowMapContext(false);
254  }
255 
256  //------------------------------------------------------------------------------------------------
257  protected void DisableFocusRightMenu()
258  {
259  SCR_DeployRequestUIBaseComponent selector = GetOpenedSelector();
260  if (selector && !GetGame().GetInputManager().IsUsingMouseAndKeyboard())
261  {
262  selector.SetExpanded(false);
263  GetGame().GetWorkspace().SetFocusedWidget(m_wDefaultFocusWidget);
264  return;
265  }
266 
267  GetGame().GetWorkspace().SetFocusedWidget(null);
268 
269  GetGame().GetInputManager().RemoveActionListener("MenuBack", EActionTrigger.DOWN, DisableFocusRightMenu);
270  AddActionListeners();
271 
272  ShowDpadWidgets(true);
273  ShowControlHints(m_wOwner, false);
274 
275  if (m_DeployMenu)
276  m_DeployMenu.AllowMapContext(true);
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  protected void DisableFocusToolMenu()
281  {
282  if (!m_MapToolMenuUI)
283  return;
284 
285  if (IsAnyEntryActive())
286  {
287  CloseAllMapTools();
288 
289  m_MapToolMenuUI.SetToolMenuFocused(true);
290  return;
291  }
292 
293  GetGame().GetInputManager().RemoveActionListener("MenuBack", EActionTrigger.DOWN, DisableFocusToolMenu);
294  m_MapToolMenuUI.SetToolMenuFocused(false);
295  AddActionListeners();
296  ShowDpadWidgets(true);
297  ShowControlHints(m_wMapToolWidget, false);
298 
299  if (m_DeployMenu)
300  m_DeployMenu.AllowMapContext(true);
301  }
302 
303  //------------------------------------------------------------------------------------------------
304  protected bool IsAnyEntryActive()
305  {
306  array<ref SCR_MapToolEntry> entries = m_MapToolMenuUI.GetMenuEntries();
307  if (!entries || entries.IsEmpty())
308  return false;
309 
310  foreach (ref SCR_MapToolEntry entry : entries)
311  {
312  //TODO: This is far from ideal, on the contrary, this is terrible.
313  if ((entry.GetImageSet() == "ruler") || (entry.GetImageSet() == "compass") || (entry.GetImageSet() == "watch") || (entry.GetImageSet() == "editor"))
314  continue;
315 
316  if (entry.IsEntryActive())
317  return true;
318  }
319 
320  return false;
321  }
322 
323  //------------------------------------------------------------------------------------------------
324  protected void CloseAllMapTools()
325  {
326  array<ref SCR_MapToolEntry> entries = m_MapToolMenuUI.GetMenuEntries();
327  if (!entries || entries.IsEmpty())
328  return;
329 
330  foreach (ref SCR_MapToolEntry entry : entries)
331  {
332  if ((entry.GetImageSet() == "ruler") || (entry.GetImageSet() == "compass") || (entry.GetImageSet() == "watch") || (entry.GetImageSet() == "editor"))
333  continue;
334 
335  if (entry.IsEntryActive())
336  entry.SetActive(false);
337  }
338  }
339 }
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
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_WidgetHelper
Definition: SCR_WidgetHelper.c:1
SCR_DeployRequestUIBaseComponent
Definition: SCR_DeployRequestUIBaseComponent.c:2
SCR_PagingButtonComponent
Definition: SCR_PagingButtonComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_Global
Definition: Functions.c:6
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_RespawnMenuWidgetHandler
Definition: SCR_RespawnMenuWidgetComponent.c:2
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389