Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpinBoxPaging.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 [Attribute("MenuTabRight")]
5 protected string m_sLeftAction;
6
7 [Attribute("MenuTabLeft")]
8 protected string m_sRightAction;
9
10//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
11// Why is this even an attribute? Why is this string not localized?
12
13 [Attribute("%1 / %2", UIWidgets.Auto, "Text which will be visualized. %1 contains the actual page and %2 total pages")]
14 protected string m_sText;
15
16//---- REFACTOR NOTE END ----
17
18 [Attribute()]
19 ref array<string> m_aElementNames;
20
21 [Attribute()]
22 protected int m_iPageCount;
23
24 [Attribute()]
25 protected int m_iPageCurrent;
26
27 [Attribute()]
29
30//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
31// Unused
32
33 protected bool m_bEnabled = true;
34 protected bool m_bCanNavigate = true;
35
36//---- REFACTOR NOTE END ----
37
39
42
44
45 //------------------------------------------------------------------------------------------------
46 override void HandlerAttached(Widget w)
47 {
48 super.HandlerAttached(w);
49
50 m_wText = TextWidget.Cast(m_wRoot.FindAnyWidget("Text"));
51
53 if (m_ButtonLeft)
54 {
55 m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
56 m_ButtonLeft.SetAction(m_sLeftAction);
57 }
58
60 if (m_ButtonRight)
61 {
62 m_ButtonRight.m_OnActivated.Insert(OnButtonRight);
64 }
65
67 if (m_iPageCurrent < -1)
69
71 }
72
73 //------------------------------------------------------------------------------------------------
74 protected void OnButtonLeft()
75 {
76 if (m_ButtonLeft.IsEnabled())
78 }
79
80 //------------------------------------------------------------------------------------------------
81 protected void OnButtonRight()
82 {
83 if (m_ButtonRight.IsEnabled())
85 }
86
87 //------------------------------------------------------------------------------------------------
88 protected void UpdateTextAndButtons(bool animate = true)
89 {
90 bool disableLeft, disableRight;
91
92 if (m_iPageCount < 2)
93 {
94 disableLeft = true;
95 disableRight = true;
96 }
97 else if (!m_bCycleMode)
98 {
99 if (m_iPageCurrent <= 0)
100 disableLeft = true;
101 else if (m_iPageCurrent >= m_iPageCount -1)
102 disableRight = true;
103 }
104
105 if (m_ButtonLeft)
106 m_ButtonLeft.SetEnabled(!disableLeft, animate);
107
108 if (m_ButtonRight)
109 m_ButtonRight.SetEnabled(!disableRight, animate);
110
111 // Change text
112 if (!m_wText)
113 return;
114
115 int currentPage = Math.Min(m_iPageCurrent + 1, m_iPageCount);
116 m_wText.SetTextFormat(m_sText, currentPage, m_iPageCount);
117 }
118
119 //------------------------------------------------------------------------------------------------
120 void SetCurrentItem(int page, bool invokeChange = true)
121 {
122 if (m_iPageCurrent == page)
123 return;
124
125 if (page < 0 || page >= m_iPageCount)
126 {
127 if (m_bCycleMode)
128 {
129 if (page == -1)
130 page = m_iPageCount - 1;
131 else
132 page = 0;
133 }
134 else
135 {
136 return;
137 }
138 }
139
140 m_iPageCurrent = page;
142
143 // Invoke change
144 if (invokeChange)
145 m_OnChanged.Invoke(this, page);
146 }
147
148 //------------------------------------------------------------------------------------------------
149 void SetPageCount(int count, bool animate = true)
150 {
151 if (count == 0 || count == 1)
152 AnimateWidget.Opacity(m_wRoot, 0, UIConstants.FADE_RATE_DEFAULT);
153 else
154 AnimateWidget.Opacity(m_wRoot, 1, UIConstants.FADE_RATE_DEFAULT);
155
156 if (count == m_iPageCount)
157 return;
158
159 m_iPageCount = Math.Max(count, 0);
162
163 UpdateTextAndButtons(animate);
164 }
165
166 //------------------------------------------------------------------------------------------------
168 {
169 return m_iPageCount;
170 }
171
172 //------------------------------------------------------------------------------------------------
174 {
175 return m_iPageCurrent;
176 }
177
178 //------------------------------------------------------------------------------------------------
179 void SetCanNavigate(bool enable)
180 {
181 if (m_ButtonLeft)
182 m_ButtonLeft.SetEnabled(enable);
183
184 if (m_ButtonRight)
185 m_ButtonRight.SetEnabled(enable);
186 }
187
188 //------------------------------------------------------------------------------------------------
189 void SetButtonsVisible(bool visible)
190 {
191 if (m_ButtonLeft)
192 m_ButtonLeft.SetVisible(visible);
193
194 if (m_ButtonRight)
195 m_ButtonRight.SetVisible(visible);
196 }
197
198 //------------------------------------------------------------------------------------------------
199 void SetButtonsActive(bool active)
200 {
201 if (m_ButtonLeft)
202 {
203 m_ButtonLeft.m_OnActivated.Remove(OnButtonLeft);
204 if (active)
205 m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
206 }
207
208 if (m_ButtonRight)
209 {
210 m_ButtonRight.m_OnActivated.Remove(OnButtonRight);
211 if (active)
212 m_ButtonRight.m_OnActivated.Insert(OnButtonRight);
213 }
214 }
215
216 //------------------------------------------------------------------------------------------------
219 static SCR_SpinBoxPagingComponent GetSpinBoxPagingComponent(string name, Widget parent, bool searchAllChildren = true)
220 {
221 auto comp = SCR_SpinBoxPagingComponent.Cast(
222 SCR_WLibComponentBase.GetComponent(SCR_SpinBoxPagingComponent, name, parent, searchAllChildren)
223 );
224 return comp;
225 }
226};
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
Definition Math.c:13
static SCR_PagingButtonComponent GetPagingButtonComponent(string name, Widget parent, bool searchAllChildren=true)
void UpdateTextAndButtons(bool animate=true)
SCR_PagingButtonComponent m_ButtonLeft
void SetButtonsVisible(bool visible)
override void HandlerAttached(Widget w)
SCR_PagingButtonComponent m_ButtonRight
void SetButtonsActive(bool active)
void SetCurrentItem(int page, bool invokeChange=true)
ref array< string > m_aElementNames
void SetPageCount(int count, bool animate=true)
static SCR_SpinBoxPagingComponent GetSpinBoxPagingComponent(string name, Widget parent, bool searchAllChildren=true)
Base class for all final Reforger interactive elements.
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134