Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WLibProgressBar.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 class SCR_WLibProgressBarComponent : ScriptedWidgetComponent
4 {
5  protected const string WIDGET_CHANGE = "Change";
6 
7  [Attribute("0")]
8  protected float m_fMin;
9 
10  [Attribute("1")]
11  protected float m_fMax;
12 
13  [Attribute("0.5")]
14  protected float m_fValue;
15 
16  [Attribute("false")]
17  protected bool m_bReverseDirection;
18 
19  [Attribute("true", desc: "Use constant speed of the animation. If false, every change will take the same time.")]
20  protected bool m_bConstantAnimationSpeed;
21 
22  [Attribute("0.0")]
23  protected float m_fAnimationTime;
24 
25  [Attribute("0.760 0.392 0.078 1")]
26  ref Color m_SliderColor;
27 
28  [Attribute("0 0 0 0.3")]
29  ref Color m_BackgroundColor;
30 
31  protected Widget m_wRoot;
32  protected Widget m_wBar;
33  protected Widget m_wChange;
34  protected Widget m_wSpacer;
35 
36  protected float m_fChange;
37 
38  //------------------------------------------------------------------------------------------------
39  override void HandlerAttached(Widget w)
40  {
41  m_wRoot = w;
42  m_wSpacer = w.FindAnyWidget("Spacer");
43  m_wChange = w.FindAnyWidget(WIDGET_CHANGE);
44  m_wBar = w.FindAnyWidget("Bar");
45 
46  if (m_wBar)
47  {
48  m_wBar.SetColor(m_SliderColor);
49  if (m_bReverseDirection)
50  m_wBar.SetZOrder(1);
51  }
52 
53  Widget background = w.FindAnyWidget("Background");
54  if (background)
55  background.SetColor(m_BackgroundColor);
56 
57  UpdateVisuals(false);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  void SetMin(float value)
62  {
63  m_fMin = value;
64  UpdateVisuals();
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  void SetMax(float value)
69  {
70  m_fMax = value;
71  UpdateVisuals();
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  void SetValue(float value, bool animate = true)
76  {
77  m_fValue = value;
78  UpdateVisuals(animate);
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  void SetChange(float value)
83  {
84  m_fChange = value;
85  UpdateVisuals(false);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  void UpdateVisuals(bool animate = true)
90  {
91  if (!m_wSpacer || !m_wBar)
92  return;
93 
94  float progress, currentProgress, change;
95  float range = m_fMax - m_fMin;
96  if (range <= 0)
97  return;
98 
99  currentProgress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
100  progress = m_fValue / range;
101  change = m_fChange / range;
102  progress = Math.Clamp(progress, 0, 1);
103 
104  if (animate && m_fAnimationTime > 0 && currentProgress != progress)
105  {
106  float speed = 1 / m_fAnimationTime;
107  if (m_bConstantAnimationSpeed)
108  speed = speed * (1 / Math.AbsFloat(currentProgress - progress));
109 
110  AnimateWidget.LayoutFill(m_wBar, progress, speed);
111  AnimateWidget.LayoutFill(m_wChange, change, speed);
112  AnimateWidget.LayoutFill(m_wSpacer, 1 - progress - change, speed);
113  }
114  else
115  {
116  HorizontalLayoutSlot.SetFillWeight(m_wBar, progress);
117  HorizontalLayoutSlot.SetFillWeight(m_wChange, change);
118  HorizontalLayoutSlot.SetFillWeight(m_wSpacer, 1 - progress - change);
119  }
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  void StopProgressAnimation()
124  {
125  AnimateWidget.StopAnimation(m_wBar, WidgetAnimationLayoutFill);
126  AnimateWidget.StopAnimation(m_wSpacer, WidgetAnimationLayoutFill);
127  float progress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
128  float value = progress * m_fMax - m_fMin;
129  SetValue(value, false);
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  void SetSliderColor(Color newColor)
134  {
135  m_SliderColor = newColor;
136  m_wBar.SetColor(m_SliderColor);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  void SetSliderChangeColor(Color newColor)
141  {
142  if (m_wChange)
143  m_wChange.SetColor(newColor);
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  float GetMin()
148  {
149  return m_fMin;
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  float GetMax()
154  {
155  return m_fMax;
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  float GetValue()
160  {
161  return m_fValue;
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  Widget GetRootWidget()
166  {
167  return m_wRoot;
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  float GetAnimationSpeed()
172  {
173  return m_fAnimationTime;
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  bool IsUsingAnimationTime()
178  {
179  return m_bConstantAnimationSpeed;
180  }
181 
182  //------------------------------------------------------------------------------------------------
183  void SetUsingAnimationTime(bool enable)
184  {
185  m_bConstantAnimationSpeed = enable;
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  void SetAnimationTime(float value)
190  {
191  m_fAnimationTime = value;
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  static SCR_WLibProgressBarComponent GetProgressBar(string name, Widget parent, bool searchAllChildren = true)
196  {
197  if (!parent || name == string.Empty)
198  return null;
199 
200  Widget w;
201  if (searchAllChildren)
202  w = parent.FindAnyWidget(name);
203  else
204  w = parent.FindWidget(name);
205 
206  if (!w)
207  {
208  Print(string.Format("SCR_WLibProgressBarComponent.GetProgressBar: widget not found: %1", name), LogLevel.WARNING);
209  Debug.DumpStack();
210  return null;
211  }
212 
214  }
215 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_fMax
protected float m_fMax
Definition: SCR_BaseEditorAttribute.c:520
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_WLibProgressBarComponent
Minimalist progress bar.
Definition: SCR_WLibProgressBar.c:3
m_fMin
SCR_BaseEditorAttributeEntryUIInfo m_fMin