DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
IngameHudHeatBuffer.c
См. документацию.
1//#define HEATBUFFER_INDICATOR_DEBUG // Uncomment for heat buffer indicator debug logs
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;
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;
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
30 m_Update = true;
31 m_FlashingStage = -1;
32
34 m_FlashingThresholds.Insert(1, 0.002);
35 m_FlashingThresholds.Insert(2, 0.332);
36 m_FlashingThresholds.Insert(3, 0.662);
37 }
38
40 {
41 #ifdef HEATBUFFER_INDICATOR_DEBUG
42 Print("IngameHudHeatBuffer::OnPlayerNegativeCondition");
43 #endif
44
45 if (player == m_Player)
46 m_Update = false;
47 }
48
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 {
107 }
108 else
109 {
110 #ifdef HEATBUFFER_INDICATOR_DEBUG
111 Print("HEAT BUFFER - DYNAMIC MAX REACHED - DONT CHANGE DIRECTION");
112 #endif
114 }
115 }
116 else if (heatBufferDiff < 0)
117 {
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
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
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
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 // Initialize the effect if it's not already active
261 if (!m_IsActive)
262 {
263 m_EffectDuration = duration;
264 m_EffectTime = 0;
265 m_FadeIn = true;
266 m_IsActive = true;
267 }
268
269 // Update the effect time
270 m_EffectTime += timeslice;
271
272 // Calculate the time fraction
273 float timeFraction = m_EffectTime / m_EffectDuration;
274
275 // Calculate opacity
276 if (m_FadeIn)
277 {
278 opacity = Math.Lerp(0.0, 1.0, timeFraction);
279 if (timeFraction >= 1.0)
280 {
281 m_FadeIn = false;
282 m_EffectTime = 0; // Reset for fade-out
283 }
284 }
285 else
286 {
287 opacity = Math.Lerp(1.0, 0.0, timeFraction);
288 if (timeFraction >= 1.0)
289 {
290 m_FadeIn = true;
291 m_EffectTime = 0; // Reset for fade-in
292 }
293 }
294
295 // Clamp the opacity to ensure it's within the valid range
296 opacity = Math.Clamp(opacity, 0.0, 1.0);
297
298 // Set the widget's alpha (opacity)
299 hbw.SetAlpha(opacity);
300
301 // Debug print statements
302 #ifdef HEATBUFFER_INDICATOR_DEBUG
303 Print("HEAT BUFFER - EFFECT - Opacity=" + opacity + " | Time Fraction=" + timeFraction + " | FadeIn=" + m_FadeIn + " | Effect time=" + m_EffectTime + " | Effect duration=" + m_EffectDuration);
304 #endif
305 }
306}
map
Определения ControlsXboxNew.c:4
const int NUMBER_OF_STAGES
Определения HeatBuffer.c:3
const float STAGE_THRESHOLDS[NUMBER_OF_STAGES]
Определения HeatBuffer.c:4
Определения HeatBuffer.c:2
void UpdateEffect(Widget hbw, float duration, float timeslice)
Определения IngameHudHeatBuffer.c:251
float m_FlashingTime
Определения IngameHudHeatBuffer.c:15
int m_PreviousDirection
Определения IngameHudHeatBuffer.c:9
int m_FlashingStage
Определения IngameHudHeatBuffer.c:16
void Update(float timeslice)
Определения IngameHudHeatBuffer.c:64
float m_EffectTime
Определения IngameHudHeatBuffer.c:12
void OnPlayerConditionChanged(PlayerBase player)
Определения IngameHudHeatBuffer.c:49
PlayerBase m_Player
Определения IngameHudHeatBuffer.c:11
int m_CurrentDirection
Определения IngameHudHeatBuffer.c:8
bool m_Update
Определения IngameHudHeatBuffer.c:10
bool m_FadeIn
Определения IngameHudHeatBuffer.c:14
void SetBaseAlpha(Widget hbw, float valuePercent, float stageThreshold)
Определения IngameHudHeatBuffer.c:239
Widget m_Root
Определения IngameHudHeatBuffer.c:4
bool CanUpdate()
Определения IngameHudHeatBuffer.c:59
ref map< int, float > m_FlashingThresholds
Определения IngameHudHeatBuffer.c:17
void OnPlayerNegativeCondition(PlayerBase player)
Определения IngameHudHeatBuffer.c:39
void IngameHudHeatBuffer(Widget root, notnull PlayerBase player)
Определения IngameHudHeatBuffer.c:19
float m_EffectDuration
Определения IngameHudHeatBuffer.c:13
bool m_IsActive
Определения IngameHudHeatBuffer.c:7
float m_CurrentValue
Определения IngameHudHeatBuffer.c:6
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
Определения EnWidgets.c:190
proto void Print(void var)
Prints content of variable to console/log.
static proto float Floor(float f)
Returns floor of value.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
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'.
int ARGB(int a, int r, int g, int b)
Определения proto.c:322