5 protected string m_sLeftAction;
8 protected string m_sRightAction;
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;
14 ref array<string> m_aElementNames;
17 protected int m_iPageCount;
20 protected int m_iPageCurrent;
25 protected bool m_bEnabled =
true;
26 protected bool m_bCanNavigate =
true;
27 protected TextWidget m_wText;
32 ref ScriptInvoker m_OnChanged =
new ScriptInvoker();
35 override void HandlerAttached(Widget w)
37 super.HandlerAttached(w);
39 m_wText = TextWidget.Cast(
m_wRoot.FindAnyWidget(
"Text"));
44 m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
45 m_ButtonLeft.SetAction(m_sLeftAction);
51 m_ButtonRight.m_OnActivated.Insert(OnButtonRight);
52 m_ButtonRight.SetAction(m_sRightAction);
55 m_iPageCurrent = Math.Clamp(m_iPageCurrent, 0, m_iPageCount - 1);
56 if (m_iPageCurrent < -1)
59 UpdateTextAndButtons(
false);
63 protected void OnButtonLeft()
65 if (m_ButtonLeft.IsEnabled())
66 SetCurrentItem(m_iPageCurrent - 1);
70 protected void OnButtonRight()
72 if (m_ButtonRight.IsEnabled())
73 SetCurrentItem(m_iPageCurrent + 1);
77 protected void UpdateTextAndButtons(
bool animate =
true)
79 bool disableLeft, disableRight;
88 if (m_iPageCurrent <= 0)
90 else if (m_iPageCurrent >= m_iPageCount -1)
95 m_ButtonLeft.SetEnabled(!disableLeft, animate);
98 m_ButtonRight.SetEnabled(!disableRight, animate);
104 int currentPage = Math.Min(m_iPageCurrent + 1, m_iPageCount);
105 m_wText.SetTextFormat(
m_sText, currentPage, m_iPageCount);
109 void SetCurrentItem(
int page,
bool invokeChange =
true)
111 if (m_iPageCurrent == page)
114 if (page < 0 || page >= m_iPageCount)
119 page = m_iPageCount - 1;
129 m_iPageCurrent = page;
130 UpdateTextAndButtons();
138 void SetPageCount(
int count,
bool animate =
true)
140 if (count == 0 || count == 1)
145 if (count == m_iPageCount)
148 m_iPageCount = Math.Max(count, 0);
149 if (m_iPageCurrent >= m_iPageCount)
150 SetCurrentItem(m_iPageCount - 1);
152 UpdateTextAndButtons(animate);
162 int GetCurrentIndex()
164 return m_iPageCurrent;
168 void SetCanNavigate(
bool enable)
171 m_ButtonLeft.SetEnabled(enable);
174 m_ButtonRight.SetEnabled(enable);
178 void SetButtonsVisible(
bool visible)
181 m_ButtonLeft.SetVisible(visible);
184 m_ButtonRight.SetVisible(visible);
188 void SetButtonsActive(
bool active)
192 m_ButtonLeft.m_OnActivated.Remove(OnButtonLeft);
194 m_ButtonLeft.m_OnActivated.Insert(OnButtonLeft);
199 m_ButtonRight.m_OnActivated.Remove(OnButtonRight);
201 m_ButtonRight.m_OnActivated.Insert(OnButtonRight);