DayZ 1.24
Loading...
Searching...
No Matches
OptionSelectorMultistate.c
Go to the documentation of this file.
1class OptionSelectorMultistate extends OptionSelector
2{
3 protected bool m_CanSwitch;
4
6 {
7 m_CanSwitch = true;
8
9 m_SelectorType = 2;
10 m_Options = options;
11 if (options.Count() == 0)
12 Error("Invalid OptionSelectorMultistate options");
13
14 if (current_index < 0 || current_index >= m_Options.Count())
15 m_SelectedOptionIndex = 0;
16 else
17 m_SelectedOptionIndex = current_index;
18
19 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
20 }
21
27
28 override void SetNextOption()
29 {
30 int idx = m_SelectedOptionIndex;
31 idx++;
32 if (idx >= m_Options.Count())
33 idx = 0;
34
35 m_AttemptOptionChange.Invoke(idx);
36 if (m_CanSwitch)
38 }
39
40 override void SetPrevOption()
41 {
42 int idx = m_SelectedOptionIndex;
43 idx--;
44 if (idx < 0)
45 idx = m_Options.Count() - 1;
46
47 m_AttemptOptionChange.Invoke(idx);
48 if (m_CanSwitch)
50 }
51
53 {
54 m_SelectedOptionIndex = index;
55 m_SelectedOption.SetText(m_Options.Get(index));
56 m_OptionChanged.Invoke(index);
57 }
58
60 {
61 m_CanSwitch = value;
62 }
63
64 bool CanSwitch()
65 {
66 return m_CanSwitch;
67 }
68
69 void SetValue(int value, bool fire_event = true)
70 {
71 if (value < m_Options.Count() && value >= 0)
72 {
73 m_SelectedOptionIndex = value;
74 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
75 if (fire_event)
76 m_OptionChanged.Invoke(m_SelectedOptionIndex);
77 }
78 }
79
80 void SetValue(string value, bool fire_event = true)
81 {
82 int index = m_Options.Find(value);
83 if (index >= 0)
84 {
85 m_SelectedOptionIndex = index;
86 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
87 if (fire_event)
88 m_OptionChanged.Invoke(m_SelectedOptionIndex);
89 }
90 }
91
93 {
94 m_SelectedOptionIndex = Math.RandomInt(0, m_Options.Count());
95 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
96 m_OptionChanged.Invoke(m_SelectedOptionIndex);
97 }
98
100 {
101 return m_SelectedOptionIndex;
102 }
103
104 override void SetStringOption(string option, bool fire_event = true)
105 {
106 int index = m_Options.Find(option);
107 if (index > -1)
108 {
109 m_SelectedOptionIndex = index;
110 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
111
112 if (fire_event)
113 m_OptionChanged.Invoke(m_SelectedOptionIndex);
114 }
115 }
116}
117
118class OptionSelectorMultistateCharacterMenu extends OptionSelectorMultistate
119{
121 string path = "cfgVehicles " + class_name + " displayName";
123
128
129 void SetDisplayNameText(string value, string appendix)
130 {
131 path = "cfgVehicles " + class_name + " displayName";
132 GetGame().ConfigGetText(path, displayname);
133 if (value == "Male")
134 m_SelectedOption.SetText("#str_cfgvehicles_survivorM0");
135 else if (value == "Female")
136 m_SelectedOption.SetText("#str_cfgvehicles_survivorF0");
137 else if (appendix != "")
138 {
139 if (value == "")
140 m_SelectedOption.SetText("NO ITEM - localization needed!");
141 else
142 m_SelectedOption.SetText("" + displayname + " " + appendix); //characters
143 }
144 else
145 m_SelectedOption.SetText(displayname);
146 }
147
148 void SetTextSmart(string value)
149 {
150 if (value == "Male" || value == "Female")
151 {
153 return;
154 }
155
157 int index = m_Options.Find(value);
158 if (InheritsFrom(class_name, "Clothing_Base"))
160 else if (InheritsFrom(class_name, "SurvivorBase"))
161 {
162 if (InheritsFrom(class_name, "SurvivorMale_Base"))
163 SetDisplayNameText("#str_cfgvehicles_survivorM0", (m_SelectedOptionIndex + 1).ToString());
164 else if (InheritsFrom(class_name, "SurvivorFemale_Base"))
165 SetDisplayNameText("#str_cfgvehicles_survivorF0", (m_SelectedOptionIndex + 1).ToString());
166 }
167 else
169 }
170
171 bool InheritsFrom(string value, string baseclass)
172 {
173 string child = value;
174 string parent;
175 while (GetGame().ConfigGetBaseName("cfgVehicles " + child, parent))
176 {
177 if (parent == baseclass)
178 return true;
179 child = parent;
180 }
181 return false;
182 }
183
184 override void SetNextOption()
185 {
186 super.SetNextOption();
187 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
188 }
189
190 override void SetPrevOption()
191 {
192 super.SetPrevOption();
193 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
194 }
195
196 override void SetValue(int value, bool fire_event = true)
197 {
198 super.SetValue(value, fire_event);
199 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
200 }
201
202 override void SetValue(string value, bool fire_event = true)
203 {
204 super.SetValue(value, fire_event);
205 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
206 }
207
208 override void SetRandomValue()
209 {
210 super.SetRandomValue();
211 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
212 }
213
214 override void SetStringOption(string option, bool fire_event = true)
215 {
216 super.SetStringOption(option, fire_event);
217 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
218 }
219}
proto string ToString()
void SetTextSmart(string value)
override void SetValue(int value, bool fire_event=true)
string displayname
bool InheritsFrom(string value, string baseclass)
void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array< string > options)
class OptionSelectorMultistate extends OptionSelector class_name
override void SetStringOption(string option, bool fire_event=true)
override void SetNextOption()
void SetDisplayNameText(string value, string appendix)
override void SetPrevOption()
override void SetRandomValue()
Definition EnMath.c:7
override void SetNextOption()
override void SetStringOption(string option, bool fire_event=true)
void SetCanSwitch(bool value)
void LoadNewValues(notnull array< string > options, int current_index)
void SetValue(int value, bool fire_event=true)
override void SetPrevOption()
void SetValue(string value, bool fire_event=true)
void PerformSetOption(int index)
void OptionSelectorMultistate(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array< string > options)
map: item x vector(index, width, height)
Definition EnWidgets.c:651
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].