Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
ingamehudheatbuffer.c
Go to the documentation of this file.
1
//#define HEATBUFFER_INDICATOR_DEBUG // Uncomment for heat buffer indicator debug logs
2
class
IngameHudHeatBuffer
3
{
4
protected
Widget
m_Root
;
5
6
protected
float
m_CurrentValue
;
7
protected
bool
m_IsActive
;
8
protected
int
m_CurrentDirection
;
// -1 = none | 0 = decreasing | 1 = increasing
9
protected
int
m_PreviousDirection
;
// -1 = none | 0 = decreasing | 1 = increasing
10
protected
bool
m_Update
;
11
protected
PlayerBase
m_Player
;
12
protected
float
m_EffectTime
;
13
protected
float
m_EffectDuration
;
14
protected
bool
m_FadeIn
;
15
protected
float
m_FlashingTime
;
16
protected
int
m_FlashingStage
;
17
protected
ref
map<int, float>
m_FlashingThresholds
;
18
19
void
IngameHudHeatBuffer
(
Widget
root, notnull
PlayerBase
player)
20
{
21
m_Root
= root;
22
m_Player
= player;
23
24
player.GetOnDeathStart().Insert(
OnPlayerNegativeCondition
);
25
player.GetOnUnconsciousStart().Insert(
OnPlayerNegativeCondition
);
26
player.GetOnUnconsciousStop().Insert(
OnPlayerConditionChanged
);
27
28
m_CurrentDirection
= -1;
29
m_PreviousDirection
= -1;
30
m_Update
=
true
;
31
m_FlashingStage
= -1;
32
33
m_FlashingThresholds
=
new
map<int, float>
;
34
m_FlashingThresholds
.Insert(1, 0.002);
35
m_FlashingThresholds
.Insert(2, 0.332);
36
m_FlashingThresholds
.Insert(3, 0.662);
37
}
38
39
void
OnPlayerNegativeCondition
(
PlayerBase
player)
40
{
41
#ifdef HEATBUFFER_INDICATOR_DEBUG
42
Print
(
"IngameHudHeatBuffer::OnPlayerNegativeCondition"
);
43
#endif
44
45
if
(player ==
m_Player
)
46
m_Update
=
false
;
47
}
48
49
void
OnPlayerConditionChanged
(
PlayerBase
player)
50
{
51
#ifdef HEATBUFFER_INDICATOR_DEBUG
52
Print
(
"IngameHudHeatBuffer::OnPlayerConditionChanged"
);
53
#endif
54
55
if
(player ==
m_Player
)
56
m_Update
=
true
;
57
}
58
59
bool
CanUpdate
()
60
{
61
return
m_Player
&&
m_Update
;
62
}
63
64
void
Update
(
float
timeslice)
65
{
66
int
heatBufferStage =
m_Player
.GetHeatBufferStage();
67
float
heatBufferVal =
m_Player
.GetStatHeatBuffer().Get();
68
float
heatBufferDynMax =
m_Player
.GetHeatBufferDynamicMax();
69
float
heatBufferPercent = heatBufferVal /
m_Player
.GetStatHeatBuffer().GetMax();
70
float
heatBufferDiff = heatBufferVal -
m_CurrentValue
;
71
m_CurrentValue
= heatBufferVal;
72
73
#ifdef HEATBUFFER_INDICATOR_DEBUG
74
Print
(
"-----------------------------------------------------------------------"
);
75
Print
(
"Buff stage="
+ heatBufferStage);
76
Print
(
"Buff value="
+ heatBufferVal);
77
Print
(
"Buff percent="
+ heatBufferPercent);
78
Print
(
"Buff dynamic max="
+ heatBufferDynMax);
79
Print
(
"Effect active="
+
m_IsActive
);
80
Print
(
"Last buff value="
+
m_CurrentValue
);
81
Print
(
"Buff differance="
+ heatBufferDiff);
82
Print
(
"Prev Heat buffer direction="
+
m_PreviousDirection
);
83
Print
(
"Flashing time="
+
m_FlashingTime
);
84
Print
(
"Flashing stage="
+
m_FlashingStage
);
85
#endif
86
87
for
(
int
i = 1; i <
HeatBufferMdfr
.
NUMBER_OF_STAGES
; ++i)
88
{
89
Widget
hbw =
m_Root
.FindAnyWidget(
"HeatBuffer"
+ i);
90
if
(!hbw)
91
continue
;
92
93
float
stageThreshold =
HeatBufferMdfr
.
STAGE_THRESHOLDS
[i];
94
#ifdef HEATBUFFER_INDICATOR_DEBUG
95
Print
(
"Stage treshold="
+ stageThreshold);
96
#endif
97
98
// Determine heat buffer direction.
99
// When heat buffer percentage value is higher the the heat buffer dynamic max value we prevent increasing for the indactor logic.
100
// Heat buffer Dynamic max value determines the max value the character can currently reach with his current heat insolation
101
if
(heatBufferDiff > 0)
102
{
103
// If heat buffer percentage value is below or at current heat buffer dynamic max range value the direction cant change
104
if
(heatBufferPercent < heatBufferDynMax)
105
{
106
m_CurrentDirection
= 1;
107
}
108
else
109
{
110
#ifdef HEATBUFFER_INDICATOR_DEBUG
111
Print
(
"HEAT BUFFER - DYNAMIC MAX REACHED - DONT CHANGE DIRECTION"
);
112
#endif
113
m_CurrentDirection
= -1;
114
}
115
}
116
else
if
(heatBufferDiff < 0)
117
{
118
m_CurrentDirection
= 0;
119
}
120
121
#ifdef HEATBUFFER_INDICATOR_DEBUG
122
Print
(
"Heat buffer direction="
+
m_CurrentDirection
);
123
#endif
124
125
// Hide visibility of flashing stages
126
if
(heatBufferStage < i && m_FlashingStage != i || m_FlashingStage == i && m_FlashingTime >= 2.9)
127
{
128
if
(
m_FlashingStage
== i)
129
{
130
m_IsActive
=
false
;
131
m_FlashingTime
= 0;
132
m_FlashingStage
= -1;
133
}
134
135
hbw.SetAlpha(0);
136
hbw.Show(
false
);
137
}
138
139
// Handle widget visibility and alpha based on stage and buffer percent
140
if
(heatBufferStage >= i)
141
{
142
hbw.Show(
true
);
143
144
if
(heatBufferPercent < stageThreshold)
145
{
146
if
(
m_CurrentDirection
== 1)
147
{
148
#ifdef HEATBUFFER_INDICATOR_DEBUG
149
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - INCREASING"
);
150
hbw.SetColor(
ARGB
(hbw.GetAlpha() * 255, 220, 220, 0));
// COLOR SET ON INDICATOR IS ONLY HERE FOR DEBUG TESTING FOR NOW
151
#endif
152
153
SetBaseAlpha
(hbw, heatBufferPercent, stageThreshold);
154
155
if
(
m_PreviousDirection
== 0 &&
m_IsActive
)
156
{
157
m_IsActive
=
false
;
158
m_FlashingTime
= 0;
159
m_FlashingStage
= -1;
160
}
161
162
UpdateEffect
(hbw, 2.0, timeslice);
163
}
164
else
if
(
m_CurrentDirection
== 0)
165
{
166
#ifdef HEATBUFFER_IND ICATOR_DEBUG
167
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - DECREASING"
);
168
#endif
169
170
SetBaseAlpha
(hbw, heatBufferPercent, stageThreshold);
171
172
if
(
m_PreviousDirection
== 1 &&
m_IsActive
)
173
{
174
m_IsActive
=
false
;
175
}
176
177
float
flashingThreshold =
m_FlashingThresholds
.Get(i);
178
if
(heatBufferDynMax < 0.5)
179
{
180
flashingThreshold = flashingThreshold + 0.002;
181
}
182
183
#ifdef HEATBUFFER_INDICATOR_DEBUG
184
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - DECREASING - Flashing threshold="
+ flashingThreshold);
185
hbw.SetColor(
ARGB
(hbw.GetAlpha() * 255, 0, 206, 209));
// COLOR SET ON INDICATOR IS ONLY HERE FOR DEBUG TESTING FOR NOW
186
#endif
187
188
if
(heatBufferPercent <= flashingThreshold)
189
{
190
#ifdef HEATBUFFER_INDICATOR_DEBUG
191
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - FLASHING"
);
192
#endif
193
194
#ifdef HEATBUFFER_INDICATOR_DEBUG
195
hbw.SetColor(
ARGB
(hbw.GetAlpha() * 255, 255, 0, 0));
// COLOR SET ON INDICATOR IS ONLY HERE FOR DEBUG TESTING FOR NOW
196
#endif
197
198
UpdateEffect
(hbw, 0.25, timeslice);
199
200
m_FlashingTime
+= timeslice;
201
if
(
m_FlashingTime
>= 2.9)
202
{
203
m_IsActive
=
false
;
204
m_FlashingTime
= 0;
205
m_FlashingStage
= -1;
206
hbw.SetAlpha(0);
207
hbw.Show(
false
);
208
}
209
}
210
}
211
else
if
(
m_CurrentDirection
== -1)
212
{
213
#ifdef HEATBUFFER_INDICATOR_DEBUG
214
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - STAL"
);
215
#endif
216
217
SetBaseAlpha
(hbw, heatBufferPercent, stageThreshold);
218
}
219
}
220
else
221
{
222
#ifdef HEATBUFFER_INDICATOR_DEBUG
223
Print
(
"HEAT BUFFER - STAGE "
+ i +
" - MAXED"
);
224
#endif
225
226
hbw.SetAlpha(1.0);
227
#ifdef HEATBUFFER_INDICATOR_DEBUG
228
hbw.SetColor(
ARGB
(hbw.GetAlpha() * 255, 220, 220, 220));
// COLOR SET ON INDICATOR IS ONLY HERE FOR DEBUG TESTING FOR NOW
229
#endif
230
}
231
}
232
}
233
234
if
(
m_PreviousDirection
!=
m_CurrentDirection
)
235
m_PreviousDirection
=
m_CurrentDirection
;
236
}
237
238
// Function that calculates and sets the base alpha value for the current heat buffer widget depending on the given heat buffer percentage value and stage threshold
239
void
SetBaseAlpha
(
Widget
hbw,
float
valuePercent,
float
stageThreshold)
240
{
241
float
baseAlpha =
Math
.
Lerp
(0.05, 1.00, (valuePercent / stageThreshold));
242
baseAlpha =
Math
.
Floor
(baseAlpha * 100) / 100;
243
244
#ifdef HEATBUFFER_INDICATOR_DEBUG
245
Print
(
"HEAT BUFFER - Set base alpha="
+ baseAlpha +
" | Widget="
+ hbw.GetName());
246
#endif
247
248
hbw.SetAlpha(baseAlpha);
// Set the current alpha to the base alpha
249
}
250
251
void
UpdateEffect
(
Widget
hbw,
float
duration,
float
timeslice)
252
{
253
#ifdef HEATBUFFER_INDICATOR_DEBUG
254
Print
(
"HEAT BUFFER - EFFECT - Widget="
+ hbw.GetName());
255
#endif
256
257
float
baseAlpha = hbw.GetAlpha();
258
float
opacity;
259
260
m_EffectDuration
= duration;
261
262
// Initialize the effect if it's not already active
263
if
(!
m_IsActive
)
264
{
265
m_EffectTime
= 0;
266
m_FadeIn
=
true
;
267
m_IsActive
=
true
;
268
}
269
270
// Update the effect time
271
m_EffectTime
+= timeslice;
272
273
// Calculate the time fraction
274
float
timeFraction =
m_EffectTime
/
m_EffectDuration
;
275
276
// Calculate opacity
277
if
(
m_FadeIn
)
278
{
279
opacity =
Math
.
Lerp
(0.0, 1.0, timeFraction);
280
if
(timeFraction >= 1.0)
281
{
282
m_FadeIn
=
false
;
283
m_EffectTime
= 0;
// Reset for fade-out
284
}
285
}
286
else
287
{
288
opacity =
Math
.
Lerp
(1.0, 0.0, timeFraction);
289
if
(timeFraction >= 1.0)
290
{
291
m_FadeIn
=
true
;
292
m_EffectTime
= 0;
// Reset for fade-in
293
}
294
}
295
296
// Clamp the opacity to ensure it's within the valid range
297
opacity =
Math
.
Clamp
(opacity, 0.0, 1.0);
298
299
// Set the widget's alpha (opacity)
300
hbw.SetAlpha(opacity);
301
302
// Debug print statements
303
#ifdef HEATBUFFER_INDICATOR_DEBUG
304
Print
(
"HEAT BUFFER - EFFECT - Opacity="
+ opacity +
" | Time Fraction="
+ timeFraction +
" | FadeIn="
+
m_FadeIn
+
" | Effect time="
+
m_EffectTime
+
" | Effect duration="
+
m_EffectDuration
);
305
#endif
306
}
307
}
HeatBufferMdfr
Definition
heatbuffer.c:2
HeatBufferMdfr::STAGE_THRESHOLDS
const float STAGE_THRESHOLDS[NUMBER_OF_STAGES]
Definition
heatbuffer.c:4
HeatBufferMdfr::NUMBER_OF_STAGES
const int NUMBER_OF_STAGES
Definition
heatbuffer.c:3
IngameHudHeatBuffer::m_Root
Widget m_Root
Definition
ingamehudheatbuffer.c:4
IngameHudHeatBuffer::m_FlashingThresholds
ref map< int, float > m_FlashingThresholds
Definition
ingamehudheatbuffer.c:17
IngameHudHeatBuffer::IngameHudHeatBuffer
void IngameHudHeatBuffer(Widget root, notnull PlayerBase player)
Definition
ingamehudheatbuffer.c:19
IngameHudHeatBuffer::OnPlayerNegativeCondition
void OnPlayerNegativeCondition(PlayerBase player)
Definition
ingamehudheatbuffer.c:39
IngameHudHeatBuffer::Update
void Update(float timeslice)
Definition
ingamehudheatbuffer.c:64
IngameHudHeatBuffer::m_EffectTime
float m_EffectTime
Definition
ingamehudheatbuffer.c:12
IngameHudHeatBuffer::m_Player
PlayerBase m_Player
Definition
ingamehudheatbuffer.c:11
IngameHudHeatBuffer::m_PreviousDirection
int m_PreviousDirection
Definition
ingamehudheatbuffer.c:9
IngameHudHeatBuffer::m_FlashingStage
int m_FlashingStage
Definition
ingamehudheatbuffer.c:16
IngameHudHeatBuffer::SetBaseAlpha
void SetBaseAlpha(Widget hbw, float valuePercent, float stageThreshold)
Definition
ingamehudheatbuffer.c:239
IngameHudHeatBuffer::m_FadeIn
bool m_FadeIn
Definition
ingamehudheatbuffer.c:14
IngameHudHeatBuffer::m_IsActive
bool m_IsActive
Definition
ingamehudheatbuffer.c:7
IngameHudHeatBuffer::m_EffectDuration
float m_EffectDuration
Definition
ingamehudheatbuffer.c:13
IngameHudHeatBuffer::UpdateEffect
void UpdateEffect(Widget hbw, float duration, float timeslice)
Definition
ingamehudheatbuffer.c:251
IngameHudHeatBuffer::OnPlayerConditionChanged
void OnPlayerConditionChanged(PlayerBase player)
Definition
ingamehudheatbuffer.c:49
IngameHudHeatBuffer::m_FlashingTime
float m_FlashingTime
Definition
ingamehudheatbuffer.c:15
IngameHudHeatBuffer::m_CurrentDirection
int m_CurrentDirection
Definition
ingamehudheatbuffer.c:8
IngameHudHeatBuffer::CanUpdate
bool CanUpdate()
Definition
ingamehudheatbuffer.c:59
IngameHudHeatBuffer::m_CurrentValue
float m_CurrentValue
Definition
ingamehudheatbuffer.c:6
IngameHudHeatBuffer::m_Update
bool m_Update
Definition
ingamehudheatbuffer.c:10
Math
Definition
enmath.c:7
PlayerBase
Definition
playerbaseclient.c:2
Widget
Definition
enwidgets.c:190
map
Definition
cachedequipmentstorage.c:4
Print
proto void Print(void var)
Prints content of variable to console/log.
Math::Clamp
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
Math::Lerp
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
Math::Floor
static proto float Floor(float f)
Returns floor of value.
ARGB
int ARGB(int a, int r, int g, int b)
Definition
proto.c:322
Games
Dayz
scripts
5_mission
gui
ingamehudheatbuffer.c
Generated by
1.17.0