Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
56  void ~OptionSelector()
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  {
67  SetNextOption();
68  return true;
69  }
70  else if (w == m_PreviousOption)
71  {
72  SetPrevOption();
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)
84  SetNextOption();
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 
109  void SetNextOption()
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 
122  void SetPrevOption()
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 
135  array<string> GetOptions()
136  {
137  return m_Options;
138  }
139 
140 
141  bool IsSet()
142  {
143  return m_SelectedOptionIndex != 0;
144  }
145 
147  bool IsEnabled()
148  {
149  return m_SelectedOptionIndex == 1;
150  }
151 
153  bool IsSelectorEnabled()
154  {
155  return m_Enabled;
156  }
157 
158  string GetStringValue()
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 
176  void ColorOption()
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  override bool IsFocusable(Widget w)
199  {
200  if (w)
201  {
202  return (w == m_Parent || w == m_NextOption || w == m_PreviousOption);
203  }
204  return false;
205  }
206 
207  override void Enable()
208  {
209  super.Enable();
210  #ifndef PLATFORM_CONSOLE
211  m_NextOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
212  m_NextOption.Show(true);
213  m_PreviousOption.ClearFlags(WidgetFlags.IGNOREPOINTER);
214  m_PreviousOption.Show(true);
215  #else
216  m_Parent.ClearFlags(WidgetFlags.NOFOCUS);
217  m_Parent.ClearFlags(WidgetFlags.IGNOREPOINTER);
218  #endif
219  }
220 
221  override void Disable()
222  {
223  super.Disable();
224  #ifndef PLATFORM_CONSOLE
225  m_NextOption.SetFlags(WidgetFlags.IGNOREPOINTER);
226  m_NextOption.Show(false);
227  m_PreviousOption.SetFlags(WidgetFlags.IGNOREPOINTER);
228  m_PreviousOption.Show(false);
229  #else
230  m_Parent.SetFlags(WidgetFlags.NOFOCUS);
231  m_Parent.SetFlags(WidgetFlags.IGNOREPOINTER);
232  #endif
233  }
234 
235  override void ColorNormalConsole(Widget w)
236  {
237  super.ColorNormalConsole(w);
238 
239  if (!w)
240  return;
241 
242  if (m_SelectedOption)
243  {
244  m_SelectedOption.SetColor(ARGB(255,255,255,255));
245  }
246  }
247 
248  override void ColorDisabledConsole(Widget w)
249  {
250  super.ColorDisabledConsole(w);
251 
252  if (!w)
253  return;
254 
255  if (m_SelectedOption)
256  {
257  m_SelectedOption.SetColor(ARGB(120,255,255,255));
258  }
259  }
260 }
GetGame
proto native CGame GetGame()
OptionSelectorBase
Definition: optionselector.c:1
OptionSelector
Definition: optionselectormultistate.c:1
y
Icon y
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
m_Enabled
bool m_Enabled
Definition: traptrigger.c:2
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition: radialmenu.c:668
Enable
proto native void Enable(bool enable)
TextWidget
Definition: enwidgets.c:219
MouseState
MouseState
Definition: ensystem.c:310
array< string >
x
Icon x
Reset
void Reset()
Definition: inventory.c:1106
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
IsFocusable
bool IsFocusable(Widget w)
Definition: serverbrowsertab.c:284