Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FilterSet.c
Go to the documentation of this file.
1 /*
2 Base 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  protected bool m_bSelected;
31 
32  // Pointer back to category of this filter, initialized in constructor of Category class
33  protected SCR_FilterCategory m_Category;
34 
35  //-----------------------------------------------------------------------------------------------------------
37  SCR_FilterCategory GetCategory() { return m_Category; }
38 
39  //-----------------------------------------------------------------------------------------------------------
41  void SetSelected(bool newValue) { m_bSelected = newValue; }
42 
43  //-----------------------------------------------------------------------------------------------------------
45  bool GetSelected(bool defaultValue = false)
46  {
47  if (defaultValue)
48  return m_bSelectedAtStart;
49 
50  return m_bSelected;
51  }
52 
53  //-----------------------------------------------------------------------------------------------------------
54  void Init(SCR_FilterCategory category)
55  {
56  m_Category = category;
57  }
58 };
59 
60 
61 //-----------------------------------------------------------------------------------------------------------
66 {
67  [Attribute()]
68  string m_sDisplayName;
69 
70  [Attribute()]
71  string m_sInternalName;
72 
73  [Attribute("false", UIWidgets.Auto, "Only one filter can be enabled at a time.")]
74  bool m_bMutuallyExclusive;
75 
76  [Attribute("true", UIWidgets.Auto, "When false, the filter panel will prohibit deselection of last selected entry.")];
77  bool m_bAllowNothingSelected;
78 
79  //[Attribute("false", UIWidgets.Auto, "The category is hidden in release build.")]
80  //bool m_bHiddenInReleaseBuild;
81 
82  //[Attribute("0", UIWidgets.ComboBox, "Type", "", ParamEnumArray.FromEnum(EContentBrowserFilterType) )]
83  //EContentBrowserFilterType m_eFilterType;
84 
85  [Attribute("", UIWidgets.ResourcePickerThumbnail, "Common image set for individual filters. Each filter can override it though.", "imageset")]
86  ResourceName m_sFilterImageSet;
87 
88  [Attribute("{00FE3DBDFD15227B}UI/Textures/Icons/icons_wrapperUI-glow.imageset", UIWidgets.ResourcePickerThumbnail, "imageset")]
89  ResourceName m_sFilterGlowImageSet;
90 
91  [Attribute("", UIWidgets.Object)]
92  protected ref array<ref SCR_FilterEntry> m_aFilters;
93 
94 
95  //-----------------------------------------------------------------------------------------------------------
96  protected void SCR_FilterCategory()
97  {
98  // Register the back-pointer of all child filters
99 
100  // !! This object is instantiated as a property of another scripted object,
101  // So when constructor is called, all objects of m_aFilters are already created by the game
102 
103  foreach (auto f : m_aFilters)
104  f.Init(this);
105  }
106 
107  // ------------ Public API ----------------
108 
109  //-----------------------------------------------------------------------------------------------------------
111  array<ref SCR_FilterEntry> GetFilters()
112  {
113  return m_aFilters;
114  }
115 
116  //-----------------------------------------------------------------------------------------------------------
118  SCR_FilterEntry FindFilter(string internalName)
119  {
120  foreach (SCR_FilterEntry e : m_aFilters)
121  {
122  if (e.m_sInternalName == internalName)
123  return e;
124  }
125 
126  return null;
127  }
128 
129  //-----------------------------------------------------------------------------------------------------------
130  bool GetAllSelected()
131  {
132  foreach (auto f : m_aFilters)
133  {
134  if (!f.GetSelected())
135  return false;
136  }
137  return true;
138  }
139 
140  //-----------------------------------------------------------------------------------------------------------
141  bool GetAnySelected()
142  {
143  foreach (auto f : m_aFilters)
144  {
145  if (f.GetSelected())
146  return true;
147  }
148  return false;
149  }
150 
151  //-----------------------------------------------------------------------------------------------------------
152  bool GetAllDeselected()
153  {
154  foreach (auto f : m_aFilters)
155  {
156  if (f.GetSelected())
157  return false;
158  }
159  return true;
160  }
161 
162  //-----------------------------------------------------------------------------------------------------------
164  int GetSelectedCount()
165  {
166  int n = 0;
167  foreach (auto f : m_aFilters)
168  {
169  if (f.GetSelected())
170  n++;
171  }
172  return n;
173  }
174 };
175 
176 
177 
178 //-----------------------------------------------------------------------------------------------------------
182 [BaseContainerProps(configRoot : true)]
184 {
185  [Attribute("", UIWidgets.Object)]
186  protected ref array<ref SCR_FilterCategory> m_aFilterCategories;
187 
188  //-----------------------------------------------------------------------------------------------------------
189  array<ref SCR_FilterCategory> GetFilterCategories()
190  {
191  return m_aFilterCategories;
192  }
193 
194  //-----------------------------------------------------------------------------------------------------------
196  SCR_FilterCategory FindFilterCategory(string internalName)
197  {
198  foreach (SCR_FilterCategory cat : m_aFilterCategories)
199  {
200  if (cat.m_sInternalName == internalName)
201  return cat;
202  }
203  return null;
204  }
205 
206  //-----------------------------------------------------------------------------------------------------------
208  ref SCR_FilterEntry FindFilter(string internalName)
209  {
210  foreach (SCR_FilterCategory cat : m_aFilterCategories)
211  {
212  SCR_FilterEntry filter = cat.FindFilter(internalName);
213  if (filter)
214  return filter;
215  }
216  return null;
217  }
218 
219  //-----------------------------------------------------------------------------------------------------------
220  bool AnyFilterSelected()
221  {
222  bool selected;
223  foreach (SCR_FilterCategory category : m_aFilterCategories)
224  {
225  selected = category.GetAnySelected();
226  if (selected)
227  return true;
228  }
229 
230  return false;
231  }
232 
233  //-----------------------------------------------------------------------------------------------------------
235  void ResetToDefaultValues()
236  {
237  // Select filters which must be selected at start according to SelectedAtStart flag
238  foreach (SCR_FilterCategory category : m_aFilterCategories)
239  {
240  foreach (SCR_FilterEntry filter : category.GetFilters())
241  filter.SetSelected(filter.m_bSelectedAtStart);
242  }
243  }
244 };
245 
246 //------------------------------------------------------------------------------------------------
248 class SCR_FilterEntryTitle : BaseContainerCustomTitle
249 {
250  //------------------------------------------------------------------------------------------------
251  override bool _WB_GetCustomTitle(BaseContainer source, out string title)
252  {
253  source.Get("m_sInternalName", title);
254  return true;
255  }
256 };
257 
258 
259 // ----------------- Saving / Loading --------------------
260 
261 //------------------------------------------------------------------------------------------------
265 {
266  const int CURRENT_VERSION = 1;
267 
268  [Attribute()]
269  string m_sTag; // Filter sets are identified by this tag, tag should be unique
270 
271  [Attribute()]
272  ref array<string> m_aSelectedFilters; // Array of selected filters
273 
274  [Attribute()]
275  ref array<string> m_aSelectedCategories;// Categories of those selected filters
276 
277  [Attribute()]
278  int m_iVersion; // Version. In the future filters will change, we will have to detect old filters.
279 };
280 
281 //------------------------------------------------------------------------------------------------
282 class SCR_AllFilterSetsStorage : ModuleGameSettings
283 {
284  [Attribute()]
285  ref array<ref SCR_FilterSetStorage> m_aFilterSets;
286 
287 
288  //------------------------------------------------------------------------------------------------
289  static void SaveFilterSet(string tag, SCR_FilterSet filterSet)
290  {
292  BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
293  BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
294 
295  // Delete the old data for this tag, if found
296  for (int i = allFilterSets.m_aFilterSets.Count()-1; i >= 0; i--)
297  {
298  SCR_FilterSetStorage storedFilterSet = allFilterSets.m_aFilterSets[i];
299  if (storedFilterSet.m_sTag == tag)
300  {
301  allFilterSets.m_aFilterSets.Remove(i);
302  }
303  }
304 
305  // Create a new entry for this filter set
306  SCR_FilterSetStorage filterSetStorage = new SCR_FilterSetStorage;
307  filterSetStorage.m_iVersion = SCR_FilterSetStorage.CURRENT_VERSION;
308  filterSetStorage.m_sTag = tag;
309  if (!filterSetStorage.m_aSelectedFilters)
310  filterSetStorage.m_aSelectedFilters = new array<string>;
311  if (!filterSetStorage.m_aSelectedCategories)
312  filterSetStorage.m_aSelectedCategories = new array<string>;
313 
314  foreach (SCR_FilterCategory category : filterSet.GetFilterCategories())
315  {
316  foreach (SCR_FilterEntry filter : category.GetFilters())
317  {
318  // Save filters
319  if (filter.GetSelected() && !filter.m_sInternalName.IsEmpty() && !category.m_sInternalName.IsEmpty() )
320  {
321  filterSetStorage.m_aSelectedCategories.Insert(category.m_sInternalName);
322  filterSetStorage.m_aSelectedFilters.Insert(filter.m_sInternalName);
323  }
324  }
325  }
326 
327  allFilterSets.m_aFilterSets.Insert(filterSetStorage);
328 
329  BaseContainerTools.ReadFromInstance(allFilterSets, allFilterSetsContainer);
330  GetGame().UserSettingsChanged();
331  GetGame().SaveUserSettings();
332  }
333 
334 
335 
336  //------------------------------------------------------------------------------------------------
337  bool IsFilterSetSaved(string tag)
338  {
340  BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
341  BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
342 
343  // Find the old data for this tag
344  SCR_FilterSetStorage storedFilterSet;
345  for (int i = 0; i < allFilterSets.m_aFilterSets.Count(); i++)
346  {
347  SCR_FilterSetStorage iFilterSet = allFilterSets.m_aFilterSets[i];
348  if (iFilterSet.m_sTag == tag)
349  return true;
350  }
351 
352  return false;
353  }
354 
355 
356 
357  //------------------------------------------------------------------------------------------------
358  static bool TryLoadFilterSet(string tag, SCR_FilterSet filterSet)
359  {
361  BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
362  BaseContainerTools.WriteToInstance(allFilterSets, allFilterSetsContainer);
363 
364  // Find the old data for this tag
365  SCR_FilterSetStorage storedFilterSet;
366  for (int i = 0; i < allFilterSets.m_aFilterSets.Count(); i++)
367  {
368  SCR_FilterSetStorage iFilterSet = allFilterSets.m_aFilterSets[i];
369  if (iFilterSet.m_sTag == tag)
370  {
371  storedFilterSet = iFilterSet;
372  break;
373  }
374  }
375 
376  // Bail if not found
377  if (!storedFilterSet)
378  return false;
379 
380  // Bail if version is invalid
381  if (storedFilterSet.m_iVersion > SCR_FilterSetStorage.CURRENT_VERSION)
382  {
383  return false;
384  }
385 
386  // Restore selected filters
387 
388  // Clear up first
389  foreach (SCR_FilterCategory category : filterSet.GetFilterCategories())
390  {
391  foreach (SCR_FilterEntry filter : category.GetFilters())
392  {
393  filter.SetSelected(false);
394  }
395  }
396 
397  // Select filters which are selected in saved data
398  for (int i = 0; i < storedFilterSet.m_aSelectedFilters.Count(); i++)
399  {
400  string filterName = storedFilterSet.m_aSelectedFilters[i];
401  string categoryName = storedFilterSet.m_aSelectedCategories[i];
402 
403  SCR_FilterCategory category = filterSet.FindFilterCategory(categoryName);
404 
405  if (category)
406  {
407  SCR_FilterEntry filter = category.FindFilter(filterName);
408  if (filter)
409  filter.SetSelected(true);
410  }
411  }
412 
413  return true;
414  }
415 
416  //------------------------------------------------------------------------------------------------
418  static void ResetAllToDefault()
419  {
420  // Find storage
422  allFilterSets.m_aFilterSets = {};
423  BaseContainer allFilterSetsContainer = GetGame().GetGameUserSettings().GetModule("SCR_AllFilterSetsStorage");
424 
425  // Save settings
426  BaseContainerTools.ReadFromInstance(allFilterSets, allFilterSetsContainer);
427  GetGame().UserSettingsChanged();
428  GetGame().SaveUserSettings();
429  }
430 };
BaseContainerProps
class SCR_FilterEntry BaseContainerProps
SCR_FilterEntry
Definition: SCR_FilterSet.c:9
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_FilterCategory
Definition: SCR_FilterSet.c:65
SCR_FilterSet
Definition: SCR_FilterSet.c:183
SCR_FilterSetStorage
Storage of one filter set.
Definition: SCR_FilterSet.c:264
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_FilterEntryTitle
Set filter title in config by internal name for better readability.
Definition: SCR_FilterSet.c:248
m_bSelected
protected bool m_bSelected
Definition: SCR_InventoryHitZonePointUI.c:396
SCR_AllFilterSetsStorage
Definition: SCR_FilterSet.c:282
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180