Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FilterSet.c
Go to the documentation of this file.
1/*
2Base classes for filters used in server browser, workshop content browser, scenario browser, etc.
3*/
4
5//-----------------------------------------------------------------------------------------------------------
10{
11 [Attribute()]
12 string m_sDisplayName;
13
14 [Attribute()]
15 string m_sInternalName;
16
17 [Attribute("false", UIWidgets.CheckBox)]
18 bool m_bSelectedAtStart;
19
20 // Main image
21 [Attribute("", UIWidgets.ResourcePickerThumbnail, "Image - texture or imageset", "edds imageset")]
22 ResourceName m_sImageTexture;
23
24 [Attribute("{00FE3DBDFD15227B}UI/Textures/Icons/icons_wrapperUI-glow.imageset", UIWidgets.ResourcePickerThumbnail, "edds imageset")]
25 ResourceName m_sGlowTexture;
26
27 [Attribute("", UIWidgets.EditBox, "Image name if image set is used")]
28 string m_sImageName;
29
30 SCR_ListBoxElementComponent m_FilterComponent;
31
32 protected bool m_bSelected;
33
34 // Pointer back to category of this filter, initialized in constructor of Category class
36
37 //-----------------------------------------------------------------------------------------------------------
40
41 //-----------------------------------------------------------------------------------------------------------
43 void SetSelected(bool newValue) { m_bSelected = newValue; }
44
45 //-----------------------------------------------------------------------------------------------------------
47 bool GetSelected(bool defaultValue = false)
48 {
49 if (defaultValue)
50 return m_bSelectedAtStart;
51
52 return m_bSelected;
53 }
54
55 //-----------------------------------------------------------------------------------------------------------
60};
61
62
63//-----------------------------------------------------------------------------------------------------------
68{
69 [Attribute()]
70 string m_sDisplayName;
71
72 [Attribute()]
73 string m_sInternalName;
74
75 [Attribute("false", UIWidgets.Auto, "Only one filter can be enabled at a time.")]
76 bool m_bMutuallyExclusive;
77
78 [Attribute("true", UIWidgets.Auto, "When false, the filter panel will prohibit deselection of last selected entry.")];
79 bool m_bAllowNothingSelected;
80
81 [Attribute(uiwidget: UIWidgets.SearchComboBox, desc:"Category won't be created on selected platforms", enums: ParamEnumArray.FromEnum(EPlatform))]
82 protected ref array<EPlatform> m_aHideOnPlatforms;
83
84 //[Attribute("false", UIWidgets.Auto, "The category is hidden in release build.")]
85 //bool m_bHiddenInReleaseBuild;
86
87 //[Attribute("0", UIWidgets.ComboBox, "Type", "", ParamEnumArray.FromEnum(EContentBrowserFilterType) )]
88 //EContentBrowserFilterType m_eFilterType;
89
90 [Attribute("", UIWidgets.ResourcePickerThumbnail, "Common image set for individual filters. Each filter can override it though.", "imageset")]
92
93 [Attribute("{00FE3DBDFD15227B}UI/Textures/Icons/icons_wrapperUI-glow.imageset", UIWidgets.ResourcePickerThumbnail, "imageset")]
95
96 [Attribute("", UIWidgets.Object)]
97 protected ref array<ref SCR_FilterEntry> m_aFilters;
98
100
101
102 //-----------------------------------------------------------------------------------------------------------
103 protected void SCR_FilterCategory()
104 {
105 // Register the back-pointer of all child filters
106
107 // !! This object is instantiated as a property of another scripted object,
108 // So when constructor is called, all objects of m_aFilters are already created by the game
109
110 foreach (auto f : m_aFilters)
111 f.Init(this);
112 }
113
114 // ------------ Public API ----------------
115
116 //-----------------------------------------------------------------------------------------------------------
118 array<ref SCR_FilterEntry> GetFilters()
119 {
120 return m_aFilters;
121 }
122
123 //-----------------------------------------------------------------------------------------------------------
125 SCR_FilterEntry FindFilter(string internalName)
126 {
127 foreach (SCR_FilterEntry e : m_aFilters)
128 {
129 if (e.m_sInternalName == internalName)
130 return e;
131 }
132
133 return null;
134 }
135
136 //-----------------------------------------------------------------------------------------------------------
138 {
139 foreach (auto f : m_aFilters)
140 {
141 if (!f.GetSelected())
142 return false;
143 }
144 return true;
145 }
146
147 //-----------------------------------------------------------------------------------------------------------
149 {
150 foreach (auto f : m_aFilters)
151 {
152 if (f.GetSelected())
153 return true;
154 }
155 return false;
156 }
157
158 //-----------------------------------------------------------------------------------------------------------
160 {
161 foreach (auto f : m_aFilters)
162 {
163 if (f.GetSelected())
164 return false;
165 }
166 return true;
167 }
168
169 //-----------------------------------------------------------------------------------------------------------
172 {
173 int n = 0;
174 foreach (auto f : m_aFilters)
175 {
176 if (f.GetSelected())
177 n++;
178 }
179 return n;
180 }
181
182 //-----------------------------------------------------------------------------------------------------------
183 void GetHideOnPlaforms(out array<EPlatform> platforms)
184 {
185 platforms.Copy(m_aHideOnPlatforms);
186 }
187};
188
189
190
191//-----------------------------------------------------------------------------------------------------------
195[BaseContainerProps(configRoot : true)]
197{
198 [Attribute("", UIWidgets.Object)]
199 protected ref array<ref SCR_FilterCategory> m_aFilterCategories;
200
201 //-----------------------------------------------------------------------------------------------------------
202 array<ref SCR_FilterCategory> GetFilterCategories()
203 {
204 return m_aFilterCategories;
205 }
206
207 //-----------------------------------------------------------------------------------------------------------
210 {
212 {
213 if (cat.m_sInternalName == internalName)
214 return cat;
215 }
216 return null;
217 }
218
219 //-----------------------------------------------------------------------------------------------------------
221 ref SCR_FilterEntry FindFilter(string internalName)
222 {
224 {
225 SCR_FilterEntry filter = cat.FindFilter(internalName);
226 if (filter)
227 return filter;
228 }
229 return null;
230 }
231
232 //-----------------------------------------------------------------------------------------------------------
234 {
235 bool selected;
237 {
238 selected = category.GetAnySelected();
239 if (selected)
240 return true;
241 }
242
243 return false;
244 }
245
246 //-----------------------------------------------------------------------------------------------------------
249 {
250 // Select filters which must be selected at start according to SelectedAtStart flag
252 {
253 foreach (SCR_FilterEntry filter : category.GetFilters())
254 filter.SetSelected(filter.m_bSelectedAtStart);
255 }
256 }
257};
258
259//------------------------------------------------------------------------------------------------
262{
263 //------------------------------------------------------------------------------------------------
264 override bool _WB_GetCustomTitle(BaseContainer source, out string title)
265 {
266 source.Get("m_sInternalName", title);
267 return true;
268 }
269};
270
271
272// ----------------- Saving / Loading --------------------
273
274//------------------------------------------------------------------------------------------------
278{
279 const int CURRENT_VERSION = 1;
280
281 [Attribute()]
282 string m_sTag; // Filter sets are identified by this tag, tag should be unique
283
284 [Attribute()]
285 ref array<string> m_aSelectedFilters; // Array of selected filters
286
287 [Attribute()]
288 ref array<string> m_aSelectedCategories;// Categories of those selected filters
289
290 [Attribute()]
291 int m_iVersion; // Version. In the future filters will change, we will have to detect old filters.
292};
293
294//------------------------------------------------------------------------------------------------
296{
297 [Attribute()]
298 ref array<ref SCR_FilterSetStorage> m_aFilterSets;
299
300
301 //------------------------------------------------------------------------------------------------
302 static void SaveFilterSet(string tag, SCR_FilterSet filterSet)
303 {
305 BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
306 BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
307
308 // Delete the old data for this tag, if found
309 for (int i = allFilterSets.m_aFilterSets.Count()-1; i >= 0; i--)
310 {
311 SCR_FilterSetStorage storedFilterSet = allFilterSets.m_aFilterSets[i];
312 if (storedFilterSet.m_sTag == tag)
313 {
314 allFilterSets.m_aFilterSets.Remove(i);
315 }
316 }
317
318 // Create a new entry for this filter set
319 SCR_FilterSetStorage filterSetStorage = new SCR_FilterSetStorage;
320 filterSetStorage.m_iVersion = SCR_FilterSetStorage.CURRENT_VERSION;
321 filterSetStorage.m_sTag = tag;
322 if (!filterSetStorage.m_aSelectedFilters)
323 filterSetStorage.m_aSelectedFilters = new array<string>;
324 if (!filterSetStorage.m_aSelectedCategories)
325 filterSetStorage.m_aSelectedCategories = new array<string>;
326
327 foreach (SCR_FilterCategory category : filterSet.GetFilterCategories())
328 {
329 foreach (SCR_FilterEntry filter : category.GetFilters())
330 {
331 // Save filters
332 if (filter.GetSelected() && !filter.m_sInternalName.IsEmpty() && !category.m_sInternalName.IsEmpty() )
333 {
334 filterSetStorage.m_aSelectedCategories.Insert(category.m_sInternalName);
335 filterSetStorage.m_aSelectedFilters.Insert(filter.m_sInternalName);
336 }
337 }
338 }
339
340 allFilterSets.m_aFilterSets.Insert(filterSetStorage);
341
342 BaseContainerTools.ReadFromInstance(allFilterSets, allFilterSetsContainer);
343 GetGame().UserSettingsChanged();
344 GetGame().SaveUserSettings();
345 }
346
347
348
349 //------------------------------------------------------------------------------------------------
350 bool IsFilterSetSaved(string tag)
351 {
353 BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
354 BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
355
356 // Find the old data for this tag
357 SCR_FilterSetStorage storedFilterSet;
358 for (int i = 0; i < allFilterSets.m_aFilterSets.Count(); i++)
359 {
360 SCR_FilterSetStorage iFilterSet = allFilterSets.m_aFilterSets[i];
361 if (iFilterSet.m_sTag == tag)
362 return true;
363 }
364
365 return false;
366 }
367
368
369
370 //------------------------------------------------------------------------------------------------
371 static bool TryLoadFilterSet(string tag, SCR_FilterSet filterSet)
372 {
374 BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
375 BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
376
377 // Find the old data for this tag
378 SCR_FilterSetStorage storedFilterSet;
379 for (int i = 0; i < allFilterSets.m_aFilterSets.Count(); i++)
380 {
381 SCR_FilterSetStorage iFilterSet = allFilterSets.m_aFilterSets[i];
382 if (iFilterSet.m_sTag == tag)
383 {
384 storedFilterSet = iFilterSet;
385 break;
386 }
387 }
388
389 // Bail if not found
390 if (!storedFilterSet)
391 return false;
392
393 // Bail if version is invalid
394 if (storedFilterSet.m_iVersion > SCR_FilterSetStorage.CURRENT_VERSION)
395 {
396 return false;
397 }
398
399 // Restore selected filters
400
401 // Clear up first
402 foreach (SCR_FilterCategory category : filterSet.GetFilterCategories())
403 {
404 foreach (SCR_FilterEntry filter : category.GetFilters())
405 {
406 filter.SetSelected(false);
407 }
408 }
409
410 // Select filters which are selected in saved data
411 for (int i = 0; i < storedFilterSet.m_aSelectedFilters.Count(); i++)
412 {
413 string filterName = storedFilterSet.m_aSelectedFilters[i];
414 string categoryName = storedFilterSet.m_aSelectedCategories[i];
415
416 SCR_FilterCategory category = filterSet.FindFilterCategory(categoryName);
417
418 if (category)
419 {
420 SCR_FilterEntry filter = category.FindFilter(filterName);
421 if (filter)
422 filter.SetSelected(true);
423 }
424 }
425
426 return true;
427 }
428
429 //------------------------------------------------------------------------------------------------
431 static void ResetAllToDefault()
432 {
433 // Find storage
435 allFilterSets.m_aFilterSets = {};
436 BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
437
438 // Save settings
439 BaseContainerTools.ReadFromInstance(allFilterSets, allFilterSetsContainer);
440 GetGame().UserSettingsChanged();
441 GetGame().SaveUserSettings();
442 }
443};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
By inheriting of this class you define a settings module.
Widget m_wCategoryTitleWidget
ref array< EPlatform > m_aHideOnPlatforms
array< ref SCR_FilterEntry > GetFilters()
Returns array with filter entries.
ref array< ref SCR_FilterEntry > m_aFilters
void GetHideOnPlaforms(out array< EPlatform > platforms)
ResourceName m_sFilterGlowImageSet
SCR_FilterEntry FindFilter(string internalName)
Finds a filter by internal name.
int GetSelectedCount()
Returns count of selected entries.
ResourceName m_sFilterImageSet
bool GetSelected(bool defaultValue=false)
Returns the selected flag.
SCR_FilterCategory GetCategory()
Returns the category of this filter.
void SetSelected(bool newValue)
Sets the selected flag, doesn't do anything special.
bool m_bSelected
void Init(SCR_FilterCategory category)
SCR_FilterCategory m_Category
Set filter title in config by internal name for better readability.
ref SCR_FilterEntry FindFilter(string internalName)
Finds a filter entry within categories.
SCR_FilterCategory FindFilterCategory(string internalName)
Finds a filter category by its internal name.
array< ref SCR_FilterCategory > GetFilterCategories()
void ResetToDefaultValues()
Initializes all filters to their default values.
ref array< ref SCR_FilterCategory > m_aFilterCategories
bool AnyFilterSelected()
Storage of one filter set.
SCR_FieldOfViewSettings Attribute
EPlatform
Definition EPlatform.c:13