Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DynamicFooterComponent.c
Go to the documentation of this file.
1/*
2Component for menu footers that handles navigation buttons, allowing quick and easy setup.
3TODO: ideally, this should support different types of buttons, once we make them derive from a common class
4*/
5
6//------------------------------------------------------------------------------------------------
8{
9 [Attribute("20", desc: "Padding between buttons")]
10 protected float m_fPadding;
11
12 [Attribute("Footer", desc: "Left footer name")]
13 protected string m_sLeftFooter;
14
15 [Attribute("FooterRight", desc: "Right footer name")]
16 protected string m_sRightFooter;
17
19
22
24
25 // ---- OVERRIDES ----
26 //------------------------------------------------------------------------------------------------
27 override void HandlerAttached(Widget w)
28 {
29 super.HandlerAttached(w);
30
32 Widget root = w.GetParent();
33 if (!root)
34 root = w;
35
36 m_wLeftFooter = root.FindAnyWidget(m_sLeftFooter);
37 m_wRightFooter = root.FindAnyWidget(m_sRightFooter);
38
39 array<SCR_InputButtonComponent> buttons = SCR_DynamicFooterComponent.FindChildrenButtons(w, false);
40
41 foreach (SCR_InputButtonComponent button : buttons)
42 {
43 RegisterButton(button);
44 }
45
46 UpdateAllButtonsPadding(m_wLeftFooter);
47 UpdateAllButtonsPadding(m_wRightFooter, SCR_EDynamicFooterButtonAlignment.RIGHT);
48 }
49
50//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
51// It is questionable if this component should care at all about giving invokers for the buttons, and instead just focus on setting the paddings/looks. The menu/dialog can then find the buttons and bind the proper events
52
53 // ---- PRIVATE ----
54 //------------------------------------------------------------------------------------------------
56 // TODO: provide the input button's action as well
57 private void OnButtonActivated(SCR_InputButtonComponent button)
58 {
60 m_OnButtonActivated.Invoke(button.GetRootWidget().GetName());
61 }
62
63//---- REFACTOR NOTE END ----
64
65 //------------------------------------------------------------------------------------------------
66 private void UpdateAllButtonsPadding(Widget wrapper, SCR_EDynamicFooterButtonAlignment alignment = 0)
67 {
68 if (!wrapper)
69 return;
70
71 array<SCR_InputButtonComponent> buttons = SCR_DynamicFooterComponent.FindChildrenButtons(wrapper);
72
73 foreach (SCR_InputButtonComponent button : buttons)
74 {
75 UpdateButtonPadding(button, alignment);
76 }
77 }
78
79 //------------------------------------------------------------------------------------------------
80 private void UpdateButtonPadding(SCR_InputButtonComponent button, SCR_EDynamicFooterButtonAlignment alignment = 0)
81 {
82 if (!button)
83 return;
84
85 float paddingRight, paddingLeft;
86 float left, top, right, bottom;
87
88 switch (alignment)
89 {
90 case SCR_EDynamicFooterButtonAlignment.LEFT:
91 paddingRight = m_fPadding;
92 break;
93
94 case SCR_EDynamicFooterButtonAlignment.RIGHT:
95 paddingLeft = m_fPadding;
96 break;
97 }
98
99 Widget widget = button.GetRootWidget();
100 AlignableSlot.GetPadding(widget, left, top, right, bottom);
101
102 AlignableSlot.SetPadding(widget, paddingLeft, top, paddingRight, bottom);
103 }
104
105 // ---- PUBLIC ----
106 //------------------------------------------------------------------------------------------------
107 SCR_InputButtonComponent CreateButton(ResourceName layout, string tag, string label, string action, SCR_EDynamicFooterButtonAlignment alignment = 0, bool visible = true)
108 {
110 Widget wrapper;
111 switch (alignment)
112 {
113 case SCR_EDynamicFooterButtonAlignment.LEFT:
114 wrapper = m_wLeftFooter;
115 break;
116
117 case SCR_EDynamicFooterButtonAlignment.RIGHT:
118 wrapper = m_wRightFooter;
119 break;
120 }
121
123 Widget buttonWidget = GetGame().GetWorkspace().CreateWidgets(layout, wrapper);
124 if (!buttonWidget)
125 return null;
126
127 SCR_InputButtonComponent button = SCR_InputButtonComponent.FindComponent(buttonWidget);
128 if (!button)
129 return null;
130
132 RegisterButton(button);
133 UpdateButtonPadding(button, alignment);
134
135 buttonWidget.SetName(tag);
136
137 button.SetVisible(visible, false);
138 button.SetLabel(label);
139 button.SetAction(action);
140
142 if (m_wRightFooter && wrapper == m_wLeftFooter)
143 m_wRightFooter.SetZOrder(buttonWidget.GetZOrder() + 1);
144
145 return button;
146 }
147
148 //------------------------------------------------------------------------------------------------
149 SCR_InputButtonComponent CreateButtonAtPosition(ResourceName layout, string tag, string label, string action, int position, SCR_EDynamicFooterButtonAlignment alignment = 0, bool visible = true)
150 {
152 Widget wrapper;
153 switch (alignment)
154 {
155 case SCR_EDynamicFooterButtonAlignment.LEFT:
156 wrapper = m_wLeftFooter;
157 break;
158
159 case SCR_EDynamicFooterButtonAlignment.RIGHT:
160 wrapper = m_wRightFooter;
161 break;
162 }
163
165 array<ref Widget> existingButtons = {};
166 SCR_WidgetHelper.GetAllChildren(wrapper, existingButtons);
167 int count;
168
169 foreach (Widget existingButton : existingButtons)
170 {
171 if (count == position)
172 count++; //Skip what will be the position of the new button
173
174 existingButton.SetZOrder(count);
175 count++;
176 }
177
179 SCR_InputButtonComponent button = CreateButton(layout, tag, label, action, alignment, visible);
180 if (button)
181 button.GetRootWidget().SetZOrder(position);
182
184 if (wrapper == m_wLeftFooter)
185 m_wRightFooter.SetZOrder(button.GetRootWidget().GetZOrder() + 1);
186
187 UpdateButtonPadding(button, alignment);
188
189 return button;
190 }
191
192 //------------------------------------------------------------------------------------------------
194 void RegisterButton(SCR_InputButtonComponent button)
195 {
196 Widget w = button.GetRootWidget();
197 m_Buttons.Insert(w.GetName(), button);
198
199 button.m_OnActivated.Insert(OnButtonActivated);
200 }
201
202 //------------------------------------------------------------------------------------------------
204 SCR_InputButtonComponent FindButton(string tag)
205 {
206 return m_Buttons.Get(tag);
207 }
208
209 //----------------------------------------------------------------------------------------
211 string GetButtonTag(SCR_InputButtonComponent button)
212 {
213 if(!button)
214 return string.Empty;
215
216 return SCR_MapHelper<string, SCR_InputButtonComponent>.GetKeyByValue(m_Buttons, button);
217 }
218
219 //------------------------------------------------------------------------------------------------
221 bool RemoveButton(string tag)
222 {
223 SCR_InputButtonComponent button = FindButton(tag);
224
225 if (!button)
226 return false;
227
228 m_Buttons.Remove(tag);
229 m_wRoot.RemoveChild(button.GetRootWidget());
230
231 return true;
232 }
233
234 //------------------------------------------------------------------------------------------------
236 void ClearButtons()
237 {
238 foreach (SCR_InputButtonComponent comp : m_Buttons)
239 {
240 m_wRoot.RemoveChild(comp.GetRootWidget());
241 }
242 m_Buttons.Clear();
243 }
244
245 //------------------------------------------------------------------------------------------------
247 array<SCR_InputButtonComponent> GetButtonsInFooter(SCR_EDynamicFooterButtonAlignment alignment)
248 {
249 Widget wrapper;
250 switch (alignment)
251 {
252 case SCR_EDynamicFooterButtonAlignment.LEFT:
253 wrapper = m_wLeftFooter;
254 break;
255
256 case SCR_EDynamicFooterButtonAlignment.RIGHT:
257 wrapper = m_wRightFooter;
258 break;
259 }
260
261 if (!wrapper)
262 return null;
263
264 return SCR_DynamicFooterComponent.FindChildrenButtons(wrapper);
265 }
266
267 //------------------------------------------------------------------------------------------------
268 Widget GetLeftFooter()
269 {
270 return m_wLeftFooter;
271 }
272
273 //------------------------------------------------------------------------------------------------
274 Widget GetRightFooter()
275 {
276 return m_wRightFooter;
277 }
278
279 //------------------------------------------------------------------------------------------------
281 ScriptInvokerString GetOnButtonActivated()
282 {
285
286 return m_OnButtonActivated;
287 }
288
289
290 // ---- STATIC ----
291 //------------------------------------------------------------------------------------------------
292 static array<SCR_InputButtonComponent> FindChildrenButtons(notnull Widget w, bool searchImmediateChildrenOnly = true)
293 {
294 array<SCR_InputButtonComponent> buttons = {};
295 array<ref Widget> children = {};
296
297 SCR_WidgetHelper.GetAllChildren(w, children, !searchImmediateChildrenOnly);
298
299 foreach (Widget child : children)
300 {
301 SCR_InputButtonComponent comp = SCR_InputButtonComponent.FindComponent(child);
302 if (comp)
303 buttons.Insert(comp);
304 }
305
306 return buttons;
307 }
308
309 //------------------------------------------------------------------------------------------------
310 static SCR_DynamicFooterComponent FindComponentInHierarchy(notnull Widget root)
311 {
312 SCR_DynamicFooterComponent comp;
313
314 ScriptedWidgetEventHandler handler = SCR_WidgetTools.FindHandlerInChildren(root, SCR_DynamicFooterComponent);
315 if (handler)
316 comp = SCR_DynamicFooterComponent.Cast(handler);
317
318 return comp;
319 }
320
321 //------------------------------------------------------------------------------------------------
322 static SCR_DynamicFooterComponent FindComponent(notnull Widget w)
323 {
324 return SCR_DynamicFooterComponent.Cast(w.FindHandler(SCR_DynamicFooterComponent));
325 }
326}
327
328enum SCR_EDynamicFooterButtonAlignment
329{
330 LEFT = 0,
331 RIGHT
332}
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector position
UI layouts Menus CleanSweep CleanSweepAreaSelection layout
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerStringMethod > ScriptInvokerString
bool SetAction(string action, EInputDeviceType currentInputDevice=-1, bool forceUpdate=false)
void SetLabel(string label)
PUBLIC API\.
static SCR_InputButtonComponent FindComponent(notnull Widget w)
Definition Types.c:486
SCR_FieldOfViewSettings Attribute
@ LEFT
navigation
@ RIGHT