Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SortHeaderComponent.c
Go to the documentation of this file.
1
6
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 //---------------------------------------------------------------------------------------------------
25 {
27
28 if (!comp)
29 return ESortOrder.NONE;
30
31 return comp.GetSortOrder();
32 }
33
34 //---------------------------------------------------------------------------------------------------
37 {
38 return GetSortOrder() == ESortOrder.ASCENDING;
39 }
40
41 //---------------------------------------------------------------------------------------------------
43 {
44 for (int i = 0; i < m_aSortElements.Count(); i++)
45 {
47 return i;
48 }
49 return -1;
50 }
51
52 //---------------------------------------------------------------------------------------------------
54 {
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 {
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
92 if (useDefaultSortOrder)
94 else
95 comp.SetSortOrder(order);
96
97 if (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 //---------------------------------------------------------------------------------------------------
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
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 = {};
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
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
171 {
172 if (comp != compClicked && comp.GetSortOrder() != ESortOrder.NONE)
173 comp.SetSortOrder(ESortOrder.NONE);
174 }
175
177 }
178
179 //---------------------------------------------------------------------------------------------------
181 {
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};
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SetSortOrder(ESortOrder order)
ref array< SCR_SortElementComponent > m_aSortElements
void OnButtonClicked(SCR_ModularButtonComponent compClicked)
void SetFocus(int id)
Sets focus on element with ID.
bool GetSortOrderAscending()
True when sort order is ASCENDING.
void SetCurrentSortElement(int id, ESortOrder order, bool useDefaultSortOrder=false, bool invokeOnChanged=true)
SCR_SortElementComponent GetCurrentSortElement()
static void FindAllSortButtons(Widget w, array< SCR_SortElementComponent > components)
Find all sort button components recursively.
int FindElement(string name)
Finds element by name. Returns id, or -1 if not found.
void SetElementVisible(int id, bool visible)
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134