5 protected const string WIDGET_CHANGE =
"Change";
8 protected float m_fMin;
11 protected float m_fMax;
14 protected float m_fValue;
17 protected bool m_bReverseDirection;
19 [
Attribute(
"true",
desc:
"Use constant speed of the animation. If false, every change will take the same time.")]
20 protected bool m_bConstantAnimationSpeed;
23 protected float m_fAnimationTime;
26 ref Color m_SliderColor;
29 ref Color m_BackgroundColor;
31 protected Widget m_wRoot;
32 protected Widget m_wBar;
33 protected Widget m_wChange;
34 protected Widget m_wSpacer;
36 protected float m_fChange;
39 override void HandlerAttached(Widget w)
42 m_wSpacer = w.FindAnyWidget(
"Spacer");
43 m_wChange = w.FindAnyWidget(WIDGET_CHANGE);
44 m_wBar = w.FindAnyWidget(
"Bar");
48 m_wBar.SetColor(m_SliderColor);
49 if (m_bReverseDirection)
53 Widget background = w.FindAnyWidget(
"Background");
55 background.SetColor(m_BackgroundColor);
61 void SetMin(
float value)
68 void SetMax(
float value)
75 void SetValue(
float value,
bool animate =
true)
78 UpdateVisuals(animate);
82 void SetChange(
float value)
89 void UpdateVisuals(
bool animate =
true)
91 if (!m_wSpacer || !m_wBar)
94 float progress, currentProgress, change;
99 currentProgress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
100 progress = m_fValue / range;
101 change = m_fChange / range;
102 progress = Math.Clamp(progress, 0, 1);
104 if (animate && m_fAnimationTime > 0 && currentProgress != progress)
106 float speed = 1 / m_fAnimationTime;
107 if (m_bConstantAnimationSpeed)
108 speed = speed * (1 / Math.AbsFloat(currentProgress - progress));
110 AnimateWidget.LayoutFill(m_wBar, progress, speed);
111 AnimateWidget.LayoutFill(m_wChange, change, speed);
112 AnimateWidget.LayoutFill(m_wSpacer, 1 - progress - change, speed);
116 HorizontalLayoutSlot.SetFillWeight(m_wBar, progress);
117 HorizontalLayoutSlot.SetFillWeight(m_wChange, change);
118 HorizontalLayoutSlot.SetFillWeight(m_wSpacer, 1 - progress - change);
123 void StopProgressAnimation()
125 AnimateWidget.StopAnimation(m_wBar, WidgetAnimationLayoutFill);
126 AnimateWidget.StopAnimation(m_wSpacer, WidgetAnimationLayoutFill);
127 float progress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
129 SetValue(value,
false);
133 void SetSliderColor(Color newColor)
135 m_SliderColor = newColor;
136 m_wBar.SetColor(m_SliderColor);
140 void SetSliderChangeColor(Color newColor)
143 m_wChange.SetColor(newColor);
165 Widget GetRootWidget()
171 float GetAnimationSpeed()
173 return m_fAnimationTime;
177 bool IsUsingAnimationTime()
179 return m_bConstantAnimationSpeed;
183 void SetUsingAnimationTime(
bool enable)
185 m_bConstantAnimationSpeed = enable;
189 void SetAnimationTime(
float value)
191 m_fAnimationTime = value;
197 if (!parent || name ==
string.Empty)
201 if (searchAllChildren)
202 w = parent.FindAnyWidget(name);
204 w = parent.FindWidget(name);
208 Print(
string.Format(
"SCR_WLibProgressBarComponent.GetProgressBar: widget not found: %1", name), LogLevel.WARNING);