Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
optionselectormultistate.c
Go to the documentation of this file.
1 class OptionSelectorMultistate extends OptionSelector
2 {
3  protected bool m_CanSwitch;
4 
5  void OptionSelectorMultistate(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array<string> options)
6  {
7  m_CanSwitch = true;
8 
9  m_SelectorType = 2;
10  m_Options = options;
11  if (options.Count() == 0)
12  {
13  Error("Invalid OptionSelectorMultistate options");
14  }
15 
16  if (current_index < 0 || current_index >= m_Options.Count())
17  {
18  m_SelectedOptionIndex = 0;
19  }
20  else
21  {
22  m_SelectedOptionIndex = current_index;
23  }
24 
25  m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
26  }
27 
28  void LoadNewValues(notnull array<string> options, int current_index)
29  {
30  m_Options = options;
31  SetValue(current_index);
32  }
33 
34  override void SetNextOption()
35  {
36  int idx = m_SelectedOptionIndex;
37  idx++;
38  if (idx >= m_Options.Count())
39  {
40  idx = 0;
41  }
42 
43  m_AttemptOptionChange.Invoke(idx);
44  if (m_CanSwitch)
45  {
46  PerformSetOption(idx);
47  }
48  }
49 
50  override void SetPrevOption()
51  {
52  int idx = m_SelectedOptionIndex;
53  idx--;
54  if (idx < 0)
55  {
56  idx = m_Options.Count() - 1;
57  }
58 
59  m_AttemptOptionChange.Invoke(idx);
60  if (m_CanSwitch)
61  {
62  PerformSetOption(idx);
63  }
64  }
65 
66  void PerformSetOption(int index)
67  {
68  m_SelectedOptionIndex = index;
69  m_SelectedOption.SetText(m_Options.Get(index));
70  m_OptionChanged.Invoke(index);
71  }
72 
73  void SetCanSwitch(bool value)
74  {
75  m_CanSwitch = value;
76  }
77 
78  bool CanSwitch()
79  {
80  return m_CanSwitch;
81  }
82 
83  void SetValue(int value, bool fire_event = true)
84  {
85  if (value < m_Options.Count() && value >= 0)
86  {
87  m_SelectedOptionIndex = value;
88  m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
89  if (fire_event)
90  m_OptionChanged.Invoke(m_SelectedOptionIndex);
91  }
92  }
93 
94  void SetValue(string value, bool fire_event = true)
95  {
96  int index = m_Options.Find(value);
97  if (index >= 0)
98  {
99  m_SelectedOptionIndex = index;
100  m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
101  if (fire_event)
102  m_OptionChanged.Invoke(m_SelectedOptionIndex);
103  }
104  }
105 
106  void SetRandomValue()
107  {
108  m_SelectedOptionIndex = Math.RandomInt(0, m_Options.Count());
109  m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
110  m_OptionChanged.Invoke(m_SelectedOptionIndex);
111  }
112 
113  int GetValue()
114  {
115  return m_SelectedOptionIndex;
116  }
117 
118  override void SetStringOption(string option, bool fire_event = true)
119  {
120  int index = m_Options.Find(option);
121  if (index > -1)
122  {
123  m_SelectedOptionIndex = index;
124  m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
125 
126  if (fire_event)
127  m_OptionChanged.Invoke(m_SelectedOptionIndex);
128  }
129  }
130 }
131 
132 class OptionSelectorMultistateCharacterMenu extends OptionSelectorMultistate
133 {
134  string class_name;
135  string path = "cfgVehicles " + class_name + " displayName";
136  string displayname;
137 
138  void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array<string> options)
139  {
140  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
141  }
142 
143  void SetDisplayNameText(string value, string appendix)
144  {
145  path = "cfgVehicles " + class_name + " displayName";
146  GetGame().ConfigGetText(path, displayname);
147  if (value == "Male")
148  {
149  m_SelectedOption.SetText("#str_cfgvehicles_survivorM0");
150  }
151  else if (value == "Female")
152  {
153  m_SelectedOption.SetText("#str_cfgvehicles_survivorF0");
154  }
155  else if (appendix != "")
156  {
157  if (value == "")
158  m_SelectedOption.SetText("NO ITEM - localization needed!");
159  else
160  m_SelectedOption.SetText("" + displayname + " " + appendix); //characters
161  }
162  else
163  {
164  m_SelectedOption.SetText(displayname);
165  }
166  }
167 
168  void SetTextSmart(string value)
169  {
170  if (value == "Male" || value == "Female")
171  {
172  SetDisplayNameText(value,"");
173  return;
174  }
175 
176  class_name = value;
177  int index = m_Options.Find(value);
178  if (InheritsFrom(class_name, "Clothing_Base"))
179  {
180  SetDisplayNameText(class_name,index.ToString());
181  }
182  else if (InheritsFrom(class_name,"SurvivorBase"))
183  {
184  if (InheritsFrom(class_name,"SurvivorMale_Base"))
185  {
186  SetDisplayNameText("#str_cfgvehicles_survivorM0",(m_SelectedOptionIndex + 1).ToString());
187  }
188  else if (InheritsFrom(class_name,"SurvivorFemale_Base"))
189  {
190  SetDisplayNameText("#str_cfgvehicles_survivorF0",(m_SelectedOptionIndex + 1).ToString());
191  }
192  }
193  else
194  {
195  SetDisplayNameText(class_name,index.ToString());
196  }
197  }
198 
199  bool InheritsFrom(string value, string baseclass)
200  {
201  string child = value;
202  string parent;
203  while (GetGame().ConfigGetBaseName("cfgVehicles " + child, parent))
204  {
205  if (parent == baseclass)
206  {
207  return true;
208  }
209  child = parent;
210  }
211  return false;
212  }
213 
214  override void SetNextOption()
215  {
216  super.SetNextOption();
217  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
218  }
219 
220  override void SetPrevOption()
221  {
222  super.SetPrevOption();
223  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
224  }
225 
226  override void SetValue(int value, bool fire_event = true)
227  {
228  super.SetValue(value,fire_event);
229  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
230  }
231 
232  override void SetValue(string value, bool fire_event = true)
233  {
234  super.SetValue(value,fire_event);
235  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
236  }
237 
238  override void SetRandomValue()
239  {
240  super.SetRandomValue();
241  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
242  }
243 
244  override void SetStringOption(string option, bool fire_event = true)
245  {
246  super.SetStringOption(option, fire_event);
247  SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
248  }
249 }
GetGame
proto native CGame GetGame()
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
OptionSelectorMultistateCharacterMenu
void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array< string > options)
Definition: optionselectormultistate.c:138
OptionSelector
Definition: optionselectormultistate.c:1
SetRandomValue
override void SetRandomValue()
Definition: optionselectormultistate.c:238
displayname
string displayname
Definition: optionselectormultistate.c:136
InheritsFrom
bool InheritsFrom(string value, string baseclass)
Definition: optionselectormultistate.c:199
ToString
proto string ToString()
class_name
class OptionSelectorMultistate extends OptionSelector class_name
SetStringOption
override void SetStringOption(string option, bool fire_event=true)
Definition: optionselectormultistate.c:244
SetPrevOption
override void SetPrevOption()
Definition: optionselectormultistate.c:220
SetDisplayNameText
void SetDisplayNameText(string value, string appendix)
Definition: optionselectormultistate.c:143
array< string >
GetValue
string GetValue(int pIndex)
Definition: universaltemperaturesource.c:256
SetTextSmart
void SetTextSmart(string value)
Definition: optionselectormultistate.c:168
SetNextOption
override void SetNextOption()
Definition: optionselectormultistate.c:214
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
SetValue
override void SetValue(int value, bool fire_event=true)
Definition: optionselectormultistate.c:226
path
string path
Definition: optionselectormultistate.c:135