Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WLibProgressBar.c
Go to the documentation of this file.
1//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
2// Does not inherit from wlib base classes, duplicates code instead.
3
5//------------------------------------------------------------------------------------------------
7{
8 protected const string WIDGET_CHANGE = "Change";
9
10 [Attribute("0")]
11 protected float m_fMin;
12
13 [Attribute("1")]
14 protected float m_fMax;
15
16 [Attribute("0.5")]
17 protected float m_fValue;
18
19 [Attribute("false")]
20 protected bool m_bReverseDirection;
21
22 [Attribute("true", desc: "Use constant speed of the animation. If false, every change will take the same time.")]
24
25 [Attribute("0.0")]
26 protected float m_fAnimationTime;
27
28 [Attribute("0.760 0.392 0.078 1")]
30
31 [Attribute("0 0 0 0.3")]
33
34 protected Widget m_wRoot;
35 protected Widget m_wBar;
36 protected Widget m_wChange;
37 protected Widget m_wSpacer;
38
39 protected float m_fChange;
40
41 //------------------------------------------------------------------------------------------------
42 override void HandlerAttached(Widget w)
43 {
44 m_wRoot = w;
45 m_wSpacer = w.FindAnyWidget("Spacer");
46 m_wChange = w.FindAnyWidget(WIDGET_CHANGE);
47 m_wBar = w.FindAnyWidget("Bar");
48
49 if (m_wBar)
50 {
51 m_wBar.SetColor(m_SliderColor);
53 m_wBar.SetZOrder(1);
54 }
55
56 Widget background = w.FindAnyWidget("Background");
57 if (background)
58 background.SetColor(m_BackgroundColor);
59
60 UpdateVisuals(false);
61 }
62
63 //------------------------------------------------------------------------------------------------
64 void SetMin(float value)
65 {
66 m_fMin = value;
68 }
69
70 //------------------------------------------------------------------------------------------------
71 void SetMax(float value)
72 {
73 m_fMax = value;
75 }
76
77 //------------------------------------------------------------------------------------------------
78 void SetValue(float value, bool animate = true)
79 {
80 m_fValue = value;
81 UpdateVisuals(animate);
82 }
83
84 //------------------------------------------------------------------------------------------------
85 void SetChange(float value)
86 {
87 m_fChange = value;
88 UpdateVisuals(false);
89 }
90
91 //------------------------------------------------------------------------------------------------
92 void UpdateVisuals(bool animate = true)
93 {
94 if (!m_wSpacer || !m_wBar)
95 return;
96
97 float progress, currentProgress, change;
98 float range = m_fMax - m_fMin;
99 if (range <= 0)
100 return;
101
102 currentProgress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
103 progress = m_fValue / range;
104 change = m_fChange / range;
105 progress = Math.Clamp(progress, 0, 1);
106
107 if (animate && m_fAnimationTime > 0 && currentProgress != progress)
108 {
109 float speed = 1 / m_fAnimationTime;
111 speed = speed * (1 / Math.AbsFloat(currentProgress - progress));
112
113 AnimateWidget.LayoutFill(m_wBar, progress, speed);
114 AnimateWidget.LayoutFill(m_wChange, change, speed);
115 AnimateWidget.LayoutFill(m_wSpacer, 1 - progress - change, speed);
116 }
117 else
118 {
119 HorizontalLayoutSlot.SetFillWeight(m_wBar, progress);
120 HorizontalLayoutSlot.SetFillWeight(m_wChange, change);
121 HorizontalLayoutSlot.SetFillWeight(m_wSpacer, 1 - progress - change);
122 }
123 }
124
125 //------------------------------------------------------------------------------------------------
127 {
130 float progress = HorizontalLayoutSlot.GetFillWeight(m_wBar);
131 float value = progress * m_fMax - m_fMin;
132 SetValue(value, false);
133 }
134
135 //------------------------------------------------------------------------------------------------
136 void SetSliderColor(Color newColor)
137 {
138 m_SliderColor = newColor;
139 m_wBar.SetColor(m_SliderColor);
140 }
141
142 //------------------------------------------------------------------------------------------------
144 {
145 if (m_wChange)
146 m_wChange.SetColor(newColor);
147 }
148
149 //------------------------------------------------------------------------------------------------
150 float GetMin()
151 {
152 return m_fMin;
153 }
154
155 //------------------------------------------------------------------------------------------------
156 float GetMax()
157 {
158 return m_fMax;
159 }
160
161 //------------------------------------------------------------------------------------------------
162 float GetValue()
163 {
164 return m_fValue;
165 }
166
167 //------------------------------------------------------------------------------------------------
169 {
170 return m_wRoot;
171 }
172
173 //------------------------------------------------------------------------------------------------
175 {
176 return m_fAnimationTime;
177 }
178
179 //------------------------------------------------------------------------------------------------
181 {
183 }
184
185 //------------------------------------------------------------------------------------------------
186 void SetUsingAnimationTime(bool enable)
187 {
189 }
190
191 //------------------------------------------------------------------------------------------------
192 void SetAnimationTime(float value)
193 {
194 m_fAnimationTime = value;
195 }
196
197 //------------------------------------------------------------------------------------------------
198 static SCR_WLibProgressBarComponent GetProgressBar(string name, Widget parent, bool searchAllChildren = true)
199 {
200 if (!parent || name == string.Empty)
201 return null;
202
203 Widget w;
204 if (searchAllChildren)
205 w = parent.FindAnyWidget(name);
206 else
207 w = parent.FindWidget(name);
208
209 if (!w)
210 {
211 Print(string.Format("SCR_WLibProgressBarComponent.GetProgressBar: widget not found: %1", name), LogLevel.WARNING);
212 Debug.DumpStack();
213 return null;
214 }
215
217 }
218};
219
220//---- REFACTOR NOTE END ----
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
static bool StopAnimation(Widget w, typename typeName)
static WidgetAnimationLayoutFill LayoutFill(Widget widget, float targetValue, float speed)
Definition Color.c:13
Definition Debug.c:13
Definition Math.c:13
Minimalist progress bar.
void SetSliderChangeColor(Color newColor)
void SetValue(float value, bool animate=true)
override void HandlerAttached(Widget w)
void UpdateVisuals(bool animate=true)
void SetSliderColor(Color newColor)
static SCR_WLibProgressBarComponent GetProgressBar(string name, Widget parent, bool searchAllChildren=true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute