Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SortHeaderComponent.c
Go to the documentation of this file.
1 
7 class SCR_SortHeaderComponent : ScriptedWidgetComponent
8 {
9  [Attribute("-1", UIWidgets.Auto, "ID of the element selected by default. When -1, none is selected at start.")]
10  int m_iDefaultSortElement;
11 
12  // Event handlers
13  ref ScriptInvoker m_OnChanged = new ScriptInvoker; // (SCR_SortHeaderComponent sortHeader)
14 
15  protected ref array<SCR_SortElementComponent> m_aSortElements;
16 
17  protected Widget m_wRoot;
18 
19  //---------------------------------------------------------------------------------------------------
20  // P U B L I C
21  //---------------------------------------------------------------------------------------------------
22 
23  //---------------------------------------------------------------------------------------------------
24  ESortOrder GetSortOrder()
25  {
26  SCR_SortElementComponent comp = GetCurrentSortElement();
27 
28  if (!comp)
29  return ESortOrder.NONE;
30 
31  return comp.GetSortOrder();
32  }
33 
34  //---------------------------------------------------------------------------------------------------
36  bool GetSortOrderAscending()
37  {
38  return GetSortOrder() == ESortOrder.ASCENDING;
39  }
40 
41  //---------------------------------------------------------------------------------------------------
42  int GetSortElementId()
43  {
44  for (int i = 0; i < m_aSortElements.Count(); i++)
45  {
46  if (m_aSortElements[i].GetSortOrder() != ESortOrder.NONE)
47  return i;
48  }
49  return -1;
50  }
51 
52  //---------------------------------------------------------------------------------------------------
53  string GetSortElementName()
54  {
55  SCR_SortElementComponent comp = GetCurrentSortElement();
56 
57  if (!comp)
58  return string.Empty;
59 
60  return comp.GetName();
61  }
62 
63  //---------------------------------------------------------------------------------------------------
65  int FindElement(string name)
66  {
67  int count = m_aSortElements.Count();
68  for (int i = 0; i < count; i++)
69  {
70  if (m_aSortElements[i].GetName() == name)
71  return i;
72  }
73 
74  return -1;
75  }
76 
77  //---------------------------------------------------------------------------------------------------
78  void SetCurrentSortElement(int id, ESortOrder order, bool useDefaultSortOrder = false, bool invokeOnChanged = true)
79  {
80  if (id < 0 || id >= m_aSortElements.Count())
81  return;
82 
83  int count = m_aSortElements.Count();
84 
85  for (int i = 0; i < count; i++)
86  {
87  if (i != id)
88  m_aSortElements[i].SetSortOrder(ESortOrder.NONE);
89  }
90 
91  SCR_SortElementComponent comp = m_aSortElements[id];
92  if (useDefaultSortOrder)
93  comp.SetSortOrder(comp.GetDefaultSortOrder());
94  else
95  comp.SetSortOrder(order);
96 
97  if (invokeOnChanged)
98  InvokeOnChanged();
99  }
100 
101  //---------------------------------------------------------------------------------------------------
102  void SetElementVisible(int id, bool visible)
103  {
104  if (id < 0 || id >= m_aSortElements.Count())
105  return;
106 
107  m_aSortElements[id].GetRootWidget().SetVisible(visible);
108  }
109 
110  //---------------------------------------------------------------------------------------------------
111  Widget GetRootWidget()
112  {
113  return m_wRoot;
114  }
115 
116 
117  //---------------------------------------------------------------------------------------------------
119  void SetFocus(int id)
120  {
121  if (id < 0 || id >= m_aSortElements.Count())
122  return;
123 
124  SCR_SortElementComponent comp = m_aSortElements[id];
125  GetGame().GetWorkspace().SetFocusedWidget(comp.GetRootWidget());
126  }
127 
128  //---------------------------------------------------------------------------------------------------
129  // P R O T E C T E D
130  //---------------------------------------------------------------------------------------------------
131 
132  //---------------------------------------------------------------------------------------------------
133  override protected void HandlerAttached(Widget w)
134  {
135  m_wRoot = w;
136  m_aSortElements = {};
137  FindAllSortButtons(w, m_aSortElements);
138 
139  // Select default sort element
140  if (m_iDefaultSortElement != -1)
141  SetCurrentSortElement(m_iDefaultSortElement, ESortOrder.NONE, useDefaultSortOrder:true, invokeOnChanged: false);
142 
143  // Subscribe to events of buttons
144  foreach (SCR_SortElementComponent comp : m_aSortElements)
145  {
146  comp.m_OnClicked.Insert(OnButtonClicked);
147  }
148  }
149 
150  //---------------------------------------------------------------------------------------------------
152  protected static void FindAllSortButtons(Widget w, array<SCR_SortElementComponent> components)
153  {
155  if (comp)
156  components.Insert(comp);
157 
158  Widget child = w.GetChildren();
159  while (child)
160  {
161  FindAllSortButtons(child, components);
162  child = child.GetSibling();
163  }
164  }
165 
166  //---------------------------------------------------------------------------------------------------
167  protected void OnButtonClicked(SCR_ModularButtonComponent compClicked)
168  {
169  // Untoggle all other buttons
170  foreach (SCR_SortElementComponent comp : m_aSortElements)
171  {
172  if (comp != compClicked && comp.GetSortOrder() != ESortOrder.NONE)
173  comp.SetSortOrder(ESortOrder.NONE);
174  }
175 
176  InvokeOnChanged();
177  }
178 
179  //---------------------------------------------------------------------------------------------------
180  protected SCR_SortElementComponent GetCurrentSortElement()
181  {
182  foreach (SCR_SortElementComponent comp : m_aSortElements)
183  {
184  if (comp.GetSortOrder() != ESortOrder.NONE)
185  return comp;
186  }
187  return null;
188  }
189 
190  //---------------------------------------------------------------------------------------------------
191  protected void InvokeOnChanged()
192  {
193  m_OnChanged.Invoke(this);
194  }
195 };
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_OnChanged
protected ref ScriptInvokerTabViewIndex m_OnChanged
Definition: SCR_TabViewComponent.c:64
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SortElementComponent
Definition: SCR_SortElementComponent.c:19
SCR_SortHeaderComponent
Definition: SCR_SortHeaderComponent.c:7
ESortOrder
ESortOrder
Definition: SCR_SortElementComponent.c:1