DayZ 1.24
Loading...
Searching...
No Matches
OptionSelector.c
Go to the documentation of this file.
2{
6 protected int m_SelectedOptionIndex;
8
10 {
11 m_Options = { "#server_browser_disabled", "#server_browser_show", "#server_browser_hide" };
12 m_ParentClass = parent_c;
13 m_SelectorType = 2;
14 if (current_index < 0 || current_index >= m_Options.Count())
15 m_SelectedOptionIndex = 0;
16 else
17 m_SelectedOptionIndex = current_index;
18
19 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/option_selector.layout", parent);
20#ifdef PLATFORM_CONSOLE
21 m_Parent = parent.GetParent().GetParent();
22#else
23#ifdef PLATFORM_WINDOWS
24 m_Parent = parent.GetParent();
25#endif
26#endif
27
28 m_SelectedOption = TextWidget.Cast(m_Root.FindAnyWidget("option_label"));
29 m_PreviousOption = m_Root.FindAnyWidget("prev_option");
30 m_NextOption = m_Root.FindAnyWidget("next_option");
31
32#ifdef PLATFORM_CONSOLE
33 m_NextOption.Show(false);
34 m_PreviousOption.Show(false);
35#endif
36
37 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
38
40 if (m_Enabled)
41 Enable();
42 else
43 Disable();
44
45 m_Parent.SetHandler(this);
46 }
47
49 {
50 delete m_Root;
51 }
52
53 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
54 {
55 if (button == MouseState.LEFT)
56 {
57 if (w == m_NextOption)
58 {
60 return true;
61 }
62 else if (w == m_PreviousOption)
63 {
65 return true;
66 }
67 }
68 return false;
69 }
70
71 override bool OnClick(Widget w, int x, int y, int button)
72 {
73 if (button == MouseState.LEFT)
74 {
75 if (w == m_Parent)
77 }
78 return true;
79 }
80
81
82 override bool OnMouseEnter(Widget w, int x, int y)
83 {
84 return super.OnMouseEnter(w, x, y);
85 }
86
87 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
88 {
89 return super.OnMouseLeave(w, enterW, x, y);
90 }
91
92 void Reset()
93 {
94 m_SelectedOptionIndex = 0;
95
96 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
97
98 m_OptionChanged.Invoke(m_SelectedOptionIndex);
99 }
100
102 {
103 m_SelectedOptionIndex++;
104 if (m_SelectedOptionIndex >= m_Options.Count())
105 m_SelectedOptionIndex = 0;
106
107 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
108
109 m_OptionChanged.Invoke(m_SelectedOptionIndex);
110 }
111
113 {
114 m_SelectedOptionIndex--;
115 if (m_SelectedOptionIndex < 0)
116 m_SelectedOptionIndex = m_Options.Count() - 1;
117
118 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
119
120 m_OptionChanged.Invoke(m_SelectedOptionIndex);
121 }
122
124 {
125 return m_Options;
126 }
127
128
129 bool IsSet()
130 {
131 return m_SelectedOptionIndex != 0;
132 }
133
136 {
137 return m_SelectedOptionIndex == 1;
138 }
139
142 {
143 return m_Enabled;
144 }
145
147 {
148 return m_Options.Get(m_SelectedOptionIndex);
149 }
150
151 void SetStringOption(string option, bool fire_event = true)
152 {
153 int index = m_Options.Find(option);
154 if (index > -1)
155 {
156 m_SelectedOptionIndex = index;
157 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
158
159 if (fire_event)
160 m_OptionChanged.Invoke(m_SelectedOptionIndex);
161 }
162 }
163
165 {
166 switch (m_SelectedOptionIndex)
167 {
168 case 0:
169 {
170 m_SelectedOption.SetColor(ARGB(255, 255, 255, 255));
171 break;
172 }
173 case 1:
174 {
175 m_SelectedOption.SetColor(ARGB(255, 0, 255, 0));
176 break;
177 }
178 case 2:
179 {
180 m_SelectedOption.SetColor(ARGB(255, 255, 0, 0));
181 break;
182 }
183 }
184 }
185
186 override bool IsFocusable(Widget w)
187 {
188 if (w)
189 return (w == m_Parent || w == m_NextOption || w == m_PreviousOption);
190 return false;
191 }
192
193 override void Enable()
194 {
195 super.Enable();
196#ifndef PLATFORM_CONSOLE
197 m_NextOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
198 m_NextOption.Show(true);
199 m_PreviousOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
200 m_PreviousOption.Show(true);
201#else
202 m_Parent.ClearFlags(WidgetFlags.NOFOCUS);
203 m_Parent.ClearFlags(WidgetFlags.IGNOREPOINTER);
204#endif
205 }
206
207 override void Disable()
208 {
209 super.Disable();
210#ifndef PLATFORM_CONSOLE
211 m_NextOption.SetFlags(WidgetFlags.IGNOREPOINTER);
212 m_NextOption.Show(false);
213 m_PreviousOption.SetFlags(WidgetFlags.IGNOREPOINTER);
214 m_PreviousOption.Show(false);
215#else
216 m_Parent.SetFlags(WidgetFlags.NOFOCUS);
217 m_Parent.SetFlags(WidgetFlags.IGNOREPOINTER);
218#endif
219 }
220
222 {
223 super.ColorNormalConsole(w);
224
225 if (!w)
226 return;
227
228 if (m_SelectedOption)
229 m_SelectedOption.SetColor(ARGB(255, 255, 255, 255));
230 }
231
233 {
234 super.ColorDisabledConsole(w);
235
236 if (!w)
237 return;
238
239 if (m_SelectedOption)
240 m_SelectedOption.SetColor(ARGB(120, 255, 255, 255));
241 }
242}
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
Widget m_Parent
Definition SizeToChild.c:86
bool m_Enabled
Definition TrapTrigger.c:65
void SetStringOption(string option, bool fire_event=true)
TextWidget m_SelectedOption
override bool IsFocusable(Widget w)
bool IsEnabled()
Returns 'true' if current index == 1 (default 'enabled' value). Take care, as different selectors may...
override void ColorNormalConsole(Widget w)
bool IsSelectorEnabled()
Returns false for the selector in 'disabled' states.
ref array< string > m_Options
override void ColorDisabledConsole(Widget w)
override bool OnMouseEnter(Widget w, int x, int y)
void OptionSelector(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled)
override void Enable()
override bool OnClick(Widget w, int x, int y, int button)
override void Disable()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
array< string > GetOptions()
override void SetNextOption()
override void SetPrevOption()
map: item x vector(index, width, height)
Definition EnWidgets.c:651
proto native CGame GetGame()
MouseState
Definition EnSystem.c:311
WidgetFlags
Definition EnWidgets.c:58
proto native void Enable(bool enable)
int ARGB(int a, int r, int g, int b)
Definition proto.c:322