Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SelectionHintComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_SelectionHintComponent : ScriptedWidgetComponent
3 {
4  [Attribute("{73B3D8BBB785B5B9}UI/Textures/Common/circleFull.edds", UIWidgets.ResourceNamePicker, "")]
5  protected ResourceName m_sHintElementTexture;
6 
7  [Attribute("", UIWidgets.ResourceNamePicker, "")]
8  protected ResourceName m_sHintElementImage;
9 
10  [Attribute("SelectionHintElement", UIWidgets.EditBox, "Name for generated selection hints widgets")]
11  protected string m_sSelectionHintElementName;
12 
13  [Attribute("0.760 0.392 0.08 1", UIWidgets.ColorPicker)]
14  protected ref Color m_ColorSelected;
15 
16  [Attribute("0.25 0.25 0.25 1", UIWidgets.ColorPicker)]
17  protected ref Color m_ColorDeselected;
18 
19  [Attribute("true")]
20  protected bool m_bSetCustomSize;
21 
22  [Attribute("16")]
23  protected float m_fItemWidth;
24 
25  [Attribute("16")]
26  protected float m_fItemHeight;
27 
28  [Attribute("0.2")]
29  protected float m_fAnimationTime;
30 
31  [Attribute("8")]
32  protected float m_fItemSpacing;
33 
34  [Attribute("0")]
35  protected int m_iCurrent;
36 
37  [Attribute("0")]
38  protected int m_iItemCount;
39 
40  protected float m_fAnimationRate = SCR_WLibComponentBase.START_ANIMATION_RATE;
41  protected Widget m_wRoot;
42  protected Widget m_wCurrent;
43  protected ref array<Widget> m_aWidgets = {};
44 
45  //------------------------------------------------------------------------------------------------
46  override void HandlerAttached(Widget w)
47  {
48  m_wRoot = w;
49 
50  // Convert time to animation speed
51  GetGame().GetCallqueue().CallLater(SetAnimationRate, SCR_WLibComponentBase.START_ANIMATION_PERIOD);
52 
53  CreateWidgets(m_iItemCount);
54 
55  // Highlight correct item
56  if (m_iItemCount > m_iCurrent)
57  SetCurrentItem(m_iCurrent, false);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  protected void CreateWidgets(int count)
62  {
63  int currentCount = m_aWidgets.Count();
64  bool addWidgets;
65 
66  if (currentCount == count)
67  return;
68  else if (currentCount < count)
69  addWidgets = true;
70 
71  // Add
72  if (addWidgets)
73  {
74  int iterations = count - currentCount;
75  for (int i = 0 ; i < iterations; i++)
76  {
77  CreateWidget();
78  }
79  }
80  else
81  {
82  int iterations = currentCount - count;
83  for (int i = 0 ; i < iterations; i++)
84  {
85  // Go from the last
86  m_aWidgets[currentCount - i - 1].RemoveFromHierarchy();
87  }
88  m_aWidgets.Resize(count);
89  }
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  protected void CreateWidget()
94  {
95  Widget w = GetGame().GetWorkspace().CreateWidget(WidgetType.ImageWidgetTypeID, WidgetFlags.VISIBLE |
96  WidgetFlags.STRETCH | WidgetFlags.BLEND | WidgetFlags.INHERIT_CLIPPING, m_ColorDeselected, 0, m_wRoot);
97 
98  ImageWidget img = ImageWidget.Cast(w);
99  if (!img)
100  return;
101 
102  m_aWidgets.Insert(img);
103 
104  if (m_sHintElementTexture != string.Empty)
105  SCR_WLibComponentBase.SetTexture(img, m_sHintElementTexture, m_sHintElementImage);
106 
107  if (m_bSetCustomSize)
108  img.SetSize(m_fItemWidth, m_fItemHeight);
109 
110  img.SetName(m_sSelectionHintElementName);
111 
112  AlignableSlot.SetPadding(img, m_fItemSpacing * 0.5, 0, m_fItemSpacing * 0.5, 0);
113  AlignableSlot.SetVerticalAlign(img, LayoutVerticalAlign.Center);
114  AlignableSlot.SetHorizontalAlign(img, LayoutHorizontalAlign.Center);
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  protected void SetAnimationRate()
119  {
120  if (m_fAnimationTime <= 0)
121  m_fAnimationRate = 1000;
122  else
123  m_fAnimationRate = 1 / m_fAnimationTime;
124  }
125 
126  // Public API
127  //------------------------------------------------------------------------------------------------
128  void SetItemCount(int count, bool animate = true)
129  {
130  if (count == m_iItemCount || count == 1) // Do not show for only one item
131  return;
132 
133  m_iItemCount = count;
134  CreateWidgets(count);
135  SetCurrentItem(m_iCurrent, animate);
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  int GetItemCount()
140  {
141  return m_iItemCount;
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  int GetCurrentItem()
146  {
147  return m_iCurrent;
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  void SetCurrentItem(int index, bool animate = true)
152  {
153  Widget newWidget;
154 
155  if (index >= 0 && index < m_iItemCount)
156  newWidget = m_aWidgets[index];
157 
158  //if (m_wCurrent == newWidget)
159  //return;
160 
161  Color color;
162  foreach (int i, Widget w : m_aWidgets)
163  {
164  if (i == index)
165  color = m_ColorSelected;
166  else
167  color = m_ColorDeselected;
168 
169  ColorizeItem(w, color, animate);
170  }
171 
172  m_iCurrent = index;
173  m_wCurrent = newWidget;
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  void ColorizeItem(Widget w, Color color, bool animate)
178  {
179  if (!color || !w || w.GetColor() == color)
180  return;
181 
182  if (animate && m_fAnimationRate < SCR_WLibComponentBase.START_ANIMATION_RATE)
183  AnimateWidget.Color(w, color, m_fAnimationRate);
184  else
185  w.SetColor(color);
186  }
187 };
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
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_aWidgets
ref array< Widget > m_aWidgets
Definition: SCR_UITaskManagerComponent.c:25
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_SelectionHintComponent
Definition: SCR_SelectionHintComponent.c:2