3 [
Attribute(
"-1", UIWidgets.EditBox,
"Maximum size of the list without using scrollbar. -1 for no limit")]
4 float m_fMaxListHeight;
6 [
Attribute(
"true", UIWidgets.CheckBox,
"Create the list below or above or below the root widget")]
7 bool m_bCreateListBelow;
9 [
Attribute(
"{B8C4345E3A833B05}UI/layouts/WidgetLibrary/ComboBox/WLib_OpenedComboRoot.layout", UIWidgets.ResourceNamePicker,
"Combo box element",
"layout")]
10 ResourceName m_sListRootLayout;
12 [
Attribute(
"{323CF37F81DF9B8A}UI/layouts/Common/Settings/ComboBox/ARComboBoxElement.layout", UIWidgets.ResourceNamePicker,
"Combo box element",
"layout")]
13 ResourceName m_sElementLayout;
15 [
Attribute(
"0", UIWidgets.EditBox,
"Gap between combo root and combo box items")]
18 [
Attribute(
"0", UIWidgets.EditBox,
"Extra pixels to the left from the center of the widget")]
19 float m_fExtraPaddingLeft;
21 [
Attribute(
"0", UIWidgets.EditBox,
"Extra pixels to the right from the center of the widget")]
22 float m_fExtraPaddingRight;
24 [
Attribute(
"0", UIWidgets.EditBox,
"Starting angle of arrow icon to coordinate texture rotation")]
25 protected float m_fArrowDefaultAngle;
27 [
Attribute(
"0", UIWidgets.CheckBox,
"Allow manual drop down list width enforcing")]
28 protected bool m_bForceListWidth;
30 [
Attribute(
"200", UIWidgets.EditBox,
"How wide should drop down list be")]
31 protected float m_fListForcedWidth;
33 [
Attribute(
"0", UIWidgets.EditBox,
"How wide should drop down list be")]
34 protected float m_fListXOffset;
37 protected string m_sSoundClosed;
40 protected string m_sButton;
43 protected ref Color m_BackgroundDefault;
46 protected ref Color m_BackgroundInteracting;
49 protected ref Color m_ArrowDefault;
52 protected ref Color m_ArrowInteracting;
55 protected ref Color m_ArrowFocused;
57 [
Attribute(
"0",
desc:
"Should the arrow flip when the Combo box is opened")]
58 protected bool m_bRotateArrow;
60 protected InputManager m_InputManager;
61 protected ref array<Widget> m_aElementWidgets =
new array<Widget>();
62 protected Widget m_wButton;
63 protected ImageWidget m_wArrowImage;
64 protected TextWidget m_wText;
65 protected VerticalLayoutWidget m_wContent;
66 protected ScrollLayoutWidget m_wScrollLayout;
67 protected Widget m_wElementsRoot;
68 protected Widget m_wContentRoot;
69 protected WorkspaceWidget m_Workspace;
71 protected bool m_bOpened;
74 ref ScriptInvoker m_OnOpened =
new ScriptInvoker();
75 ref ScriptInvoker m_OnClosed =
new ScriptInvoker();
77 protected float posX, posY;
79 protected Widget m_wTextBackground;
81 protected const int INITIALIZATION_CHECK_FREQUENCY = 10;
84 override void HandlerAttached(Widget w)
86 super.HandlerAttached(w);
89 m_wText = TextWidget.Cast(w.FindAnyWidget(
"Content"));
90 m_wContentRoot = w.FindAnyWidget(
"ComboButton");
96 comp.GetOnClick().Insert(OpenList);
97 comp.GetOnMouseEnter().Insert(OnHandlerHovered);
98 comp.GetOnMouseLeave().Insert(OnHandlerUnhovered);
99 comp.GetOnFocus().Insert(OnHandlerFocus);
100 comp.GetOnFocusLost().Insert(OnHandlerFocusLost);
107 m_wArrowImage = ImageWidget.Cast(w.FindAnyWidget(
"ImageArrow"));
110 m_wArrowImage.SetRotation(m_fArrowDefaultAngle);
111 m_wArrowImage.SetColor(m_ArrowDefault);
116 Widget overlayText = w.FindAnyWidget(
"OverlayText");
118 m_wTextBackground = overlayText.FindAnyWidget(
"Background");
120 if(m_wTextBackground)
121 m_wTextBackground.SetColor(m_BackgroundDefault);
128 override void HandlerDeattached(Widget w)
130 super.HandlerDeattached(w);
137 protected bool OnHandlerClicked()
147 override bool OnFocus(Widget w,
int x,
int y)
151 GetGame().GetWorkspace().SetFocusedWidget(m_wContentRoot);
157 override bool OnFocusLost(Widget w,
int x,
int y)
164 protected void OnHandlerFocus()
170 m_wRoot.SetFlags(WidgetFlags.NOFOCUS);
174 protected void OnHandlerFocusLost()
177 super.OnFocusLost(
m_wRoot, 0, 0);
180 m_wRoot.ClearFlags(WidgetFlags.NOFOCUS);
184 protected void OnHandlerHovered()
187 AnimateWidget.Color(m_wArrowImage, m_ArrowFocused, m_fAnimationRate);
191 protected void OnHandlerUnhovered()
195 Color color = m_ArrowDefault;
198 color = m_ArrowInteracting;
200 AnimateWidget.Color(m_wArrowImage, color, m_fAnimationRate);
212 override protected void OnEnabled(
bool animate)
214 super.OnEnabled(animate);
221 override protected void OnDisabled(
bool animate)
223 super.OnDisabled(animate);
230 protected void UpdateName()
235 if (m_aElementNames && m_iSelectedItem > -1 && m_iSelectedItem < m_aElementNames.Count())
236 m_wText.SetText(m_aElementNames[m_iSelectedItem]);
238 m_wText.SetText(
string.Empty);
242 override bool SetCurrentItem(
int i,
bool playSound =
false,
bool animate =
false)
244 bool result = super.SetCurrentItem(i, playSound, animate);
258 foreach (Widget w : m_aElementWidgets)
260 w.RemoveFromHierarchy();
262 m_aElementWidgets.Clear();
264 foreach (
int i,
string name : m_aElementNames)
270 if (!m_wElementsRoot.IsVisible())
271 m_wElementsRoot.SetVisible(
true);
273 m_aElementWidgets.Insert(w);
274 OnCreateElement(w, i);
279 if (i == m_iSelectedItem)
281 GetGame().GetWorkspace().SetFocusedWidget(comp.GetRootWidget());
282 comp.SetToggled(
true,
false,
false);
285 comp.SetText(m_aElementNames[i]);
286 comp.m_OnClicked.Insert(OnElementSelected);
292 if (m_iSelectedItem > -1 && m_iSelectedItem < m_aElementWidgets.Count())
293 GetGame().GetWorkspace().AddModal(m_wElementsRoot, m_aElementWidgets[m_iSelectedItem]);
294 else if (m_aElementWidgets.Count() > 0 && m_aElementWidgets[0])
295 GetGame().GetWorkspace().AddModal(m_wElementsRoot, m_aElementWidgets[0]);
298 GetGame().GetCallqueue().Remove(CheckElementsInitialized);
299 GetGame().GetCallqueue().CallLater(CheckElementsInitialized, INITIALIZATION_CHECK_FREQUENCY,
true);
303 protected void CheckElementsInitialized()
305 if (!m_bOpened || m_aElementWidgets.IsEmpty())
307 GetGame().GetCallqueue().Remove(CheckElementsInitialized);
311 int initializedItems;
312 float totalItems = m_aElementWidgets.Count();
314 foreach (Widget element : m_aElementWidgets)
317 element.GetScreenSize(x, y);
323 if (initializedItems != totalItems)
328 m_wScrollLayout.SetSliderPos(0, m_iSelectedItem / totalItems,
true);
330 GetGame().GetCallqueue().Remove(CheckElementsInitialized);
336 if (m_bOpened || !m_aElementNames || !m_wContentRoot)
343 if(m_wTextBackground)
344 AnimateWidget.Color(m_wTextBackground, m_BackgroundInteracting, m_fAnimationRate);
348 m_InputManager.AddActionListener(
"MenuBack", EActionTrigger.DOWN, OnMenuBack);
350 m_InputManager.AddActionListener(
"MenuBackWB", EActionTrigger.DOWN, OnMenuBack);
354 m_wContentRoot.GetScreenPos(x, y);
355 m_wContentRoot.GetScreenSize(w, h);
364 x += m_fExtraPaddingLeft;
365 w -= m_fExtraPaddingLeft + m_fExtraPaddingRight;
367 m_wElementsRoot =
GetGame().GetWorkspace().CreateWidgets(m_sListRootLayout,
GetGame().GetWorkspace());
368 if (m_aElementData.IsEmpty())
369 m_wElementsRoot.SetVisible(
false);
371 if (!m_wElementsRoot)
375 m_wContent = VerticalLayoutWidget.Cast(m_wElementsRoot.FindAnyWidget(
"Content"));
379 if (m_bCreateListBelow)
381 y += h + m_fItemsGap;
386 m_wContent.SetFillOrigin(VerticalFillOrigin.BOTTOM);
389 separator.SetZOrder(-1);
393 FrameSlot.SetPos(m_wElementsRoot, x + m_fListXOffset, y);
394 SizeLayoutWidget size = SizeLayoutWidget.Cast(m_wElementsRoot.FindAnyWidget(
"SizeLayout"));
397 size.EnableWidthOverride(
true);
399 if (m_bForceListWidth)
400 size.SetWidthOverride(m_fListForcedWidth);
402 size.SetWidthOverride(w);
404 if (m_fMaxListHeight > 0)
406 size.SetMaxDesiredHeight(m_fMaxListHeight);
407 size.EnableMaxDesiredHeight(
true);
412 m_wScrollLayout = ScrollLayoutWidget.Cast(m_wElementsRoot.FindAnyWidget(
"ScrollLayout"));
419 m_wElementsRoot.AddHandler(m_ModalHandler);
420 m_ModalHandler.m_OnModalClickOut.Insert(CloseList);
423 m_ModalHandler.SetupOwners(
this, menu);
429 m_wArrowImage.SetRotation(m_fArrowDefaultAngle + 180);
431 AnimateWidget.Color(m_wArrowImage, m_ArrowInteracting, m_fAnimationRate);
435 m_OnOpened.Invoke(
this);
439 protected void OnCreateElement(Widget elementWidget,
int index)
446 GetGame().GetCallqueue().Remove(CheckElementsInitialized);
448 if (!m_bOpened || !m_wElementsRoot || !m_aElementNames)
452 if(m_wTextBackground)
453 AnimateWidget.Color(m_wTextBackground, m_BackgroundDefault, m_fAnimationRate);
456 GetGame().GetInputManager().RemoveActionListener(
"MenuBack", EActionTrigger.DOWN, OnMenuBack);
458 GetGame().GetInputManager().RemoveActionListener(
"MenuBackWB", EActionTrigger.DOWN, OnMenuBack);
462 m_wElementsRoot.RemoveFromHierarchy();
464 foreach (Widget w : m_aElementWidgets)
473 comp.m_OnToggled.Remove(OnElementSelected);
475 m_aElementWidgets.Clear();
478 m_wRoot.SetNavigation(WidgetNavigationDirection.UP, WidgetNavigationRuleType.ESCAPE);
479 m_wRoot.SetNavigation(WidgetNavigationDirection.DOWN, WidgetNavigationRuleType.ESCAPE);
481 GetGame().GetWorkspace().SetFocusedWidget(m_wContentRoot);
487 m_wArrowImage.SetRotation(m_fArrowDefaultAngle);
489 AnimateWidget.Color(m_wArrowImage, m_ArrowDefault, m_fAnimationRate);
493 m_OnClosed.Invoke(
this);
497 protected void OnMenuBack()
504 override int AddItem(
string item,
bool last =
false, Managed
data =
null)
506 int i = super.AddItem(item, last,
data);
515 override void ClearAll()
524 override void RemoveItem(
int item,
bool last =
false)
526 super.RemoveItem(item, last);
535 int i = m_aElementWidgets.Find(comp.m_wRoot);
538 SetCurrentItem(i,
true,
true);
540 m_wText.SetText(m_aElementNames[i]);
552 int GetElementWidgets(notnull array<Widget> elementWidgets)
554 foreach (Widget w: m_aElementWidgets)
555 elementWidgets.Insert(w);
557 return elementWidgets.Count();
569 static SCR_ComboBoxComponent GetComboBoxComponent(
string name, Widget parent,
bool searchAllChildren =
true)
584 ref ScriptInvoker m_OnModalClickOut =
new ScriptInvoker();
587 override bool OnModalClickOut(Widget modalRoot,
int x,
int y,
int button)
589 m_OnModalClickOut.Invoke();
594 override void HandlerDeattached(Widget w)
611 protected void OnMenuUpdate(
float tDelta)
621 if (!
m_Owner.GetRootWidget().IsVisibleInHierarchy())