Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_SliderComponent.c
Go to the documentation of this file.
1
//------------------------------------------------------------------------------------------------
2
class
SCR_SliderComponent
:
SCR_ChangeableComponentBase
3
{
4
[
Attribute
(
"0.5"
)]
5
protected
float
m_fValue
;
6
7
[
Attribute
(
"0"
)]
8
protected
float
m_fMinValue
;
9
10
[
Attribute
(
"1"
)]
11
protected
float
m_fMaxValue
;
12
13
[
Attribute
(
"0.05"
)]
14
protected
float
m_fStep
;
15
16
[
Attribute
(
"%1"
,
UIWidgets
.LocaleEditBox,
"Localization friendly string: %1 shows primary value, %2 shows secondary value. It can be overwritten by SetValueString() function"
)]
17
protected
string
m_sFormatText
;
18
19
[
Attribute
(
"1"
,
UIWidgets
.EditBox,
"Multiplies the value in displayed text.\nWith 100 and percentage format, value 1 is visualized as 100%"
)]
20
protected
float
m_fShownValueMultiplier
;
21
22
[
Attribute
(
"1"
,
UIWidgets
.EditBox,
"Multiplies the value in displayed text.\nWith 100 and percentage format, value 1 is visualized as 100%"
)]
23
protected
float
m_fShownSecondaryMultiplier
;
24
25
[
Attribute
(
"1"
,
UIWidgets
.EditBox,
"Multiplies the internal value for primary value display before offset is added."
)]
26
protected
float
m_fValueMultiplier
;
27
28
[
Attribute
(
"1"
,
UIWidgets
.EditBox,
"Multiplies the internal value for secondary value display before offset is added."
)]
29
protected
float
m_fSecondaryMultiplier
;
30
31
[
Attribute
(
"0"
,
UIWidgets
.EditBox,
"Offsets the internal value for primary value display.\nWith 1, value 1 is read as 2"
)]
32
protected
float
m_fValueOffset
;
33
34
[
Attribute
(
"0"
,
UIWidgets
.EditBox,
"Offsets the internal value for secondary value display.\nWith 1, value 1 is read as 2"
)]
35
protected
float
m_fSecondaryOffset
;
36
37
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"Should the value text be clamped to Min/Max value after offset is added?"
)]
38
protected
bool
m_bClampValue
;
39
40
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"Should the value text be rounded?"
)]
41
protected
bool
m_bRoundValue
;
42
43
[
Attribute
(
"0"
)]
44
protected
int
m_iDecimalPrecision
;
45
46
[
Attribute
(
SCR_SoundEvent
.SOUND_FE_ITEM_CHANGE)]
47
protected
string
m_sChangeSound
;
48
49
protected
TextWidget
m_wText
;
50
protected
SliderWidget
m_wSlider
;
51
protected
float
m_fOldValue
;
52
53
protected
ref
SCR_EventHandlerComponent
m_Handler
;
54
protected
ref
ScriptInvoker
m_OnChangedFinal
;
55
56
//------------------------------------------------------------------------------------------------
57
override
void
HandlerAttached
(
Widget
w)
58
{
59
super.HandlerAttached(w);
60
61
m_wSlider
=
SliderWidget
.Cast(w.FindAnyWidget(
"Slider"
));
62
m_wText
=
TextWidget
.Cast(w.FindAnyWidget(
"SliderText"
));
63
64
if
(!
m_wSlider
)
65
return
;
66
67
// Get slider handling
68
m_Handler
=
SCR_EventHandlerComponent
.Cast(
m_wSlider
.FindHandler(
SCR_EventHandlerComponent
));
69
if
(!
m_Handler
)
70
return
;
71
72
SetSliderSettings
(
m_fMinValue
,
m_fMaxValue
,
m_fStep
,
m_sFormatText
);
73
74
m_Handler
.GetOnFocus().Insert(
OnSliderFocus
);
75
m_Handler
.GetOnFocusLost().Insert(
OnSliderFocusLost
);
76
77
m_Handler
.GetOnChange().Insert(
OnValueChanged
);
78
m_Handler
.GetOnChangeFinal().Insert(
OnValueFinal
);
79
80
UpdateValue
();
81
}
82
83
//------------------------------------------------------------------------------------------------
84
override
void
HandlerDeattached
(
Widget
w)
85
{
86
super.HandlerDeattached(w);
87
88
m_Handler
.GetOnChange().Remove(
OnValueChanged
);
89
m_Handler
.GetOnChangeFinal().Remove(
OnValueFinal
);
90
}
91
92
//------------------------------------------------------------------------------------------------
93
override
bool
OnFocus
(
Widget
w,
int
x,
int
y)
94
{
95
// Do not focus parent, call the super function on slider focus
96
97
// Set focus to handler
98
GetGame
().GetWorkspace().SetFocusedWidget(
m_wSlider
);
99
return
false
;
100
}
101
102
//------------------------------------------------------------------------------------------------
103
protected
void
OnValueChanged
(
Widget
w)
104
{
105
float
value =
UpdateValue
();
106
107
//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
108
// Can lead to severe sound spamming based on speed of user interaction
109
110
if
(
m_sChangeSound
!=
string
.Empty && !
float
.AlmostEqual(
m_fOldValue
, value))
111
PlaySound
(
m_sChangeSound
);
112
113
//---- REFACTOR NOTE END ----
114
115
m_fOldValue
= value;
116
117
m_OnChanged
.Invoke(
this
, value);
118
}
119
120
//------------------------------------------------------------------------------------------------
121
protected
float
UpdateValue
()
122
{
123
float
value;
124
if
(
m_wSlider
)
125
value =
m_wSlider
.GetCurrent();
126
127
// Update displayed text, optional secondary value display
128
if
(
m_wText
&&
m_wText
.IsVisible())
129
{
130
float
value1 = value *
m_fValueMultiplier
+
m_fValueOffset
;
131
float
value2 = value *
m_fSecondaryMultiplier
+
m_fSecondaryOffset
;
132
133
if
(
m_bClampValue
)
134
{
135
value1 =
Math
.Clamp(value1,
m_fMinValue
,
m_fMaxValue
);
136
value2 =
Math
.Clamp(value2,
m_fMinValue
,
m_fMaxValue
);
137
}
138
139
if
(
m_bRoundValue
)
140
{
141
value1 =
RoundValue
(value1 *
m_fShownValueMultiplier
,
m_iDecimalPrecision
);
142
value2 =
RoundValue
(value2 *
m_fShownSecondaryMultiplier
,
m_iDecimalPrecision
);
143
}
144
145
m_wText
.SetTextFormat(
m_sFormatText
, value1, value2);
146
}
147
148
return
value;
149
}
150
151
//------------------------------------------------------------------------------------------------
152
protected
float
RoundValue
(
float
value,
int
precision
)
153
{
154
if
(!
m_bRoundValue
)
155
return
value;
156
157
float
coef =
Math
.Pow(10,
precision
);
158
value =
Math
.Round(value * coef) / coef;
159
160
return
value;
161
}
162
163
//------------------------------------------------------------------------------------------------
164
protected
void
OnValueFinal
(
Widget
w)
165
{
166
float
value;
167
if
(
m_wSlider
)
168
value =
m_wSlider
.GetCurrent();
169
170
if
(
m_OnChangedFinal
)
171
m_OnChangedFinal
.Invoke(
this
, value);
172
}
173
174
//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
175
// Solutions such as these feel weird given the current widget event system. There's probably a better setup
176
177
//------------------------------------------------------------------------------------------------
178
protected
void
OnSliderFocus
()
179
{
180
m_wRoot
.SetFlags(
WidgetFlags
.NOFOCUS);
181
182
super.OnFocus(
m_wRoot
, 0, 0);
// Emulate focus on a parent class
183
}
184
185
//------------------------------------------------------------------------------------------------
186
protected
void
OnSliderFocusLost
()
187
{
188
m_wRoot
.ClearFlags(
WidgetFlags
.NOFOCUS);
189
190
super.OnFocusLost(
m_wRoot
, 0, 0);
// Emulate focus on a parent class
191
}
192
193
194
//---- REFACTOR NOTE END ----
195
196
// User API
197
//------------------------------------------------------------------------------------------------
198
void
SetValue
(
float
value)
199
{
200
if
(!
m_wSlider
)
201
return
;
202
203
m_fValue
= value;
204
m_wSlider
.SetCurrent(value);
205
OnValueChanged
(
m_wSlider
);
206
}
207
208
//------------------------------------------------------------------------------------------------
209
ScriptInvoker
GetOnChangedFinal
()
210
{
211
if
(!
m_OnChangedFinal
)
212
m_OnChangedFinal
=
new
ScriptInvoker
();
213
return
m_OnChangedFinal
;
214
}
215
216
//------------------------------------------------------------------------------------------------
217
float
GetValue
()
218
{
219
return
m_wSlider
.GetCurrent();
220
}
221
222
//------------------------------------------------------------------------------------------------
223
void
SetFormatText
(
string
text)
224
{
225
m_sFormatText
= text;
226
}
227
228
//------------------------------------------------------------------------------------------------
229
string
GetFormatText
()
230
{
231
return
m_sFormatText
;
232
}
233
234
//------------------------------------------------------------------------------------------------
235
void
ShowCustomValue
(
string
value)
236
{
237
if
(!
m_wText
|| !
m_wText
.IsVisible())
238
return
;
239
240
m_wText
.SetTextFormat(
m_sFormatText
, value);
241
}
242
243
//------------------------------------------------------------------------------------------------
244
void
SetSliderSettings
(
float
min,
float
max,
float
step,
string
formatText =
string
.Empty)
245
{
246
m_wSlider
.SetMin(min);
247
m_wSlider
.SetMax(max);
248
m_wSlider
.SetStep(step);
249
if
(formatText !=
string
.Empty)
250
m_sFormatText
= formatText;
251
}
252
253
//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
254
// m_wSlider could be null
255
256
//------------------------------------------------------------------------------------------------
257
void
SetMin
(
float
min)
258
{
259
m_wSlider
.SetMin(min);
260
}
261
262
//------------------------------------------------------------------------------------------------
263
void
SetMax
(
float
max)
264
{
265
m_wSlider
.SetMax(max);
266
}
267
268
//------------------------------------------------------------------------------------------------
269
void
SetStep
(
float
step)
270
{
271
m_wSlider
.SetStep(step);
272
}
273
274
//---- REFACTOR NOTE END ----
275
276
//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
277
// the error case is a valid value: why not return -1 instead?
278
279
//------------------------------------------------------------------------------------------------
280
float
GetMin
()
281
{
282
if
(!
m_wSlider
)
283
return
0;
284
285
return
m_wSlider
.GetMin();
286
}
287
288
//------------------------------------------------------------------------------------------------
289
float
GetMax
()
290
{
291
if
(!
m_wSlider
)
292
return
0;
293
294
return
m_wSlider
.GetMax();
295
}
296
297
//------------------------------------------------------------------------------------------------
298
float
GetStep
()
299
{
300
if
(!
m_wSlider
)
301
return
0;
302
303
return
m_wSlider
.GetStep();
304
}
305
306
//---- REFACTOR NOTE END ----
307
308
//------------------------------------------------------------------------------------------------
309
void
SetShownValueMultiplier
(
float
multiplier)
310
{
311
m_fShownValueMultiplier
= multiplier;
312
}
313
314
//------------------------------------------------------------------------------------------------
315
float
GetShownValueMultiplier
()
316
{
317
return
m_fShownValueMultiplier
;
318
}
319
320
//------------------------------------------------------------------------------------------------
323
static
SCR_SliderComponent
GetSliderComponent
(
string
name,
Widget
parent,
bool
searchAllChildren =
true
)
324
{
325
return
SCR_SliderComponent
.Cast(
SCR_ScriptedWidgetComponent
.
GetComponent
(
SCR_SliderComponent
, name, parent, searchAllChildren));
326
}
327
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
precision
params precision
Definition
SCR_2DOpticsComponent.c:20
Math
Definition
Math.c:13
SCR_ChangeableComponentBase
Base class for all widgets that can change their internal state as editbox or spinbox.
Definition
SCR_ChangeableComponentBase.c:5
SCR_ChangeableComponentBase::m_OnChanged
ref ScriptInvoker m_OnChanged
Definition
SCR_ChangeableComponentBase.c:34
SCR_EventHandlerComponent
Definition
SCR_EventHandlerComponent.c:9
SCR_ScriptedWidgetComponent
Definition
SCR_ScriptedWidgetComponent.c:8
SCR_ScriptedWidgetComponent::m_wRoot
Widget m_wRoot
Definition
SCR_ScriptedWidgetComponent.c:9
SCR_ScriptedWidgetComponent::GetComponent
static SCR_ScriptedWidgetComponent GetComponent(typename componentType, string name, Widget parent, bool searchAllChildren=true)
Base method for component lookup through the widget library.
Definition
SCR_ScriptedWidgetComponent.c:29
SCR_SliderComponent
Definition
SCR_SliderComponent.c:3
SCR_SliderComponent::OnSliderFocusLost
void OnSliderFocusLost()
Definition
SCR_SliderComponent.c:186
SCR_SliderComponent::m_fSecondaryOffset
float m_fSecondaryOffset
Definition
SCR_SliderComponent.c:35
SCR_SliderComponent::SetFormatText
void SetFormatText(string text)
Definition
SCR_SliderComponent.c:223
SCR_SliderComponent::m_fValueOffset
float m_fValueOffset
Definition
SCR_SliderComponent.c:32
SCR_SliderComponent::UpdateValue
float UpdateValue()
Definition
SCR_SliderComponent.c:121
SCR_SliderComponent::m_iDecimalPrecision
int m_iDecimalPrecision
Definition
SCR_SliderComponent.c:44
SCR_SliderComponent::m_bClampValue
bool m_bClampValue
Definition
SCR_SliderComponent.c:38
SCR_SliderComponent::m_fStep
float m_fStep
Definition
SCR_SliderComponent.c:14
SCR_SliderComponent::m_fValueMultiplier
float m_fValueMultiplier
Definition
SCR_SliderComponent.c:26
SCR_SliderComponent::m_wText
TextWidget m_wText
Definition
SCR_SliderComponent.c:49
SCR_SliderComponent::OnValueFinal
void OnValueFinal(Widget w)
Definition
SCR_SliderComponent.c:164
SCR_SliderComponent::m_fShownValueMultiplier
float m_fShownValueMultiplier
Definition
SCR_SliderComponent.c:20
SCR_SliderComponent::m_fValue
float m_fValue
Definition
SCR_SliderComponent.c:5
SCR_SliderComponent::GetShownValueMultiplier
float GetShownValueMultiplier()
Definition
SCR_SliderComponent.c:315
SCR_SliderComponent::m_sFormatText
string m_sFormatText
Definition
SCR_SliderComponent.c:17
SCR_SliderComponent::OnSliderFocus
void OnSliderFocus()
Definition
SCR_SliderComponent.c:178
SCR_SliderComponent::GetSliderComponent
static SCR_SliderComponent GetSliderComponent(string name, Widget parent, bool searchAllChildren=true)
Definition
SCR_SliderComponent.c:323
SCR_SliderComponent::HandlerDeattached
override void HandlerDeattached(Widget w)
Definition
SCR_SliderComponent.c:84
SCR_SliderComponent::m_Handler
ref SCR_EventHandlerComponent m_Handler
Definition
SCR_SliderComponent.c:53
SCR_SliderComponent::GetOnChangedFinal
ScriptInvoker GetOnChangedFinal()
Definition
SCR_SliderComponent.c:209
SCR_SliderComponent::m_fMinValue
float m_fMinValue
Definition
SCR_SliderComponent.c:8
SCR_SliderComponent::SetMin
void SetMin(float min)
Definition
SCR_SliderComponent.c:257
SCR_SliderComponent::SetStep
void SetStep(float step)
Definition
SCR_SliderComponent.c:269
SCR_SliderComponent::m_wSlider
SliderWidget m_wSlider
Definition
SCR_SliderComponent.c:50
SCR_SliderComponent::GetStep
float GetStep()
Definition
SCR_SliderComponent.c:298
SCR_SliderComponent::SetShownValueMultiplier
void SetShownValueMultiplier(float multiplier)
Definition
SCR_SliderComponent.c:309
SCR_SliderComponent::ShowCustomValue
void ShowCustomValue(string value)
Definition
SCR_SliderComponent.c:235
SCR_SliderComponent::HandlerAttached
override void HandlerAttached(Widget w)
Definition
SCR_SliderComponent.c:57
SCR_SliderComponent::GetMax
float GetMax()
Definition
SCR_SliderComponent.c:289
SCR_SliderComponent::SetSliderSettings
void SetSliderSettings(float min, float max, float step, string formatText=string.Empty)
Definition
SCR_SliderComponent.c:244
SCR_SliderComponent::m_fMaxValue
float m_fMaxValue
Definition
SCR_SliderComponent.c:11
SCR_SliderComponent::m_sChangeSound
string m_sChangeSound
Definition
SCR_SliderComponent.c:47
SCR_SliderComponent::RoundValue
float RoundValue(float value, int precision)
Definition
SCR_SliderComponent.c:152
SCR_SliderComponent::m_OnChangedFinal
ref ScriptInvoker m_OnChangedFinal
Definition
SCR_SliderComponent.c:54
SCR_SliderComponent::SetValue
void SetValue(float value)
Definition
SCR_SliderComponent.c:198
SCR_SliderComponent::m_fSecondaryMultiplier
float m_fSecondaryMultiplier
Definition
SCR_SliderComponent.c:29
SCR_SliderComponent::m_fOldValue
float m_fOldValue
Definition
SCR_SliderComponent.c:51
SCR_SliderComponent::GetValue
float GetValue()
Definition
SCR_SliderComponent.c:217
SCR_SliderComponent::GetMin
float GetMin()
Definition
SCR_SliderComponent.c:280
SCR_SliderComponent::OnValueChanged
void OnValueChanged(Widget w)
Definition
SCR_SliderComponent.c:103
SCR_SliderComponent::m_bRoundValue
bool m_bRoundValue
Definition
SCR_SliderComponent.c:41
SCR_SliderComponent::OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition
SCR_SliderComponent.c:93
SCR_SliderComponent::m_fShownSecondaryMultiplier
float m_fShownSecondaryMultiplier
Definition
SCR_SliderComponent.c:23
SCR_SliderComponent::SetMax
void SetMax(float max)
Definition
SCR_SliderComponent.c:263
SCR_SliderComponent::GetFormatText
string GetFormatText()
Definition
SCR_SliderComponent.c:229
SCR_SoundEvent
Definition
SCR_SoundEvent.c:2
SCR_WLibComponentBase::PlaySound
void PlaySound(string sound)
Definition
SCR_WLibComponentBase.c:123
SliderWidget
Definition
SliderWidget.c:13
TextWidget
Definition
TextWidget.c:16
UIWidgets
Definition
attributes.c:40
Widget
Definition
Widget.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
WidgetFlags
WidgetFlags
Widget flags. See enf::Widget::SetFlags().
Definition
WidgetFlags.c:14
ScriptInvoker
ScriptInvokerBase< func > ScriptInvoker
Definition
tools.c:134
scripts
Game
UI
Components
WidgetLibrary
SCR_Slider
SCR_SliderComponent.c
Generated by
1.17.0