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

class OptionSelectorMultistateCharacterMenu extends OptionSelectorMultistate
{
	string class_name;
	string path = "cfgVehicles " + class_name + " displayName";
	string displayname;
	
	void OptionSelectorMultistateCharacterMenu(Widget parent, int current_index, ScriptedWidgetEventHandler parent_c, bool disabled, notnull array<string> options)
	{
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	void SetDisplayNameText(string value, string appendix)
	{
		path = "cfgVehicles " + class_name + " displayName";
		GetGame().ConfigGetText(path, displayname);
		if (value == "Male")
		{
			m_SelectedOption.SetText("#str_cfgvehicles_survivorM0");
		}
		else if (value == "Female")
		{
			m_SelectedOption.SetText("#str_cfgvehicles_survivorF0");
		}
		else if (appendix != "")
		{
			if (value == "")
				m_SelectedOption.SetText("NO ITEM - localization needed!");
			else
				m_SelectedOption.SetText("" + displayname + " " + appendix); //characters
		}
		else
		{
			m_SelectedOption.SetText(displayname);
		}
	}
	
	void SetTextSmart(string value)
	{
		if (value == "Male" || value == "Female")
		{
			SetDisplayNameText(value,"");
			return;
		}
		
		class_name = value;
		int index = m_Options.Find(value);
		if (InheritsFrom(class_name, "Clothing_Base"))
		{
			SetDisplayNameText(class_name,index.ToString());
		}
		else if (InheritsFrom(class_name,"SurvivorBase"))
		{
			if (InheritsFrom(class_name,"SurvivorMale_Base"))
			{
				SetDisplayNameText("#str_cfgvehicles_survivorM0",(m_SelectedOptionIndex + 1).ToString());
			}
			else if (InheritsFrom(class_name,"SurvivorFemale_Base"))
			{
				SetDisplayNameText("#str_cfgvehicles_survivorF0",(m_SelectedOptionIndex + 1).ToString());
			}
		}
		else
		{
			SetDisplayNameText(class_name,index.ToString());
		}
	}
	
	bool InheritsFrom(string value, string baseclass)
	{
		string child = value;
		string parent;
		while (GetGame().ConfigGetBaseName("cfgVehicles " + child, parent))
		{
			if (parent == baseclass)
			{
				return true;
			}
			child = parent;
		}
		return false;
	}
	
	override void SetNextOption()
	{
		super.SetNextOption();
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	override void SetPrevOption()
	{
		super.SetPrevOption();
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	override void SetValue(int value, bool fire_event = true)
	{
		super.SetValue(value,fire_event);
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	override void SetValue(string value, bool fire_event = true)
	{
		super.SetValue(value,fire_event);
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	override void SetRandomValue()
	{
		super.SetRandomValue();
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
	
	override void SetStringOption(string option, bool fire_event = true)
	{
		super.SetStringOption(option, fire_event);
		SetTextSmart(m_Options.Get(m_SelectedOptionIndex));
	}
}