Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SortElementComponent.c
Go to the documentation of this file.
2 {
3  ASCENDING = 0,
4  DESCENDING = 1,
5  NONE = 2 // This element does not perform sorting
6 };
7 
19 class SCR_SortElementComponent : SCR_ModularButtonComponent
20 {
21  protected bool m_bSortOrderAscending;
22 
23  [Attribute("", UIWidgets.Auto, "Internal name, returned by GetName()")]
24  protected string m_sName;
25 
26  [Attribute("false", UIWidgets.Auto, "Locks sorting direction only in the order set by m_bDefaultSortOrder.")]
27  protected bool m_bSortSingleOrder;
28 
29  [Attribute("0", UIWidgets.ComboBox, "Default sort order when we first click on this element.", enums: ParamEnumArray.FromEnum(ESortOrder))]
30  protected ESortOrder m_eDefaultSortOrder;
31 
32  // Tags for effects
33  const string TAG_ALL = "all";
34  const string TAG_SORT_ASC = "sort_asc";
35  const string TAG_SORT_DESC = "sort_desc";
36  const string TAG_SORT_NONE = "sort_none";
37 
38 
39  //---------------------------------------------------------------------------------------------------
40  // P U B L I C
41  //---------------------------------------------------------------------------------------------------
42 
43 
44  //---------------------------------------------------------------------------------------------------
45  void SetSortOrder(ESortOrder order)
46  {
47  if (order == ESortOrder.NONE)
48  {
49  SetToggled(false);
50  }
51  else
52  {
53  SetToggled(true);
54 
55  // If this must be sorted only in one order
56  if (m_bSortSingleOrder)
57  {
58  SelectNewSortOrder(reset: true); // To be sure...
59  }
60  else
61  {
62  if (order == ESortOrder.ASCENDING)
63  m_bSortOrderAscending = true;
64  else
65  m_bSortOrderAscending = false;
66  }
67  }
68 
69  UpdateSortEffects();
70  }
71 
72  //---------------------------------------------------------------------------------------------------
73  ESortOrder GetSortOrder()
74  {
75  if (!GetToggled())
76  return ESortOrder.NONE;
77  else
78  {
79  if (m_bSortOrderAscending)
80  return ESortOrder.ASCENDING;
81  else
82  return ESortOrder.DESCENDING;
83  }
84  }
85 
86  //---------------------------------------------------------------------------------------------------
87  ESortOrder GetDefaultSortOrder()
88  {
89  return m_eDefaultSortOrder;
90  }
91 
92  //---------------------------------------------------------------------------------------------------
93  string GetName()
94  {
95  return m_sName;
96  }
97 
98 
99  //---------------------------------------------------------------------------------------------------
100  // P R O T E C T E D
101  //---------------------------------------------------------------------------------------------------
102 
103  //---------------------------------------------------------------------------------------------------
104  protected override void HandlerAttached(Widget w)
105  {
106  super.HandlerAttached(w);
107 
108  // Setting default sort order to NONE is illegal
109  if (m_eDefaultSortOrder == ESortOrder.NONE)
110  m_eDefaultSortOrder = ESortOrder.ASCENDING;
111 
112  // Override toggle-ability:
113  m_bCanBeToggled = true; // This can be toggled, when toggled it means that we are sorting by this column
114  m_bToggledOnlyThroughApi = true; // Toggled only through API, because when it's toggled on, we don't want to untoggle it.
115  SelectNewSortOrder(reset: true);
116  UpdateSortEffects();
117  }
118 
119  //---------------------------------------------------------------------------------------------------
120  protected override void Internal_SetToggled(bool newToggled, bool invokeOnToggled = true)
121  {
122  super.Internal_SetToggled(newToggled, invokeOnToggled);
123  UpdateSortEffects();
124  }
125 
126  //---------------------------------------------------------------------------------------------------
127  protected override bool OnClick(Widget w, int x, int y, int button)
128  {
129  bool oldToggled = m_bToggled;
130 
131  if (!oldToggled)
132  Internal_SetToggled(true, true);
133 
134  SelectNewSortOrder(reset: !oldToggled); // Reset sort order when switching from toggled off to toggled on state
135  UpdateSortEffects();
136 
137  bool returnValue = super.OnClick(w, x, y, button);
138 
139  return returnValue;
140  }
141 
142 
143  //---------------------------------------------------------------------------------------------------
145  protected void SelectNewSortOrder(bool reset)
146  {
147  if (m_bSortSingleOrder || reset)
148  {
149  if (m_eDefaultSortOrder == ESortOrder.ASCENDING)
150  m_bSortOrderAscending = true;
151  else
152  m_bSortOrderAscending = false;
153  }
154  else
155  {
156  m_bSortOrderAscending = !m_bSortOrderAscending;
157  }
158  }
159 
160  //---------------------------------------------------------------------------------------------------
164  protected void UpdateSortEffects()
165  {
166  array<string> tags = {TAG_ALL};
167  if (GetToggled())
168  {
169  if (m_bSortOrderAscending)
170  tags.Insert(TAG_SORT_ASC);
171  else
172  tags.Insert(TAG_SORT_DESC);
173  }
174  else
175  tags.Insert(TAG_SORT_NONE);
176 
178  }
179 
180 
181 };
ASCENDING
@ ASCENDING
Definition: SCR_SortElementComponent.c:3
GetToggled
bool GetToggled()
Definition: SCR_ModularButtonComponent.c:129
m_bCanBeToggled
protected bool m_bCanBeToggled
Definition: SCR_ModularButtonComponent.c:41
m_bToggled
protected bool m_bToggled
Definition: SCR_ModularButtonComponent.c:76
m_bToggledOnlyThroughApi
protected bool m_bToggledOnlyThroughApi
Definition: SCR_ModularButtonComponent.c:44
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SortElementComponent
Definition: SCR_SortElementComponent.c:19
SetToggled
void SetToggled(bool toggled, bool invokeOnToggled=true)
Definition: SCR_ModularButtonComponent.c:115
DESCENDING
@ DESCENDING
Definition: SCR_SortElementComponent.c:4
NONE
@ NONE
Definition: SCR_SortElementComponent.c:5
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19
SetEffectsWithAnyTagEnabled
void SetEffectsWithAnyTagEnabled(notnull array< string > tags)
Definition: SCR_ModularButtonComponent.c:259
ESortOrder
ESortOrder
Definition: SCR_SortElementComponent.c:1