Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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  [Attribute("%1 / %2", UIWidgets.Auto, "Text which will be visualized. %1 contains the actual page and %2 total pages")]
11  protected string m_sText;
12 
13  [Attribute()]
14  ref array<string> m_aElementNames;
15 
16  [Attribute()]
17  protected int m_iPageCount;
18 
19  [Attribute()]
20  protected int m_iPageCurrent;
21 
22  [Attribute()]
23  bool m_bCycleMode;
24 
25  protected bool m_bEnabled = true;
26  protected bool m_bCanNavigate = true;
27  protected TextWidget m_wText;
28 
29  protected SCR_PagingButtonComponent m_ButtonLeft;
30  protected SCR_PagingButtonComponent m_ButtonRight;
31 
32  ref ScriptInvoker m_OnChanged = new ScriptInvoker();
33 
34  //------------------------------------------------------------------------------------------------
35  override void HandlerAttached(Widget w)
36  {
37  super.HandlerAttached(w);
38 
39  m_wText = TextWidget.Cast(m_wRoot.FindAnyWidget("Text"));
40 
41  m_ButtonLeft = SCR_PagingButtonComponent.GetPagingButtonComponent("ButtonLeft", w);
42  if (m_ButtonLeft)
43  {
44  m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
45  m_ButtonLeft.SetAction(m_sLeftAction);
46  }
47 
48  m_ButtonRight = SCR_PagingButtonComponent.GetPagingButtonComponent("ButtonRight", w);
49  if (m_ButtonRight)
50  {
51  m_ButtonRight.m_OnActivated.Insert(OnButtonRight);
52  m_ButtonRight.SetAction(m_sRightAction);
53  }
54 
55  m_iPageCurrent = Math.Clamp(m_iPageCurrent, 0, m_iPageCount - 1);
56  if (m_iPageCurrent < -1)
57  m_iPageCurrent = 0;
58 
59  UpdateTextAndButtons(false);
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected void OnButtonLeft()
64  {
65  if (m_ButtonLeft.IsEnabled())
66  SetCurrentItem(m_iPageCurrent - 1);
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  protected void OnButtonRight()
71  {
72  if (m_ButtonRight.IsEnabled())
73  SetCurrentItem(m_iPageCurrent + 1);
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  protected void UpdateTextAndButtons(bool animate = true)
78  {
79  bool disableLeft, disableRight;
80 
81  if (m_iPageCount < 2)
82  {
83  disableLeft = true;
84  disableRight = true;
85  }
86  else if (!m_bCycleMode)
87  {
88  if (m_iPageCurrent <= 0)
89  disableLeft = true;
90  else if (m_iPageCurrent >= m_iPageCount -1)
91  disableRight = true;
92  }
93 
94  if (m_ButtonLeft)
95  m_ButtonLeft.SetEnabled(!disableLeft, animate);
96 
97  if (m_ButtonRight)
98  m_ButtonRight.SetEnabled(!disableRight, animate);
99 
100  // Change text
101  if (!m_wText)
102  return;
103 
104  int currentPage = Math.Min(m_iPageCurrent + 1, m_iPageCount);
105  m_wText.SetTextFormat(m_sText, currentPage, m_iPageCount);
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  void SetCurrentItem(int page, bool invokeChange = true)
110  {
111  if (m_iPageCurrent == page)
112  return;
113 
114  if (page < 0 || page >= m_iPageCount)
115  {
116  if (m_bCycleMode)
117  {
118  if (page == -1)
119  page = m_iPageCount - 1;
120  else
121  page = 0;
122  }
123  else
124  {
125  return;
126  }
127  }
128 
129  m_iPageCurrent = page;
130  UpdateTextAndButtons();
131 
132  // Invoke change
133  if (invokeChange)
134  m_OnChanged.Invoke(this, page);
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  void SetPageCount(int count, bool animate = true)
139  {
140  if (count == 0 || count == 1)
141  AnimateWidget.Opacity(m_wRoot, 0, UIConstants.FADE_RATE_DEFAULT);
142  else
143  AnimateWidget.Opacity(m_wRoot, 1, UIConstants.FADE_RATE_DEFAULT);
144 
145  if (count == m_iPageCount)
146  return;
147 
148  m_iPageCount = Math.Max(count, 0);
149  if (m_iPageCurrent >= m_iPageCount)
150  SetCurrentItem(m_iPageCount - 1);
151 
152  UpdateTextAndButtons(animate);
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  int GetPageCount()
157  {
158  return m_iPageCount;
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  int GetCurrentIndex()
163  {
164  return m_iPageCurrent;
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  void SetCanNavigate(bool enable)
169  {
170  if (m_ButtonLeft)
171  m_ButtonLeft.SetEnabled(enable);
172 
173  if (m_ButtonRight)
174  m_ButtonRight.SetEnabled(enable);
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  void SetButtonsVisible(bool visible)
179  {
180  if (m_ButtonLeft)
181  m_ButtonLeft.SetVisible(visible);
182 
183  if (m_ButtonRight)
184  m_ButtonRight.SetVisible(visible);
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  void SetButtonsActive(bool active)
189  {
190  if (m_ButtonLeft)
191  {
192  m_ButtonLeft.m_OnActivated.Remove(OnButtonLeft);
193  if (active)
194  m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
195  }
196 
197  if (m_ButtonRight)
198  {
199  m_ButtonRight.m_OnActivated.Remove(OnButtonRight);
200  if (active)
201  m_ButtonRight.m_OnActivated.Insert(OnButtonRight);
202  }
203  }
204 
205  //------------------------------------------------------------------------------------------------
208  static SCR_SpinBoxPagingComponent GetSpinBoxPagingComponent(string name, Widget parent, bool searchAllChildren = true)
209  {
210  auto comp = SCR_SpinBoxPagingComponent.Cast(
211  SCR_WLibComponentBase.GetComponent(SCR_SpinBoxPagingComponent, name, parent, searchAllChildren)
212  );
213  return comp;
214  }
215 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
UIConstants
Definition: Constants.c:130
SCR_SpinBoxPagingComponent
Definition: SCR_SpinBoxPaging.c:2
m_OnChanged
protected ref ScriptInvokerTabViewIndex m_OnChanged
Definition: SCR_TabViewComponent.c:64
SCR_PagingButtonComponent
Definition: SCR_PagingButtonComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_bCycleMode
bool m_bCycleMode
Definition: SCR_TabViewComponent.c:31
m_sText
class SCR_BaseEditorAttribute m_sText