Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpinBoxComponent.c
Go to the documentation of this file.
2{
3 protected static const ref Color COLOR_HINT_SELECTED = UIColors.CONTRAST_COLOR;
4 protected static const ref Color COLOR_HINT_DESELECTED = UIColors.WHITE_HOVERED;
5
8 protected TextWidget m_wText;
9 protected Widget m_wContent;
11 protected ref array<Widget> m_aHintElements = new array<Widget>();
12
13 [Attribute("false", UIWidgets.CheckBox, "use light grey arrows instead of big yellow ones")]
14 protected bool m_bUseLightArrows;
15
16 [Attribute("false", UIWidgets.CheckBox, "On last item and pressing right arrow, it will go to the start of the list")]
17 protected bool m_bCycleMode;
18
19 [Attribute("true", UIWidgets.CheckBox, "Show bar of available elements and which one is selected.")]
20 protected bool m_bShowHints;
21
22 [Attribute("24", UIWidgets.EditBox, "Width of a hint element")]
23 protected float m_fHintElementWidth;
24
25 [Attribute("4", UIWidgets.EditBox, "Height of a hint element")]
26 protected float m_fHintElementHeight;
27
28 [Attribute("1", UIWidgets.EditBox, "How much wider should be the selected hint element")]
30
31 [Attribute("true", UIWidgets.CheckBox, "Should hints fill the available space")]
32 protected bool m_fHintFillMode;
33
34 [Attribute("4", UIWidgets.EditBox, "How large gaps between hints should there be")]
35 protected float m_fHintSpacing;
36
37 [Attribute("", UIWidgets.EditBox, "")]
39
40 [Attribute("", UIWidgets.EditBox, "")]
42
43 [Attribute("HintBarElement", UIWidgets.EditBox, "Name for generated Hint bar widgets")]
44 protected string m_sHintBarElementName;
45
46//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
47// Old untyped invokers
48
51
52//---- REFACTOR NOTE END ----
53
54 protected bool m_bHasActionListeners;
56
57 //------------------------------------------------------------------------------------------------
58 override void HandlerAttached(Widget w)
59 {
60 super.HandlerAttached(w);
61 m_wText = TextWidget.Cast(w.FindAnyWidget("SelectionText"));
62 m_wContent = w.FindAnyWidget("Overlay");
63 m_wCountBar = w.FindAnyWidget("HintBar");
64
65 // Buttons
66 Widget left = w.FindAnyWidget("ButtonLeft");
67 Widget right = w.FindAnyWidget("ButtonRight");
68
69 if (left)
70 {
72 if (m_ButtonLeft)
73 m_ButtonLeft.m_OnActivated.Insert(OnLeftArrowClick);
74 }
75
76 if (right)
77 {
79 if (m_ButtonRight)
80 m_ButtonRight.m_OnActivated.Insert(OnRightArrowClick);
81 }
82
83 if (m_wText)
84 {
85 if (m_aElementNames && m_iSelectedItem > -1 && m_iSelectedItem < m_aElementNames.Count())
86 m_wText.SetText(m_aElementNames[m_iSelectedItem]);
87 else
88 m_wText.SetText(string.Empty);
89 }
90
91 SetInitialState(false);
92 }
93
94 //------------------------------------------------------------------------------------------------
95 override bool OnFocus(Widget w, int x, int y)
96 {
97 super.OnFocus(w, x, y);
98
100
102 return false;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 override bool OnFocusLost(Widget w, int x, int y)
107 {
108 super.OnFocusLost(w, x, y);
109
112
114 return false;
115 }
116
117 //TODO: revise this logic: there should be no reason to reset current item every time a new one is added or removed
118 //------------------------------------------------------------------------------------------------
119 override int AddItem(string item, bool last = false, Managed data = null)
120 {
121 int i = super.AddItem(item, last, data);
122
123 SetInitialState(last);
124 return i;
125 }
126
127 //------------------------------------------------------------------------------------------------
128 override void RemoveItem(int item, bool last = false)
129 {
130 super.RemoveItem(item, last);
131 SetInitialState(last);
132 }
133
134 //------------------------------------------------------------------------------------------------
135 override void ClearAll()
136 {
137 super.ClearAll();
138 SetInitialState(true);
139 }
140
141 //------------------------------------------------------------------------------------------------
142 override bool SetCurrentItem(int i, bool playSound = false, bool animate = false)
143 {
144 return SetCurrentItem_Internal(i, playSound, animate, true);
145 }
146
147 // --- Protected ---
148 //------------------------------------------------------------------------------------------------
149 protected bool SetCurrentItem_Internal(int i, bool playSound, bool animate, bool invokeOnChanged)
150 {
151 int lastIndex = m_iSelectedItem;
152 if (!super.SetCurrentItem(i, playSound, animate))
153 return false;
154
155 if (m_wText)
156 m_wText.SetText(m_aElementNames[i]);
157
158 if (m_bShowHints)
159 UpdateHintBar(i, lastIndex);
160
161 EnableArrows(i, animate);
162
163 if (invokeOnChanged)
164 m_OnChanged.Invoke(this, m_iSelectedItem);
165
166 return true;
167 }
168
169 //------------------------------------------------------------------------------------------------
170 protected void CreateHintBar()
171 {
172 // Delete any old elements
173 foreach (Widget w : m_aHintElements)
174 {
175 w.RemoveFromHierarchy();
176 }
177 m_aHintElements.Clear();
178
179 m_wCountBar.SetVisible(true);
180
181 for (int i = 0, len = m_aElementNames.Count(); i < len; i++)
182 {
183 Widget w = GetGame().GetWorkspace().CreateWidget(WidgetType.ImageWidgetTypeID, WidgetFlags.VISIBLE | WidgetFlags.STRETCH | WidgetFlags.BLEND | WidgetFlags.INHERIT_CLIPPING, Color.FromInt(Color.WHITE), 0, m_wCountBar);
184 ImageWidget img = ImageWidget.Cast(w);
185 if (!img)
186 break;
187
189 // Force size only when sizes are more than 0 - automatic sizing
192
193 img.SetColor(COLOR_HINT_DESELECTED);
194 HorizontalLayoutSlot.SetPadding(img, m_fHintSpacing * 0.5, 0, m_fHintSpacing * 0.5, 0);
195 HorizontalLayoutSlot.SetHorizontalAlign(img, LayoutHorizontalAlign.Stretch);
196
197 // Use fill instead
198 if (m_fHintFillMode)
199 HorizontalLayoutSlot.SetSizeMode(img, LayoutSizeMode.Fill);
200
201 m_aHintElements.Insert(img);
202 img.SetName(m_sHintBarElementName + i);
203 }
204
206 }
207
208 //------------------------------------------------------------------------------------------------
209 protected void UpdateHintBar(int currentIndex, int oldIndex)
210 {
211 if (!m_bShowHints)
212 return;
213
214 bool focused = GetGame().GetWorkspace().GetFocusedWidget() == m_wRoot;
215
216 int count = m_aHintElements.Count();
217 if (oldIndex > -1 && oldIndex < count)
218 {
222 }
223
224 if (currentIndex > -1 && currentIndex < count)
225 {
229 }
230 }
231
232 //------------------------------------------------------------------------------------------------
233 protected void SetInitialState(bool invokeOnChanged = true)
234 {
235 int realIndex = m_iSelectedItem;
236 if (realIndex < 0 || realIndex >= m_aElementNames.Count())
237 realIndex = 0;
238
239 m_iSelectedItem = int.MIN;
240 SetCurrentItem_Internal(realIndex, false, false, invokeOnChanged);
241
242 if (m_bShowHints && m_aElementNames && m_wCountBar)
244 }
245
246 //------------------------------------------------------------------------------------------------
248 protected void EnableArrows(int selected, bool animate)
249 {
251 return;
252
253 if (m_bCycleMode)
254 {
255 bool enabled = m_aElementNames.Count() > 1;
256 m_ButtonLeft.SetEnabled(enabled, animate);
257 m_ButtonRight.SetEnabled(enabled, animate);
258 }
259 else
260 {
261 m_ButtonLeft.SetEnabled(selected != 0, animate);
262 m_ButtonRight.SetEnabled(selected != (m_aElementNames.Count() - 1), animate);
263 }
264 }
265
266 //------------------------------------------------------------------------------------------------
267 protected void OnLeftArrowClick()
268 {
269 GetGame().GetWorkspace().SetFocusedWidget(m_wRoot);
270
271 if (m_iSelectedItem <= 0)
272 {
273 if (m_bCycleMode)
274 SetCurrentItem(m_aElementNames.Count() - 1, true, true);
275 }
276 else
277 {
278 SetCurrentItem(m_iSelectedItem - 1, true, true);
279 }
280
282 m_OnLeftArrowClick.Invoke();
283 }
284
285 //------------------------------------------------------------------------------------------------
286 protected void OnRightArrowClick()
287 {
288 GetGame().GetWorkspace().SetFocusedWidget(m_wRoot);
289
290 if (m_iSelectedItem >= (m_aElementNames.Count() - 1))
291 {
292 if (m_bCycleMode)
293 SetCurrentItem(0, true, true);
294 }
295 else
296 {
297 SetCurrentItem(m_iSelectedItem + 1, true, true);
298 }
299
301 m_OnRightArrowClick.Invoke();
302 }
303
304//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
305// Directly calling OnClick, even if it's public, feels rather hacky, as it is triggered by the C++ widget classes, and here we do not even provide proper data in params
306
307 //------------------------------------------------------------------------------------------------
308 protected void OnMenuLeft()
309 {
310 if (GetGame().GetWorkspace().GetFocusedWidget() != m_wRoot && !m_bAllowSwitchingWithoutFocus)
311 return;
312
313 if (m_ButtonLeft && m_ButtonLeft.IsEnabled())
314 m_ButtonLeft.OnClick(m_ButtonLeft.m_wRoot, 0, 0, 0); // TODO: Replace with other function, which accepts more params (turn of anims and sounds separately)
315 }
316
317 //------------------------------------------------------------------------------------------------
318 protected void OnMenuRight()
319 {
320 if (GetGame().GetWorkspace().GetFocusedWidget() != m_wRoot && !m_bAllowSwitchingWithoutFocus)
321 return;
322
323 if (m_ButtonRight && m_ButtonRight.IsEnabled())
324 m_ButtonRight.OnClick(m_ButtonRight.m_wRoot, 0, 0, 0); // TODO: Replace with other function, which accepts more params (turn of anims and sounds separately)
325 }
326
327//---- REFACTOR NOTE END ----
328
329 // --- Public ---
330 //------------------------------------------------------------------------------------------------
332 {
334 return;
335
336 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuLeft);
337 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnMenuRight);
338
340 }
341
342 //------------------------------------------------------------------------------------------------
344 {
346 return;
347
348 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuLeft);
349 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnMenuRight);
350
351 m_bHasActionListeners = false;
352 }
353
354 //------------------------------------------------------------------------------------------------
355 // Determines if left/right page switch action listeners should be removed on focus lost
357 {
359 }
360
361 //------------------------------------------------------------------------------------------------
362 void SetCycleMode(bool cycle)
363 {
364 m_bCycleMode = cycle;
366 }
367
368 //------------------------------------------------------------------------------------------------
376
377 //------------------------------------------------------------------------------------------------
385
386 //------------------------------------------------------------------------------------------------
389 static SCR_SpinBoxComponent GetSpinBoxComponent(string name, Widget parent, bool searchAllChildren = true)
390 {
391 return SCR_SpinBoxComponent.Cast(SCR_ScriptedWidgetComponent.GetComponent(SCR_SpinBoxComponent, name, parent, searchAllChildren));
392 }
393}
ArmaReforgerScripted GetGame()
Definition game.c:1398
Get all prefabs that have the spawner data
Widget m_wRoot
static WidgetAnimationColor Color(Widget widget, Color color, float speed)
static WidgetAnimationLayoutFill LayoutFill(Widget widget, float targetValue, float speed)
Definition Color.c:13
static SCR_ScriptedWidgetComponent GetComponent(typename componentType, string name, Widget parent, bool searchAllChildren=true)
Base method for component lookup through the widget library.
ref ScriptInvoker m_OnRightArrowClick
ref array< Widget > m_aHintElements
override bool OnFocus(Widget w, int x, int y)
override void RemoveItem(int item, bool last=false)
void SetInitialState(bool invokeOnChanged=true)
ref ScriptInvoker m_OnLeftArrowClick
override bool OnFocusLost(Widget w, int x, int y)
void UpdateHintBar(int currentIndex, int oldIndex)
SCR_PagingButtonComponent m_ButtonRight
SCR_PagingButtonComponent m_ButtonLeft
static const ref Color COLOR_HINT_SELECTED
static const ref Color COLOR_HINT_DESELECTED
ScriptInvoker GetOnRightArrowClick()
ScriptInvoker GetOnLeftArrowClick()
bool SetCurrentItem_Internal(int i, bool playSound, bool animate, bool invokeOnChanged)
static SCR_SpinBoxComponent GetSpinBoxComponent(string name, Widget parent, bool searchAllChildren=true)
override bool SetCurrentItem(int i, bool playSound=false, bool animate=false)
void EnableArrows(int selected, bool animate)
Based on cycle mode set which arrow should be enabled at given selection.
override int AddItem(string item, bool last=false, Managed data=null)
void SetCycleMode(bool cycle)
override void HandlerAttached(Widget w)
void SetKeepActionListeners(bool keep)
static bool SetTexture(ImageWidget widget, ResourceName texture, string image="")
SCR_FieldOfViewSettings Attribute
EActionTrigger
WidgetFlags
Widget flags. See enf::Widget::SetFlags().
Definition WidgetFlags.c:14
LayoutHorizontalAlign
LayoutSizeMode
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134