DayZ 1.24
Loading...
Searching...
No Matches
DropdownPrefab.c
Go to the documentation of this file.
1class DropdownPrefab extends ScriptedWidgetEventHandler
2{
3 protected Widget m_Root;
4 protected Widget m_Parent;
7 protected ref array<Widget> m_Content = new array<Widget>;
8
9 protected Widget m_Button;
10 protected Widget m_Holder;
11 protected TextWidget m_Text;
14
15 protected bool m_IsExpanded;
16 ref ScriptInvoker m_OnSelectItem = new ScriptInvoker();
17
18 void DropdownPrefab(Widget root, string text = "")
19 {
20 m_Parent = root;
21 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/dropdown_prefab/dropdown_prefab.layout", root);
22
23 m_Scroller = ScrollWidget.Cast(m_Root.FindAnyWidget("dropdown_container"));
24 m_ContentContainer = m_Root.FindAnyWidget("dropdown_content");
25 m_Text = TextWidget.Cast(m_Root.FindAnyWidget("dropdown_text"));
26 m_Holder = m_Root.FindAnyWidget("holder");
28
29 m_Button = m_Root.FindAnyWidget("dropdown_selector_button");
30 m_ImageExpand = ImageWidget.Cast(m_Root.FindAnyWidget("expand_image"));
31 m_ImageCollapse = ImageWidget.Cast(m_Root.FindAnyWidget("collapse_image"));
32
33 m_Root.SetHandler(this);
34
36 }
37
39 {
40 Widget child = m_ContentContainer.GetChildren();
41 while (child)
42 {
43 if (m_Content.Find(child) > -1)
44 m_Content.Insert(child);
45 }
46
47 m_ContentContainer.Update();
48 m_Root.Update();
49
50 float x, y;
51 m_ContentContainer.GetScreenSize(x, y);
52 if (y > m_Scroller.GetContentHeight())
53 m_Scroller.SetAlpha(1);
54 else
55 m_Scroller.SetAlpha(0);
56 }
57
59 {
60 ButtonWidget element = ButtonWidget.Cast(GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/dropdown_prefab/dropdown_element.layout", m_ContentContainer));
61 RichTextWidget textWidget = RichTextWidget.Cast(element.FindAnyWidget("dropdown_element_text"));
62 textWidget.SetText(text);
63
64 if (content)
65 element.AddChild(content, false);
66 m_ContentContainer.Update();
67 textWidget.Update();
68 m_Root.Update();
69 element.Update();
70
71 m_Content.Insert(element);
72 return m_Content.Count() - 1;
73 }
74
76 {
77 if (0 < index && index < m_Content.Count())
78 {
79 delete m_Content.Get(index);
80 m_ContentContainer.Update();
81 m_Root.Update();
82 m_Parent.Update();
83 }
84 }
85
86 void Close()
87 {
88 if (m_IsExpanded)
89 {
91 m_Scroller.Show(m_IsExpanded);
92 m_ImageExpand.Show(!m_IsExpanded);
93 m_ImageCollapse.Show(m_IsExpanded);
94
95 m_Root.Update();
96 m_Parent.Update();
97 }
98 }
99
100 void SetText(string text)
101 {
102 m_Text.SetText(text);
103 }
104
105 override bool OnClick(Widget w, int x, int y, int button)
106 {
107 int index = m_Content.Find(w);
108 if (index > -1)
109 {
110 m_OnSelectItem.Invoke(index);
111 m_IsExpanded = false;
112 m_Scroller.Show(m_IsExpanded);
113 m_ImageExpand.Show(!m_IsExpanded);
114 m_ImageCollapse.Show(m_IsExpanded);
115 return true;
116 }
117 return false;
118 }
119
120 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
121 {
122 if ((w == m_Button || w == m_Text || w == m_Holder) && button == MouseState.LEFT)
123 {
125 m_Scroller.Show(m_IsExpanded);
126 m_ImageExpand.Show(!m_IsExpanded);
127 m_ImageCollapse.Show(m_IsExpanded);
128
129 m_Root.Update();
130 m_Parent.Update();
131 m_ContentContainer.Update();
132
133 return true;
134 }
135 return false;
136 }
137}
string m_Text
Definition ActionBase.c:49
bool m_IsExpanded
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
Widget m_Parent
Definition SizeToChild.c:86
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void DropdownPrefab(Widget root, string text="")
int AddElement(string text, Widget content=null)
override bool OnClick(Widget w, int x, int y, int button)
void RemoveElement(int index)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
proto native CGame GetGame()
MouseState
Definition EnSystem.c:311