DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
OptionSelectorMultistate.c
См. документацию.
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 static OptionSelectorMultistate NewFromAccess(Widget parent, ListOptionsAccess optionAccess, ScriptedWidgetEventHandler parent_c, bool disabled)
29 {
30 array<string> items = {};
31 optionAccess.GetAllItemsText(items);
32 return new OptionSelectorMultistate(parent, optionAccess.GetIndex(), parent_c, disabled, items);
33 }
34
35 void LoadNewValues(notnull array<string> options, int current_index)
36 {
37 m_Options = options;
38 SetValue(current_index);
39 }
40
41 override void SetNextOption()
42 {
43 int idx = m_SelectedOptionIndex;
44 idx++;
45 if (idx >= m_Options.Count())
46 {
47 idx = 0;
48 }
49
50 m_AttemptOptionChange.Invoke(idx);
51 if (m_CanSwitch)
52 {
54 }
55 }
56
57 override void SetPrevOption()
58 {
59 int idx = m_SelectedOptionIndex;
60 idx--;
61 if (idx < 0)
62 {
63 idx = m_Options.Count() - 1;
64 }
65
66 m_AttemptOptionChange.Invoke(idx);
67 if (m_CanSwitch)
68 {
70 }
71 }
72
73 void PerformSetOption(int index)
74 {
75 m_SelectedOptionIndex = index;
76 m_SelectedOption.SetText(m_Options.Get(index));
77 m_OptionChanged.Invoke(index);
78 }
79
80 void SetCanSwitch(bool value)
81 {
82 m_CanSwitch = value;
83 }
84
85 bool CanSwitch()
86 {
87 return m_CanSwitch;
88 }
89
90 void SetValue(int value, bool fire_event = true)
91 {
92 if (value < m_Options.Count() && value >= 0)
93 {
94 m_SelectedOptionIndex = value;
95 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
96 if (fire_event)
97 m_OptionChanged.Invoke(m_SelectedOptionIndex);
98 }
99 }
100
101 void SetValue(string value, bool fire_event = true)
102 {
103 int index = m_Options.Find(value);
104 if (index >= 0)
105 {
106 m_SelectedOptionIndex = index;
107 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
108 if (fire_event)
109 m_OptionChanged.Invoke(m_SelectedOptionIndex);
110 }
111 }
112
114 {
115 m_SelectedOptionIndex = Math.RandomInt(0, m_Options.Count());
116 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
117 m_OptionChanged.Invoke(m_SelectedOptionIndex);
118 }
119
121 {
122 return m_SelectedOptionIndex;
123 }
124
125 override void SetStringOption(string option, bool fire_event = true)
126 {
127 int index = m_Options.Find(option);
128 if (index > -1)
129 {
130 m_SelectedOptionIndex = index;
131 m_SelectedOption.SetText(m_Options.Get(m_SelectedOptionIndex));
132
133 if (fire_event)
134 m_OptionChanged.Invoke(m_SelectedOptionIndex);
135 }
136 }
137}
138
139class OptionSelectorMultistateCharacterMenu extends OptionSelectorMultistate
140{
142 string path = "cfgVehicles " + class_name + " displayName";
144
145 void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array<string> options)
146 {
147 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
148 }
149
150 void SetDisplayNameText(string value, string appendix)
151 {
152 path = "cfgVehicles " + class_name + " displayName";
154 if (value == "Male")
155 {
156 m_SelectedOption.SetText("#str_cfgvehicles_survivorM0");
157 }
158 else if (value == "Female")
159 {
160 m_SelectedOption.SetText("#str_cfgvehicles_survivorF0");
161 }
162 else if (appendix != "")
163 {
164 if (value == "")
165 m_SelectedOption.SetText("NO ITEM - localization needed!");
166 else
167 m_SelectedOption.SetText("" + displayname + " " + appendix); //characters
168 }
169 else
170 {
171 m_SelectedOption.SetText(displayname);
172 }
173 }
174
175 void SetTextSmart(string value)
176 {
177 if (value == "Male" || value == "Female")
178 {
179 SetDisplayNameText(value,"");
180 return;
181 }
182
183 class_name = value;
184 int index = m_Options.Find(value);
185 if (InheritsFrom(class_name, "Clothing_Base"))
186 {
187 SetDisplayNameText(class_name,index.ToString());
188 }
189 else if (InheritsFrom(class_name,"SurvivorBase"))
190 {
191 if (InheritsFrom(class_name,"SurvivorMale_Base"))
192 {
193 SetDisplayNameText("#str_cfgvehicles_survivorM0",(m_SelectedOptionIndex + 1).ToString());
194 }
195 else if (InheritsFrom(class_name,"SurvivorFemale_Base"))
196 {
197 SetDisplayNameText("#str_cfgvehicles_survivorF0",(m_SelectedOptionIndex + 1).ToString());
198 }
199 }
200 else
201 {
202 SetDisplayNameText(class_name,index.ToString());
203 }
204 }
205
206 bool InheritsFrom(string value, string baseclass)
207 {
208 string child = value;
209 string parent;
210 while (GetGame().ConfigGetBaseName("cfgVehicles " + child, parent))
211 {
212 if (parent == baseclass)
213 {
214 return true;
215 }
216 child = parent;
217 }
218 return false;
219 }
220
221 override void SetNextOption()
222 {
223 super.SetNextOption();
224 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
225 }
226
227 override void SetPrevOption()
228 {
229 super.SetPrevOption();
230 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
231 }
232
233 override void SetValue(int value, bool fire_event = true)
234 {
235 super.SetValue(value,fire_event);
236 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
237 }
238
239 override void SetValue(string value, bool fire_event = true)
240 {
241 super.SetValue(value,fire_event);
242 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
243 }
244
245 override void SetRandomValue()
246 {
247 super.SetRandomValue();
248 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
249 }
250
251 override void SetStringOption(string option, bool fire_event = true)
252 {
253 super.SetStringOption(option, fire_event);
254 SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
255 }
256}
proto string ToString()
void SetTextSmart(string value)
Определения OptionSelectorMultistate.c:175
override void SetValue(int value, bool fire_event=true)
Определения OptionSelectorMultistate.c:233
string displayname
Определения OptionSelectorMultistate.c:143
string path
Определения OptionSelectorMultistate.c:142
bool InheritsFrom(string value, string baseclass)
Определения OptionSelectorMultistate.c:206
void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array< string > options)
Определения OptionSelectorMultistate.c:145
class OptionSelectorMultistate extends OptionSelector class_name
override void SetStringOption(string option, bool fire_event=true)
Определения OptionSelectorMultistate.c:251
override void SetNextOption()
Определения OptionSelectorMultistate.c:221
void SetDisplayNameText(string value, string appendix)
Определения OptionSelectorMultistate.c:150
override void SetPrevOption()
Определения OptionSelectorMultistate.c:227
override void SetRandomValue()
Определения OptionSelectorMultistate.c:245
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
Определения EnMath.c:7
bool m_CanSwitch
Определения OptionSelectorMultistate.c:3
override void SetNextOption()
Определения OptionSelectorMultistate.c:41
int GetValue()
Определения OptionSelectorMultistate.c:120
void SetRandomValue()
Определения OptionSelectorMultistate.c:113
override void SetStringOption(string option, bool fire_event=true)
Определения OptionSelectorMultistate.c:125
void SetCanSwitch(bool value)
Определения OptionSelectorMultistate.c:80
void LoadNewValues(notnull array< string > options, int current_index)
Определения OptionSelectorMultistate.c:35
void SetValue(int value, bool fire_event=true)
Определения OptionSelectorMultistate.c:90
override void SetPrevOption()
Определения OptionSelectorMultistate.c:57
bool CanSwitch()
Определения OptionSelectorMultistate.c:85
void SetValue(string value, bool fire_event=true)
Определения OptionSelectorMultistate.c:101
void PerformSetOption(int index)
Определения OptionSelectorMultistate.c:73
static OptionSelectorMultistate NewFromAccess(Widget parent, ListOptionsAccess optionAccess, ScriptedWidgetEventHandler parent_c, bool disabled)
Определения OptionSelectorMultistate.c:28
void OptionSelectorMultistate(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array< string > options)
Определения OptionSelectorMultistate.c:5
map: item x vector(index, width, height)
Определения EnWidgets.c:651
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].