Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CustomDropdownEditorUIComponent.c
Go to the documentation of this file.
2{
3 //TODO: Check how to close the drop down if anything else is clicked (How does the combobox work?)
4 [Attribute("ItemHolder")]
5 protected string m_sItemHolderName;
6
7 [Attribute("ModeSelection_List0")]
8 protected string m_sListWidgetName;
9
10 [Attribute("Stripe")]
11 protected string m_sListWidgetStripeName;
12
13 [Attribute("ModeSelection_Mode0")]
14 protected string m_sDropdownButtonName;
15
16 [Attribute("Content")]
17 protected string m_DropdownTextName;
18
19 [Attribute("PcArrow")]
20 protected string m_sArrowWidgetName;
21
22 [Attribute("GamepadHint")]
23 protected string m_sGamepadHintWidgetName;
24
25 [Attribute()]
27
28 [Attribute("0.025", "Fade delay in seconds. For every new button that is added the delay increases slightly")]
29 protected float m_fFadeDelayNextButton;
30
31 [Attribute("4", "How fast each button appears")]
32 protected float m_fButtonFadeSpeed;
33
34 [Attribute("-1", desc: "How much will the list of controls hints be offset vertically.\nKeep -1 to leave it unaffected.")]
36
37 //Refs
38 protected Widget m_Root;
45 protected ref array<SCR_ButtonImageComponent> m_aItemButtons = {};
46 protected ref array<SCR_EditorModeUIInfo> m_aModeUIInfo = {};
47
48 //States
49 protected bool m_bIsOpened;
50 protected int m_iSelectedItem;
51 protected bool m_bHovered;
52
56
57 protected int m_iCloseOnIndex;
58 protected bool m_bIsEnabled = true;
59
60 //------------------------------------------------------------------------------------------------
63 void SetDropdownEnable(bool enable)
64 {
65 m_bIsEnabled = enable;
66
67 if (m_bIsOpened)
69
70 m_Root.SetEnabled(enable);
71
72 if (enable)
73 {
74 OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
75 }
76 else
77 {
78 m_ArrowWidget.SetVisible(false);
79
80 Widget gamePadhintWidget = m_Root.FindAnyWidget(m_sGamepadHintWidgetName);
81 if (gamePadhintWidget)
82 gamePadhintWidget.SetVisible(false);
83 }
84
85 }
86
87 //------------------------------------------------------------------------------------------------
89 {
90 if (m_bIsOpened)
92 else
94 }
95
96 //------------------------------------------------------------------------------------------------
98 {
99 int index = m_aItemButtons.Find(button);
100
101 if (index < 0)
102 return;
103
104 SetCurrentItem(index, true);
105 }
106
107 //------------------------------------------------------------------------------------------------
108 protected void OnDropDownFocus()
109 {
110 if (!m_bIsOpened)
111 OpenDropdown();
112
113 GetGame().GetWorkspace().SetFocusedWidget(m_aItemButtons[0].GetRootWidget());
114 }
115
116 //------------------------------------------------------------------------------------------------
117 protected void OnMenuActionLeft()
118 {
120 }
121
122 //------------------------------------------------------------------------------------------------
127 {
128 if (!m_ItemHolder)
129 return;
130
131 Widget itemWidget = GetGame().GetWorkspace().CreateWidgets(m_sItemPrefab, m_ItemHolder);
132 if (!itemWidget)
133 return;
134
135 SCR_ButtonImageComponent newItem = SCR_ButtonImageComponent.Cast(itemWidget.FindHandler(SCR_ButtonImageComponent));
136
137 if (newItem)
138 {
139 newItem.m_OnClicked.Insert(OnItemClicked);
140 m_aItemButtons.Insert(newItem);
141 m_aModeUIInfo.Insert(uiInfo);
142
143 uiInfo.SetIconTo(newItem.GetImageWidget());
144 newItem.GetImageWidget().SetVisible(true);
145
146 TextWidget textWidget = TextWidget.Cast(newItem.GetRootWidget().FindAnyWidget("Text"));
147 if (textWidget)
148 uiInfo.SetNameTo(textWidget);
149
150 Widget sideBar = newItem.GetRootWidget().FindAnyWidget("SideBar");
151
152 if (sideBar)
153 sideBar.SetColor(uiInfo.GetModeColor());
154
156 if (tooltip)
157 tooltip.SetInfo(uiInfo);
158 }
159 else
160 {
161 itemWidget.RemoveFromHierarchy();
162 }
163 }
164
165 //------------------------------------------------------------------------------------------------
169 bool IsOpened()
170 {
171 return m_bIsOpened;
172 }
173
174 //---- REFACTOR NOTE START: 90 and 270 rotation is understandable but it might be hard to find in case of tweaking
175
176 //------------------------------------------------------------------------------------------------
179 void OpenDropdown(int focusIndex =-1)
180 {
181 float fadeDelay = 0;
182 SCR_FadeUIComponent fadeComponent
184 {
185 if (!button.GetRootWidget().IsVisible())
186 continue;
187
188 fadeComponent = SCR_FadeUIComponent.Cast(button.GetRootWidget().FindHandler(SCR_FadeUIComponent));
189 if (fadeComponent)
190 {
191 fadeComponent.SetFadeInSpeed(m_fButtonFadeSpeed);
192 fadeComponent.DelayedFadeIn(fadeDelay * 1000);
193 fadeDelay += m_fFadeDelayNextButton;
194 }
195 }
196
198 m_ListWidgetStripeFadeComponent.DelayedFadeIn(fadeDelay * 1000);
199
200 m_ListWidget.SetVisible(true);
201
202 // Set arrow image angle
203 if (m_ArrowWidget)
204 m_ArrowWidget.SetRotation(90);
205
207 {
208 SCR_AvailableActionsDisplay availableActionsDisplay = SCR_AvailableActionsDisplay.Cast(GetGame().GetHUDManager().FindInfoDisplay(SCR_AvailableActionsDisplay));
209 if (availableActionsDisplay)
210 availableActionsDisplay.SetAdditionalOffsetY(m_iAvailableActionsOffsetY);
211 }
212
213 //Rotate arrow
214
215 m_bIsOpened = true;
217 Event_OnDropdownOpened.Invoke(this);
218
219 if (focusIndex > -1)
220 {
221 WorkspaceWidget workspace = GetGame().GetWorkspace();
222 if (!workspace)
223 return;
224
225 workspace.SetFocusedWidget(m_aItemButtons[focusIndex].GetRootWidget());
226 }
227
228 // Setup action listeners
229 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuActionLeft);
230 }
231
232 //------------------------------------------------------------------------------------------------
235 {
236 m_ListWidget.SetVisible(false);
237
238 // Set arrow image angle
239 if (m_ArrowWidget)
240 m_ArrowWidget.SetRotation(270);
241
243 {
244 SCR_AvailableActionsDisplay availableActionsDisplay = SCR_AvailableActionsDisplay.Cast(GetGame().GetHUDManager().FindInfoDisplay(SCR_AvailableActionsDisplay));
245 if (availableActionsDisplay)
246 availableActionsDisplay.SetAdditionalOffsetY(0);
247 }
248
249 m_bIsOpened = false;
251 Event_OnDropdownClosed.Invoke(this);
252
253 SCR_FadeUIComponent fadeComponent;
255 {
256 fadeComponent = SCR_FadeUIComponent.Cast(button.GetRootWidget().FindHandler(SCR_FadeUIComponent));
257 if (fadeComponent)
258 fadeComponent.CancelFade(false);
259 }
260
262 m_ListWidgetStripeFadeComponent.CancelFade(false);
263
264 // Remove action listeners
265 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuActionLeft);
266 }
267
268 //---- REFACTOR NOTE END ----
269
270 protected void OnLMB()
271 {
272 if (m_bIsOpened && !m_bHovered)
274 }
275
276 //------------------------------------------------------------------------------------------------
280 void SetCurrentItem(int index, bool callOnChanged)
281 {
283
284 if (callOnChanged && Event_OnChanged)
285 Event_OnChanged.Invoke(this, index);
286
287 if (!m_aModeUIInfo.IsIndexValid(index))
288 return;
289
291
292 if (m_DropdownText)
293 uiInfo.SetNameTo(m_DropdownText);
294
296 uiInfo.SetIconTo(m_DropdownButton.GetImageWidget());
297 }
298
299 //------------------------------------------------------------------------------------------------
303 {
304 return m_iSelectedItem;
305 }
306
307// //------------------------------------------------------------------------------------------------
308// //! Clear all elements
309// void ClearAll()
310// {
311// }
312
313 //------------------------------------------------------------------------------------------------
316 {
317 return m_Root;
318 }
319
320 //------------------------------------------------------------------------------------------------
324 void SetItemEnabled(int index, bool enabled)
325 {
327 return;
328
329 m_aItemButtons[index].GetRootWidget().SetEnabled(enabled);
330 }
331
332 //------------------------------------------------------------------------------------------------
337 void SetItemVisible(int index, bool visible)
338 {
340 return;
341
342 m_aItemButtons[index].GetRootWidget().SetVisible(visible);
343 }
344
346
347 //------------------------------------------------------------------------------------------------
350 {
351 if (!Event_OnChanged)
353
354 return Event_OnChanged;
355 }
356
357 //------------------------------------------------------------------------------------------------
366
367 //------------------------------------------------------------------------------------------------
376
377 //------------------------------------------------------------------------------------------------
378 protected void OnInputDeviceIsGamepad(bool isGamepad)
379 {
380 if (!m_bIsEnabled)
381 return;
382
383 m_ArrowWidget.SetVisible(!isGamepad);
384
385 Widget gamePadhintWidget = m_Root.FindAnyWidget(m_sGamepadHintWidgetName);
386 if (gamePadhintWidget)
387 gamePadhintWidget.SetVisible(isGamepad);
388 }
389
390 //------------------------------------------------------------------------------------------------
391 override bool OnMouseEnter(Widget w, int x, int y)
392 {
393 m_bHovered = true;
394 return false;
395 }
396
397 //------------------------------------------------------------------------------------------------
398 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
399 {
400 m_bHovered = false;
401 return false;
402 }
403
404 //------------------------------------------------------------------------------------------------
405 override void HandlerAttached(Widget w)
406 {
407 if (SCR_Global.IsEditMode())
408 return;
409
410 GetGame().GetInputManager().AddActionListener("MouseLeft", EActionTrigger.DOWN, OnLMB);
411 m_Root = w;
412 m_ItemHolder = w.FindAnyWidget(m_sItemHolderName);
413 m_ListWidget = w.FindAnyWidget(m_sListWidgetName);
414 m_ArrowWidget = ImageWidget.Cast(w.FindAnyWidget(m_sArrowWidgetName));
415
416 if (m_ListWidget)
417 {
418 Widget listWidgetStripe = m_ListWidget.FindAnyWidget(m_sListWidgetStripeName);
419
420 if (listWidgetStripe)
421 {
422 m_ListWidgetStripeFadeComponent = SCR_FadeUIComponent.Cast(listWidgetStripe.FindHandler(SCR_FadeUIComponent));
423
426 }
427 }
428
429
430 Widget dropDownWidget = w.FindAnyWidget(m_sDropdownButtonName);
431 if (!dropDownWidget)
432 return;
433
434 m_DropdownText = TextWidget.Cast(w.FindAnyWidget(m_DropdownTextName));
435 if (!m_DropdownText)
436 return;
437
438 m_DropdownButton = SCR_ButtonImageComponent.Cast(dropDownWidget.FindHandler(SCR_ButtonImageComponent));
439 m_DropdownButton.m_OnClicked.Insert(OnDropDownClicked);
440 m_DropdownButton.m_OnFocus.Insert(OnDropDownFocus);
441
442 ScriptInvoker invoker = GetGame().OnInputDeviceIsGamepadInvoker();
443 if (invoker)
444 invoker.Insert(OnInputDeviceIsGamepad);
445
446 OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
447 }
448
449 //------------------------------------------------------------------------------------------------
450 override void HandlerDeattached(Widget w)
451 {
452 ScriptInvoker invoker = GetGame().OnInputDeviceIsGamepadInvoker();
453 if (invoker)
454 invoker.Remove(OnInputDeviceIsGamepad);
455
456 GetGame().GetInputManager().RemoveActionListener("MouseLeft", EActionTrigger.DOWN, OnLMB);
457 }
458}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_HUDManagerComponent GetHUDManager()
Definition game.c:1151
InputManager GetInputManager()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void OnDropDownClicked(SCR_ButtonImageComponent button)
ref array< SCR_ButtonImageComponent > m_aItemButtons
override bool OnMouseEnter(Widget w, int x, int y)
void OnItemClicked(SCR_ButtonImageComponent button)
void AddItem(SCR_EditorModeUIInfo uiInfo, Color color)
void CancelFade(bool callFadeDone)
static bool IsEditMode()
Definition Functions.c:1566
SCR_FieldOfViewSettings Attribute
EActionTrigger
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134