Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SubMenuBase.c
Go to the documentation of this file.
1 /*
2 Component for SCR_SuperMenuComponent tab.
3 Relies on a SCR_DynamicFooterComponent somewhere in the layout under the menuRoot widget passed on creation to handle input buttons of the tab
4 */
5 
7 {
8  protected ResourceName m_sNavigationButtonLayout;
9 
10  protected SCR_DynamicFooterComponent m_DynamicFooter;
11  protected ref array<SCR_InputButtonComponent> m_aNavigationButtons = {};
12  protected ref map<SCR_InputButtonComponent, bool> m_aNavigationButtonsVisibilityFlags = new map<SCR_InputButtonComponent, bool>();
13 
14  Widget m_wMenuRoot;
15  int m_iIndex;
16 
17  protected bool m_bShown;
18  protected bool m_bFocused;
19 
20  // Menu requests
21  protected ref ScriptInvokerVoid m_OnRequestCloseMenu;
22  protected ref ScriptInvokerInt2 m_OnRequestTabChange;
23 
24  //------------------------------------------------------------------------------------------------
25  // --- Menu events ---
26  //------------------------------------------------------------------------------------------------
27  void OnMenuFocusGained()
28  {
29  m_bFocused = true;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  void OnMenuFocusLost()
34  {
35  m_bFocused = false;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  void OnMenuShow();
40  void OnMenuHide();
41  void OnMenuUpdate(float tDelta);
42 
43  //------------------------------------------------------------------------------------------------
44  // --- Tab events ---
45  //------------------------------------------------------------------------------------------------
46  // Tab initialization, depending on SCR_TabViewComponent settings it can happen before or after OnMenuOpen, or even when the tab is first selected
47  void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
48  {
49  m_iIndex = index;
50  m_wMenuRoot = menuRoot;
51  m_DynamicFooter = SCR_DynamicFooterComponent.FindComponentInHierarchy(menuRoot);
52  m_sNavigationButtonLayout = buttonsLayout;
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  // Tab has actively been selected, or it's the default one after creation
57  void OnTabShow()
58  {
59  ShowNavigationButtons(true);
60  m_bShown = true;
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  // Another tab has been selected
65  void OnTabHide()
66  {
67  ShowNavigationButtons(false);
68  m_bShown = false;
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  // Tab destruction
73  void OnTabRemove()
74  {
75  foreach (SCR_InputButtonComponent comp : m_aNavigationButtons)
76  {
77  Widget w = comp.GetRootWidget();
78  if (!w)
79  continue;
80 
81  w.RemoveFromHierarchy();
82  }
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  // Generic, happens anytime a tab is selected
87  void OnTabChange();
88 
89  //------------------------------------------------------------------------------------------------
90  // --- Protected ---
91  //------------------------------------------------------------------------------------------------
92  protected void ShowNavigationButtons(bool show)
93  {
94  bool visible;
95 
96  foreach (SCR_InputButtonComponent comp : m_aNavigationButtons)
97  {
98  if (m_aNavigationButtonsVisibilityFlags.Contains(comp))
99  visible = m_aNavigationButtonsVisibilityFlags.Get(comp);
100 
101  visible = visible && show;
102 
103  comp.SetVisible(visible, false);
104  }
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  // Flags a button to be set visible the next time ShowNavigationButtons() is called, like on TabShow
109  protected void FlagNavigationButtonVisibility(SCR_InputButtonComponent button, bool show)
110  {
111  if (!button)
112  return;
113 
114  if (!m_aNavigationButtonsVisibilityFlags.Contains(button) || !m_aNavigationButtons.Contains(button))
115  {
116  PrintFormat(
117  "SCR_SubMenuBase - FlagNavigationButtonVisibility() - button %1, %2 is not a sub menu footer button as it was not created with CreateNavigationButton() method",
118  button,
119  button.GetRootWidget().GetName()
120  );
121 
122  return;
123  }
124 
125  m_aNavigationButtonsVisibilityFlags.Set(button, show);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  // Use this to control the visibility of buttons created with CreateNavigationButton() method
130  protected void SetNavigationButtonVisibile(SCR_InputButtonComponent button, bool show, bool animate = false)
131  {
132  if (!button)
133  return;
134 
135  if (!m_aNavigationButtonsVisibilityFlags.Contains(button) || !m_aNavigationButtons.Contains(button))
136  {
137  PrintFormat(
138  "SCR_SubMenuBase - SetFooterButtonVisibile() - button %1, %2 is not a sub menu footer button as it was not created with CreateNavigationButton() method",
139  button,
140  button.GetRootWidget().GetName()
141  );
142 
143  return;
144  }
145 
146  FlagNavigationButtonVisibility(button, show);
147  button.SetVisible(m_bShown && show, animate);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  // If used on tab show, make sure to avoid creating duplicates
152  protected SCR_InputButtonComponent CreateNavigationButton(string actionName, string label, bool rightFooter = false, bool show = true)
153  {
154  if (!m_DynamicFooter)
155  return null;
156 
157  SCR_EDynamicFooterButtonAlignment alignment = SCR_EDynamicFooterButtonAlignment.LEFT;
158  if (rightFooter)
159  alignment = SCR_EDynamicFooterButtonAlignment.RIGHT;
160 
161  SCR_InputButtonComponent comp = m_DynamicFooter.CreateButton(m_sNavigationButtonLayout, label + m_iIndex, label, actionName, alignment, show);
162 
163  if (!comp)
164  return null;
165 
166  m_aNavigationButtons.Insert(comp);
167  m_aNavigationButtonsVisibilityFlags.Insert(comp, show);
168  return comp;
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  protected void RequestCloseMenu()
173  {
174  if (m_OnRequestCloseMenu)
175  m_OnRequestCloseMenu.Invoke();
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  // Provides the desired tab and the current index
180  protected void RequestTabChange(int newTabIndex)
181  {
182  if (m_OnRequestTabChange)
183  m_OnRequestTabChange.Invoke(newTabIndex, m_iIndex);
184  }
185 
186  //------------------------------------------------------------------------------------------------
187  // --- Public ---
188  //------------------------------------------------------------------------------------------------
189  bool GetShown()
190  {
191  return m_bShown;
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  ScriptInvokerVoid GetOnRequestCloseMenu()
196  {
197  if (!m_OnRequestCloseMenu)
198  m_OnRequestCloseMenu = new ScriptInvokerVoid();
199 
200  return m_OnRequestCloseMenu;
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  ScriptInvokerInt2 GetOnRequestTabChange()
205  {
206  if (!m_OnRequestTabChange)
207  m_OnRequestTabChange = new ScriptInvokerInt2();
208 
209  return m_OnRequestTabChange;
210  }
211 }
m_bShown
protected bool m_bShown
Definition: SCR_InfoDisplay.c:61
ScriptInvokerInt2
ScriptInvokerBase< ScriptInvokerInt2Method > ScriptInvokerInt2
Definition: SCR_ScriptInvokerHelper.c:25
SCR_SubMenuBase
Definition: SCR_SubMenuBase.c:6
m_iIndex
private int m_iIndex
Definition: SCR_StressTestGroupActivation.c:11
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1