5 protected string m_sItemHolderName;
8 protected string m_sListWidgetName;
11 protected string m_sListWidgetStripeName;
14 protected string m_sDropdownButtonName;
17 protected string m_DropdownTextName;
20 protected string m_sArrowWidgetName;
23 protected string m_sGamepadHintWidgetName;
26 protected ResourceName m_sItemPrefab;
28 [
Attribute(
"0.025",
"Fade delay in seconds. For every new button that is added the delay increases slightly")]
29 protected float m_fFadeDelayNextButton;
31 [
Attribute(
"4",
"How fast each button appears")]
32 protected float m_fButtonFadeSpeed;
34 [
Attribute(
"-1",
desc:
"How much will the list of controls hints be offset vertically.\nKeep -1 to leave it unaffected.")]
35 protected int m_iAvailableActionsOffsetY;
38 protected Widget m_Root;
39 protected Widget m_ItemHolder;
40 protected Widget m_ListWidget;
42 protected TextWidget m_DropdownText;
43 protected ImageWidget m_ArrowWidget;
45 protected ref array<SCR_ButtonImageComponent> m_aItemButtons = {};
46 protected ref array<SCR_EditorModeUIInfo> m_aModeUIInfo = {};
49 protected bool m_bIsOpened;
50 protected int m_iSelectedItem;
51 protected bool m_bHovered;
53 protected ref ScriptInvoker Event_OnDropdownOpened;
54 protected ref ScriptInvoker Event_OnDropdownClosed;
55 protected ref ScriptInvoker Event_OnChanged;
57 protected int m_iCloseOnIndex;
58 protected bool m_bIsEnabled =
true;
63 void SetDropdownEnable(
bool enable)
78 m_ArrowWidget.SetVisible(
false);
80 Widget gamePadhintWidget =
m_Root.FindAnyWidget(m_sGamepadHintWidgetName);
81 if (gamePadhintWidget)
82 gamePadhintWidget.SetVisible(
false);
99 int index = m_aItemButtons.Find(button);
104 SetCurrentItem(
index,
true);
108 protected void OnDropDownFocus()
113 GetGame().GetWorkspace().SetFocusedWidget(m_aItemButtons[0].GetRootWidget());
117 protected void OnMenuActionLeft()
131 Widget itemWidget =
GetGame().GetWorkspace().CreateWidgets(m_sItemPrefab, m_ItemHolder);
139 newItem.m_OnClicked.Insert(OnItemClicked);
140 m_aItemButtons.Insert(newItem);
141 m_aModeUIInfo.Insert(uiInfo);
143 uiInfo.SetIconTo(newItem.GetImageWidget());
144 newItem.GetImageWidget().SetVisible(
true);
146 TextWidget textWidget = TextWidget.Cast(newItem.GetRootWidget().FindAnyWidget(
"Text"));
148 uiInfo.SetNameTo(textWidget);
150 Widget sideBar = newItem.GetRootWidget().FindAnyWidget(
"SideBar");
153 sideBar.SetColor(uiInfo.GetModeColor());
157 tooltip.SetInfo(uiInfo);
161 itemWidget.RemoveFromHierarchy();
177 void OpenDropdown(
int focusIndex =-1)
183 if (!button.GetRootWidget().IsVisible())
189 fadeComponent.SetFadeInSpeed(m_fButtonFadeSpeed);
190 fadeComponent.DelayedFadeIn(fadeDelay * 1000);
191 fadeDelay += m_fFadeDelayNextButton;
195 if (m_ListWidgetStripeFadeComponent)
196 m_ListWidgetStripeFadeComponent.DelayedFadeIn(fadeDelay * 1000);
198 m_ListWidget.SetVisible(
true);
202 m_ArrowWidget.SetRotation(90);
204 if (m_iAvailableActionsOffsetY != -1)
207 if (availableActionsDisplay)
208 availableActionsDisplay.SetAdditionalOffsetY(m_iAvailableActionsOffsetY);
214 if (Event_OnDropdownOpened)
215 Event_OnDropdownOpened.Invoke(
this);
219 WorkspaceWidget workspace =
GetGame().GetWorkspace();
223 workspace.SetFocusedWidget(m_aItemButtons[focusIndex].GetRootWidget());
227 GetGame().GetInputManager().AddActionListener(
UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuActionLeft);
234 m_ListWidget.SetVisible(
false);
238 m_ArrowWidget.SetRotation(270);
240 if (m_iAvailableActionsOffsetY != -1)
243 if (availableActionsDisplay)
244 availableActionsDisplay.SetAdditionalOffsetY(0);
248 if (Event_OnDropdownClosed)
249 Event_OnDropdownClosed.Invoke(
this);
256 fadeComponent.CancelFade(
false);
259 if (m_ListWidgetStripeFadeComponent)
260 m_ListWidgetStripeFadeComponent.CancelFade(
false);
263 GetGame().GetInputManager().RemoveActionListener(
UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuActionLeft);
266 protected void OnLMB()
268 if (m_bIsOpened && !m_bHovered)
276 void SetCurrentItem(
int index,
bool callOnChanged)
278 m_iSelectedItem =
index;
283 if (!m_aModeUIInfo.IsIndexValid(
index))
289 uiInfo.SetNameTo(m_DropdownText);
291 if (m_DropdownButton)
292 uiInfo.SetIconTo(m_DropdownButton.GetImageWidget());
298 int GetSelectedIndex()
300 return m_iSelectedItem;
311 Widget GetRootWidget()
320 void SetItemEnabled(
int index,
bool enabled)
322 if (index < 0 || index >= m_aItemButtons.Count())
325 m_aItemButtons[
index].GetRootWidget().SetEnabled(enabled);
333 void SetItemVisible(
int index,
bool visible)
335 if (index < 0 || index >= m_aItemButtons.Count())
338 m_aItemButtons[
index].GetRootWidget().SetVisible(visible);
345 ScriptInvoker GetOnChanged()
355 ScriptInvoker GetOnOpened()
357 if (!Event_OnDropdownOpened)
358 Event_OnDropdownOpened =
new ScriptInvoker();
360 return Event_OnDropdownOpened;
365 ScriptInvoker GetOnClosed()
367 if (!Event_OnDropdownClosed)
368 Event_OnDropdownClosed =
new ScriptInvoker();
370 return Event_OnDropdownClosed;
374 protected void OnInputDeviceIsGamepad(
bool isGamepad)
379 m_ArrowWidget.SetVisible(!isGamepad);
381 Widget gamePadhintWidget =
m_Root.FindAnyWidget(m_sGamepadHintWidgetName);
382 if (gamePadhintWidget)
383 gamePadhintWidget.SetVisible(isGamepad);
387 override bool OnMouseEnter(Widget w,
int x,
int y)
394 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
401 override void HandlerAttached(Widget w)
406 GetGame().GetInputManager().AddActionListener(
"MouseLeft", EActionTrigger.DOWN, OnLMB);
408 m_ItemHolder = w.FindAnyWidget(m_sItemHolderName);
409 m_ListWidget = w.FindAnyWidget(m_sListWidgetName);
410 m_ArrowWidget = ImageWidget.Cast(w.FindAnyWidget(m_sArrowWidgetName));
414 Widget listWidgetStripe = m_ListWidget.FindAnyWidget(m_sListWidgetStripeName);
416 if (listWidgetStripe)
420 if (m_ListWidgetStripeFadeComponent)
421 m_ListWidgetStripeFadeComponent.SetFadeInSpeed(m_fButtonFadeSpeed);
426 Widget dropDownWidget = w.FindAnyWidget(m_sDropdownButtonName);
430 m_DropdownText = TextWidget.Cast(w.FindAnyWidget(m_DropdownTextName));
435 m_DropdownButton.m_OnClicked.Insert(OnDropDownClicked);
436 m_DropdownButton.m_OnFocus.Insert(OnDropDownFocus);
438 ScriptInvoker invoker =
GetGame().OnInputDeviceIsGamepadInvoker();
440 invoker.Insert(OnInputDeviceIsGamepad);
446 override void HandlerDeattached(Widget w)
448 ScriptInvoker invoker =
GetGame().OnInputDeviceIsGamepadInvoker();
450 invoker.Remove(OnInputDeviceIsGamepad);
452 GetGame().GetInputManager().RemoveActionListener(
"MouseLeft", EActionTrigger.DOWN, OnLMB);