Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ParamEnumArray.c
Go to the documentation of this file.
1
class
SCR_ParamEnumArray
: ParamEnumArray
2
{
3
protected
static
const
int
CORE_MODULE_COUNT
= 2;
4
5
protected
static
const
string
ENTRY_SEPARATOR
=
SCR_StringHelper
.SEMICOLON;
6
protected
static
const
string
VALUE_SEPARATOR
=
SCR_StringHelper
.COMMA;
7
protected
static
const
string
ESCAPE_CHARACTER
=
SCR_StringHelper
.SINGLE_QUOTE;
8
9
//------------------------------------------------------------------------------------------------
19
static
ParamEnumArray
FromAddons
(
int
titleFormat = 2,
int
hideCoreModules = 0)
20
{
21
ParamEnumArray
params
=
new
ParamEnumArray();
22
array<string> addonGUIDs = {};
23
GameProject
.GetLoadedAddons(addonGUIDs);
24
25
int
count = addonGUIDs.Count();
26
foreach
(
int
i,
string
addonGUID : addonGUIDs)
27
{
28
if
(hideCoreModules == 1 &&
GameProject
.IsVanillaAddon(addonGUID))
29
continue
;
30
31
if
(hideCoreModules == 2 && count >
CORE_MODULE_COUNT
&&
GameProject
.IsVanillaAddon(addonGUID))
32
continue
;
33
34
string
title;
35
switch
(titleFormat)
36
{
37
case
0: title =
GameProject
.GetAddonID(addonGUID);
break
;
38
case
1: title =
GameProject
.GetAddonTitle(addonGUID);
break
;
39
default
:
40
case
2: title =
string
.Format(
"%1 (%2)"
,
GameProject
.GetAddonTitle(addonGUID),
GameProject
.GetAddonID(addonGUID));
break
;
41
}
42
43
params
.Insert(
new
ParamEnum
(title, i.ToString(), addonGUID));
44
}
45
46
return
params
;
47
}
48
49
//------------------------------------------------------------------------------------------------
54
static
ParamEnumArray
FromEnumArray
(
typename
enumTypeName, notnull array<int> enumValues)
55
{
56
if
(!enumTypeName)
57
return
null;
58
59
if
(enumValues.IsEmpty())
60
return
FromEnum
(enumTypeName);
61
62
ParamEnumArray result =
new
ParamEnumArray();
63
int
val;
64
65
map<int, string>
possibleValues =
new
map<int, string>
();
66
for
(
int
i, count = enumTypeName.GetVariableCount(); i < count; ++i)
67
{
68
if
(enumTypeName.GetVariableType(i) ==
int
&& enumTypeName.GetVariableValue(null, i, val))
69
possibleValues.Insert(val, enumTypeName.GetVariableName(i));
70
}
71
72
foreach
(
int
enumValue : enumValues)
73
{
74
if
(possibleValues.Contains(enumValue))
75
result.Insert(
new
ParamEnum
(possibleValues.Get(enumValue), enumValue.ToString()));
76
}
77
78
return
result;
79
}
80
81
// //------------------------------------------------------------------------------------------------
82
// //! Get a ParamEnumArray of mask-provided enum values
83
// //! \param[in] enumTypeName
84
// //! \param[in] mask
85
// //! \return ParamEnumArray or null if enumTypeName is null
86
// static ParamEnumArray FromEnumMask(typename enumTypeName, int mask, bool avoidZero = false)
87
// {
88
// if (!enumTypeName)
89
// return null;
90
//
91
// ParamEnumArray result = new ParamEnumArray();
92
// int val;
93
//
94
// for (int i, count = enumTypeName.GetVariableCount(); i < count; ++i)
95
// {
96
// if (enumTypeName.GetVariableType(i) == int && enumTypeName.GetVariableValue(null, i, val))
97
// {
98
// if ((val == 0 && !avoidZero) || (val & mask) == val)
99
// result.Insert(new ParamEnum(enumTypeName.GetVariableName(i), val.ToString()));
100
// }
101
// }
102
//
103
// return result;
104
// }
105
106
//------------------------------------------------------------------------------------------------
112
static
ParamEnumArray
FromEnumSkip
(
typename
enumTypeName,
int
skipFirst,
int
skipLast = 0)
113
{
114
if
(!enumTypeName)
115
return
null;
116
117
ParamEnumArray result = ParamEnumArray.FromEnum(enumTypeName);
118
int
count = result.Count();
119
if
(count < 2)
120
return
result;
121
122
if
(skipFirst < 0)
123
skipFirst = 0;
124
125
if
(skipLast < 0)
126
skipLast = 0;
127
128
if
(skipFirst + skipLast >= count)
129
return
result;
130
131
if
(skipFirst > count)
132
skipFirst = 0;
133
134
if
(skipLast > count)
135
skipLast = 0;
136
137
for
(
int
i; i < skipFirst; ++i)
138
{
139
result.RemoveOrdered(0);
140
}
141
142
count -= skipFirst;
143
144
for
(
int
i; i < skipLast; ++i)
145
{
146
result.Remove(--count);
147
}
148
149
return
result;
150
}
151
152
//------------------------------------------------------------------------------------------------
164
static
ParamEnumArray
FromString
(
string
input)
165
{
166
if
(
SCR_StringHelper
.
IsEmptyOrWhiteSpace
(input))
167
return
{
new
ParamEnum
(
"No options set"
,
"0"
,
"No options set - please edit the Attribute's SCR_ParamEnumArray.FromString string value"
) };
168
169
array<string> entries =
SplitString
(input,
ENTRY_SEPARATOR
);
170
171
ParamEnumArray result = {};
172
array<string> values;
173
174
foreach
(
int
i,
string
entry : entries)
175
{
176
entry.TrimInPlace();
177
values =
SplitString
(entry,
VALUE_SEPARATOR
, 3);
178
179
int
valuesCount = values.Count();
180
if
(valuesCount < 1)
// cannot happen
181
continue
;
182
183
foreach
(
int
j,
string
value2 : values)
184
{
185
value2.TrimInPlace();
186
values[j] = value2;
187
}
188
189
string
value = i.ToString();
190
string
text;
191
string
description;
192
193
if
(valuesCount == 1)
// 1 - text only
194
{
195
text = values[0];
196
text.TrimInPlace();
197
}
198
else
if
(valuesCount == 2)
// 2 - text and description
199
{
200
text = values[0];
201
description = values[1];
202
203
text.TrimInPlace();
204
description.TrimInPlace();
205
}
206
else
// 3 - VALUE, text and description - other splits are joined into description
207
{
208
value = values[0];
209
text = values[1];
210
description = values[2];
211
212
// value.TrimInPlace(); // we keep spaces, they may eventually be useful
213
text.TrimInPlace();
214
description.TrimInPlace();
215
}
216
217
if
(description)
218
description +=
"\nValue: "
+ value;
219
else
220
description =
"Value: "
+ value;
221
222
result.Insert(
new
ParamEnum
(text, value, description));
223
}
224
225
return
result;
226
}
227
228
//------------------------------------------------------------------------------------------------
234
protected
static
array<string>
SplitString
(
string
input,
string
separator,
int
maxCount = 0)
235
{
236
if
(!separator)
// .IsEmpty()
237
return
{ input };
238
239
array<string> result = {};
240
input.Split(separator, result,
false
);
241
242
for
(
int
i = result.Count() - 1; i >= 1; --i)
243
{
244
if
(result[i - 1].EndsWith(
ESCAPE_CHARACTER
))
245
{
246
result[i - 1] = result[i - 1].Substring(0, result[i - 1].Length() - 1) + separator + result[i];
247
result.RemoveOrdered(i);
248
}
249
}
250
251
if
(maxCount > 0)
252
{
253
int
count = result.Count();
254
if
(count > maxCount)
255
{
256
for
(
int
i = count - 1; i > maxCount - 1; --i)
257
{
258
result[2] = result[2] + separator + result[i];
259
result.Remove(i);
260
}
261
}
262
}
263
264
return
result;
265
}
266
}
ParamEnum
void ParamEnum(string key, string value, string desc="")
Definition
attributes.c:25
FromEnum
ParamEnum Managed FromEnum(typename e)
Definition
attributes.c:20
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
GameProject
Definition
GameProject.c:13
SCR_ParamEnumArray
Definition
SCR_ParamEnumArray.c:2
SCR_ParamEnumArray::SplitString
static array< string > SplitString(string input, string separator, int maxCount=0)
Definition
SCR_ParamEnumArray.c:234
SCR_ParamEnumArray::VALUE_SEPARATOR
static const string VALUE_SEPARATOR
Definition
SCR_ParamEnumArray.c:6
SCR_ParamEnumArray::FromAddons
static ParamEnumArray FromAddons(int titleFormat=2, int hideCoreModules=0)
Definition
SCR_ParamEnumArray.c:19
SCR_ParamEnumArray::CORE_MODULE_COUNT
static const int CORE_MODULE_COUNT
Definition
SCR_ParamEnumArray.c:3
SCR_ParamEnumArray::FromEnumArray
static ParamEnumArray FromEnumArray(typename enumTypeName, notnull array< int > enumValues)
Definition
SCR_ParamEnumArray.c:54
SCR_ParamEnumArray::FromString
static ParamEnumArray FromString(string input)
Definition
SCR_ParamEnumArray.c:164
SCR_ParamEnumArray::ENTRY_SEPARATOR
static const string ENTRY_SEPARATOR
Definition
SCR_ParamEnumArray.c:5
SCR_ParamEnumArray::ESCAPE_CHARACTER
static const string ESCAPE_CHARACTER
Definition
SCR_ParamEnumArray.c:7
SCR_ParamEnumArray::FromEnumSkip
static ParamEnumArray FromEnumSkip(typename enumTypeName, int skipFirst, int skipLast=0)
Definition
SCR_ParamEnumArray.c:112
SCR_StringHelper
Definition
SCR_StringHelper.c:2
SCR_StringHelper::IsEmptyOrWhiteSpace
static bool IsEmptyOrWhiteSpace(string input)
Definition
SCR_StringHelper.c:594
map
Definition
Types.c:486
scripts
Game
Global
SCR_ParamEnumArray.c
Generated by
1.17.0