Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
optionselector.c
Go to the documentation of this file.
2{
3 protected Widget m_PreviousOption;
4 protected Widget m_NextOption;
5 protected TextWidget m_SelectedOption;
6 protected int m_SelectedOptionIndex;
7 protected ref array<string> m_Options;
8
9 void OptionSelector(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled)
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 {
16 m_SelectedOptionIndex = 0;
17 }
18 else
19 {
20 m_SelectedOptionIndex = current_index;
21 }
22
23 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/option_selector.layout", parent);
24 #ifdef PLATFORM_CONSOLE
25 m_Parent = parent.GetParent().GetParent();
26 #else
27 #ifdef PLATFORM_WINDOWS
28 m_Parent = parent.GetParent();
29 #endif
30 #endif
31
32 m_SelectedOption = TextWidget.Cast(m_Root.FindAnyWidget("option_label"));
33 m_PreviousOption = m_Root.FindAnyWidget("prev_option");
34 m_NextOption = m_Root.FindAnyWidget("next_option");
35
36 #ifdef PLATFORM_CONSOLE
37 m_NextOption.Show(false);
38 m_PreviousOption.Show(false);
39 #endif
40
41 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
42
43 m_Enabled = !disabled;
44 if (m_Enabled)
45 {
46 Enable();
47 }
48 else
49 {
50 Disable();
51 }
52
53 m_Parent.SetHandler(this);
54 }
55
57 {
58 delete m_Root;
59 }
60
61 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
62 {
63 if (button == MouseState.LEFT)
64 {
65 if (w == m_NextOption)
66 {
68 return true;
69 }
70 else if (w == m_PreviousOption)
71 {
73 return true;
74 }
75 }
76 return false;
77 }
78
79 override bool OnClick(Widget w, int x, int y, int button)
80 {
81 if (button == MouseState.LEFT)
82 {
83 if (w == m_Parent)
85 }
86 return true;
87 }
88
89
90 override bool OnMouseEnter(Widget w, int x, int y)
91 {
92 return super.OnMouseEnter(w, x, y);
93 }
94
95 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
96 {
97 return super.OnMouseLeave(w, enterW, x, y);
98 }
99
100 void Reset()
101 {
102 m_SelectedOptionIndex = 0;
103
104 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
105
106 m_OptionChanged.Invoke(m_SelectedOptionIndex);
107 }
108
110 {
111 m_SelectedOptionIndex++;
112 if (m_SelectedOptionIndex >= m_Options.Count())
113 {
114 m_SelectedOptionIndex = 0;
115 }
116
117 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
118
119 m_OptionChanged.Invoke(m_SelectedOptionIndex);
120 }
121
123 {
124 m_SelectedOptionIndex--;
125 if (m_SelectedOptionIndex < 0)
126 {
127 m_SelectedOptionIndex = m_Options.Count() - 1;
128 }
129
130 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
131
132 m_OptionChanged.Invoke(m_SelectedOptionIndex);
133 }
134
136 {
137 return m_Options;
138 }
139
140
141 bool IsSet()
142 {
143 return m_SelectedOptionIndex != 0;
144 }
145
148 {
149 return m_SelectedOptionIndex == 1;
150 }
151
154 {
155 return m_Enabled;
156 }
157
159 {
160 return m_Options.Get(m_SelectedOptionIndex);
161 }
162
163 void SetStringOption(string option, bool fire_event = true)
164 {
165 int index = m_Options.Find(option);
166 if (index > -1)
167 {
168 m_SelectedOptionIndex = index;
169 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
170
171 if (fire_event)
172 m_OptionChanged.Invoke(m_SelectedOptionIndex);
173 }
174 }
175
177 {
178 switch (m_SelectedOptionIndex)
179 {
180 case 0:
181 {
182 m_SelectedOption.SetColor(ARGB(255, 255, 255, 255));
183 break;
184 }
185 case 1:
186 {
187 m_SelectedOption.SetColor(ARGB(255, 0, 255, 0));
188 break;
189 }
190 case 2:
191 {
192 m_SelectedOption.SetColor(ARGB(255, 255, 0, 0));
193 break;
194 }
195 }
196 }
197
198 void ShowNavigationButtons(bool show)
199 {
200 m_NextOption.Show(show);
201 m_PreviousOption.Show(show);
202 }
203
204 override bool IsFocusable(Widget w)
205 {
206 if (w)
207 {
208 return (w == m_Parent || w == m_NextOption || w == m_PreviousOption);
209 }
210 return false;
211 }
212
213 override void Enable()
214 {
215 super.Enable();
216 #ifndef PLATFORM_CONSOLE
217 m_NextOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
218 m_NextOption.Show(true);
219 m_PreviousOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
220 m_PreviousOption.Show(true);
221 #else
222 m_Parent.ClearFlags(WidgetFlags.NOFOCUS);
223 m_Parent.ClearFlags(WidgetFlags.IGNOREPOINTER);
224 #endif
225 }
226
227 override void Disable()
228 {
229 super.Disable();
230 #ifndef PLATFORM_CONSOLE
231 m_NextOption.SetFlags(WidgetFlags.IGNOREPOINTER);
232 m_NextOption.Show(false);
233 m_PreviousOption.SetFlags(WidgetFlags.IGNOREPOINTER);
234 m_PreviousOption.Show(false);
235 #else
236 m_Parent.SetFlags(WidgetFlags.NOFOCUS);
237 m_Parent.SetFlags(WidgetFlags.IGNOREPOINTER);
238 #endif
239 }
240
241 override void ColorNormalConsole(Widget w)
242 {
243 super.ColorNormalConsole(w);
244
245 if (!w)
246 return;
247
248 if (m_SelectedOption)
249 {
250 m_SelectedOption.SetColor(ARGB(255,255,255,255));
251 }
252 }
253
254 override void ColorDisabledConsole(Widget w)
255 {
256 super.ColorDisabledConsole(w);
257
258 if (!w)
259 return;
260
261 if (m_SelectedOption)
262 {
263 m_SelectedOption.SetColor(ARGB(120,255,255,255));
264 }
265 }
266}
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()
void ShowNavigationButtons(bool show)
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()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
bool m_Enabled
Definition traptrigger.c:71
proto native CGame GetGame()
MouseState
Definition ensystem.c:311
WidgetFlags
Definition enwidgets.c:58
Icon x
Icon y
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
Widget m_Root
Definition sizetochild.c:91
Widget m_Parent
Definition sizetochild.c:92