DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CodeLockVisualManager.c
См. документацию.
1// Enhanced light state enum with specific states
3{
4 OFF, // No lights, no battery
5 LOCKED, // Red light solid
6 UNLOCKED, // Green light solid
7 SETTING_MODE, // Green light blinking
8 BRUTE_FORCE_PROTECTION // Red light blinking
9}
10
12{
15
16 // Current visual state tracking
18 private bool m_IsBlinking;
19
20 // State tracking for change detection
21 private float m_LastBatteryPercent;
22 private bool m_LastReversedState;
25 private int m_LastVisibleBars;
26
27 // Dirty flag system
28 private bool m_FullVisualUpdate;
29
30 // Timers for animations
31 private ref Timer m_BlinkTimer;
32 private float m_BlinkTime;
33 private bool m_BlinkPhase; // true = light on, false = light off
34
35 // Animation constants
36 private const float BLINK_INTERVAL = 0.1;
37 private const float BLINK_CYCLE_TIME = 1.0;
38
39 // Animation phase values
40 private const float LIGHT_VISIBLE = 0.0; // Animation phase for visible light
41 private const float LIGHT_HIDDEN = 1.0; // Animation phase for hidden light
42
43 private const string CODELOCK_ANIMATED_FRONT = "CodelockFrontTranslation";
44 private const string CODELOCK_ANIMATED_BACK = "CodelockBackTranslation";
45 private const string CODELOCK_ANIMATED_BACK_R = "CodelockBackRotation";
46 private const string CODELOCK_ANIMATED_R = "CodelockRotation";
47 const string CODELOCK_ANIMATED_ZIP = "CodelockZipHide";
48 const string CODELOCK_ANIMATED_RED_LIGHT = "CodelockRedLightOnHide";
49 const string CODELOCK_ANIMATED_GREEN_LIGHT = "CodelockGreenLightOnHide";
50 const string CODELOCK_ANIMATED_BUTTON_GREEN_LIGHT = "CodelockButtonGreenLightOnHide";
51 const string CODELOCK_ANIMATED_BUTTON_RED_LIGHT = "CodelockButtonRedLightOnHide";
52 const string CODELOCK_ANIMATED_BATTERY_LIGHT = "CodelockBatteryLightOnHide";
53
55 "CodelockBatteryBar1Hide",
56 "CodelockBatteryBar2Hide",
57 "CodelockBatteryBar3Hide",
58 "CodelockBatteryBar4Hide",
59 "CodelockBatteryBar5Hide",
60 "CodelockBatteryBar6Hide"
61 };
62
64 {
65 m_CodeLock = codeLock;
68 m_IsBlinking = false;
69 m_BlinkTime = 0;
70 m_BlinkPhase = false;
71 m_FullVisualUpdate = false;
72
73 // Initialize tracking variables
75 m_LastReversedState = false;
79 }
80
82 {
84 }
85
86 void MarkDirty()
87 {
88 m_FullVisualUpdate = true;
89 }
90
92 {
94 #ifdef CODELOCKCOMPONENT_LOG
95 if (m_CurrentLightState != newLightState)
96 ErrorEx(string.Format("Current light state=%1 | New light state=%2", typename.EnumToString(CodeLockLightState, m_CurrentLightState), typename.EnumToString(CodeLockLightState, newLightState)), ErrorExSeverity.INFO);
97 #endif
98
99 bool lightStateChanged = m_FullVisualUpdate || (newLightState != m_CurrentLightState);
100 bool animationsChanged = m_FullVisualUpdate || HasAnimationsChanged();
101 bool batteryLevelChanged = m_FullVisualUpdate || HasBatteryLevelChanged();
102
103 // Only update if something actually changed or we're marked dirty
104 if (!m_FullVisualUpdate && !lightStateChanged && !animationsChanged && !batteryLevelChanged)
105 {
106 #ifdef CODELOCKCOMPONENT_LOG
107 ErrorEx("No visual changes detected, skipping update of visuals..", ErrorExSeverity.INFO);
108 #endif
109 return;
110 }
111
112 if (lightStateChanged)
113 {
114 SetLightState(newLightState);
115 }
116
117 if (animationsChanged)
118 {
120 }
121
122 if (batteryLevelChanged)
123 {
125 }
126
127 m_FullVisualUpdate = false;
128 }
129
130 // Check if animations need updating
131 protected bool HasAnimationsChanged()
132 {
133 if (!m_CodeLock.HasValidParent())
134 {
135 // Detached state - check if we were previously attached
136 return (m_LastAnimationPhaseFront != 0.0 || m_LastAnimationPhaseBack != 0.0);
137 }
138 else
139 {
140 // Attached state - check for changes
141 bool reversed = m_CodeLock.GetReversedState();
142 if (reversed != m_LastReversedState)
143 return true;
144
145 EntityAI hierarchyParent = m_CodeLock.GetHierarchyRoot();
146 float newFrontPhase = GetAnimationPhaseForFrontPart(hierarchyParent, reversed);
147 float newBackPhase = GetAnimationPhaseForBackPart(hierarchyParent, reversed);
148
149 if (newFrontPhase != m_LastAnimationPhaseFront || newBackPhase != m_LastAnimationPhaseBack)
150 return true;
151 }
152
153 return false;
154 }
155
156 // Check if battery level changed enough to warrant visual update
158 {
159 if (!m_CodeLock.HasValidParent())
160 {
161 if (m_LastVisibleBars != 0)
162 return true;
163 }
164 else
165 {
166 float currentPercent = m_CodeLock.GetBatteryEnergy();
167 int currentBars = CalculateVisibleBars(currentPercent);
168 if (currentBars != m_LastVisibleBars)
169 return true;
170 }
171
172 return false;
173 }
174
175 // Determine what the light state should be based on current conditions
177 {
178 // No battery = everything off
179 if (m_CodeLock.NeedBattery())
180 {
181 float energy = m_CodeLock.GetBatteryEnergy();
182 if (energy <= 0 || !m_CodeLock.HasValidParent())
183 return CodeLockLightState.OFF;
184 }
185
186 if (m_CodeLock.HasValidParent())
187 {
188 // Handle brute force protection
189 if (m_Component.HasBruteForceProtection() || m_Component.ShouldHandleBruteForce())
190 return CodeLockLightState.BRUTE_FORCE_PROTECTION;
191
192 // Check if we're in setting mode
193 CodeLockStage stage = m_Component.GetStage();
194 if (stage == CodeLockStage.SETTING)
195 return CodeLockLightState.SETTING_MODE;
196
197 // If we have a PIN, show lock state
198 if (m_Component.HasPIN())
199 {
200 if (m_Component.IsLocked())
201 return CodeLockLightState.LOCKED;
202 else
203 return CodeLockLightState.UNLOCKED;
204 }
205 }
206
207 // Default state with battery but no PIN
208 return CodeLockLightState.OFF;
209 }
210
211 // Set the light state and handle state transitions
213 {
214 if (m_CurrentLightState == newState)
215 return;
216
217 // Stop any current blinking
218 StopBlinking();
219
220 m_CurrentLightState = newState;
221
222 switch(newState)
223 {
224 case CodeLockLightState.OFF:
225 SetAllLights(LIGHT_HIDDEN); // Red off, Green off
226 break;
227
228 case CodeLockLightState.LOCKED:
229 SetMainLights(LIGHT_VISIBLE, LIGHT_HIDDEN); // Red on, Green off
230 SetButtonLights(LIGHT_HIDDEN, LIGHT_VISIBLE); // Green off, Red on
231 break;
232
233 case CodeLockLightState.UNLOCKED:
235 SetButtonLights(LIGHT_VISIBLE, LIGHT_HIDDEN); // Green on, Red off
236 break;
237
238 case CodeLockLightState.SETTING_MODE:
239 SetMainLights(LIGHT_HIDDEN, LIGHT_HIDDEN); // Red off, Green off
240 SetButtonLights(LIGHT_HIDDEN, LIGHT_HIDDEN); // Both button lights start off (will blink green)
241 StartBlinking(CodeLockLightState.SETTING_MODE);
242 break;
243
244 case CodeLockLightState.BRUTE_FORCE_PROTECTION:
245 SetMainLights(LIGHT_HIDDEN, LIGHT_HIDDEN); // Red off, Green off
246 SetButtonLights(LIGHT_HIDDEN, LIGHT_HIDDEN); // Both button lights start off (will blink red)
247 StartBlinking(CodeLockLightState.BRUTE_FORCE_PROTECTION);
248 break;
249 }
250 }
251
252 // Set animation phases for front light selections
253 protected void SetMainLights(float redPhase, float greenPhase)
254 {
255 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_RED_LIGHT, redPhase);
256 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_GREEN_LIGHT, greenPhase);
257 }
258
259 // Set animation phases for button light selections
260 protected void SetButtonLights(float greenButtonPhase, float redButtonPhase)
261 {
262 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BUTTON_GREEN_LIGHT, greenButtonPhase);
263 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BUTTON_RED_LIGHT, redButtonPhase);
264 }
265
266 protected void SetBatteryLight(float phase)
267 {
268 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BATTERY_LIGHT, phase);
269 }
270
271 // Set all lights to the same phase
272 protected void SetAllLights(float phase)
273 {
274 SetMainLights(phase, phase);
275 SetButtonLights(phase, phase);
276 }
277
278 // Start blinking animation for specific states
279 protected void StartBlinking(CodeLockLightState blinkState)
280 {
281 if (m_IsBlinking)
282 return;
283
284 m_IsBlinking = true;
285 m_BlinkTime = 0;
286 m_BlinkPhase = false;
287
289 m_BlinkTimer.Run(BLINK_INTERVAL, this, "UpdateBlinking", null, true);
290 }
291
292 // Stop blinking animation
293 protected void StopBlinking()
294 {
295 if (m_BlinkTimer)
296 {
297 m_BlinkTimer.Stop();
298 m_BlinkTimer = NULL;
299 }
300
301 m_IsBlinking = false;
302 m_BlinkTime = 0;
303 m_BlinkPhase = false;
304 }
305
306 // Update blinking animation - called by timer
308 {
309 if (!m_IsBlinking)
310 return;
311
313
315 {
317 m_BlinkTime = 0;
318
320 }
321 }
322
323 // Apply the current blink state to the appropriate lights
324 protected void ApplyBlinkState()
325 {
326 float visiblePhase, hiddenPhase;
327
328 // Determine phases for blinking
329 if (m_BlinkPhase)
330 {
331 visiblePhase = LIGHT_VISIBLE;
332 hiddenPhase = LIGHT_HIDDEN;
333 }
334 else
335 {
336 visiblePhase = LIGHT_HIDDEN;
337 hiddenPhase = LIGHT_HIDDEN;
338 }
339
340 switch(m_CurrentLightState)
341 {
342 case CodeLockLightState.SETTING_MODE:
343 {
344 // Blink green main light
345 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_GREEN_LIGHT, visiblePhase);
346
347 // Blink green button light (green on, red off)
348 SetButtonLights(visiblePhase, LIGHT_HIDDEN);
349 break;
350 }
351 case CodeLockLightState.BRUTE_FORCE_PROTECTION:
352 {
353 // Blink red main light
354 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_RED_LIGHT, visiblePhase);
355
356 // Blink red button light (green off, red on)
357 SetButtonLights(LIGHT_HIDDEN, visiblePhase);
358 break;
359 }
360 default:
361 return; // No blinking for this state
362 }
363 }
364
365 // Helper method to set button light to specific color (non-blinking)
366 void SetButtonLightColor(bool isRed)
367 {
368 if (isRed)
369 {
370 SetButtonLights(LIGHT_HIDDEN, LIGHT_VISIBLE); // Green off, Red on
371 }
372 else
373 {
374 SetButtonLights(LIGHT_VISIBLE, LIGHT_HIDDEN); // Green on, Red off
375 }
376 }
377
378 // Helper method to turn off both button lights
383
384 // Update physical animations (position, rotation, etc.)
385 protected void UpdateAnimations()
386 {
387 if (m_CodeLock.HasValidParent())
388 {
389 EntityAI hierarchyParent = m_CodeLock.GetHierarchyRoot();
390 UpdateAttachedAnimations(hierarchyParent);
391 }
392 else
393 {
395 }
396 }
397
398 // Update animations when attached to a structure
399 protected void UpdateAttachedAnimations(EntityAI hierarchyParent)
400 {
401 // Handle rotation
402 bool reversed = m_CodeLock.GetReversedState(); // Assuming this is accessible
403 float rotationPhase;
404 if (reversed)
405 rotationPhase = 180.0;
406 else
407 rotationPhase = 0;
408
409 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_R, rotationPhase);
410
411 // Handle position based on parent type
412 m_LastAnimationPhaseFront = GetAnimationPhaseForFrontPart(hierarchyParent, reversed);
413 m_LastAnimationPhaseBack = GetAnimationPhaseForBackPart(hierarchyParent, reversed);
414
417 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_ZIP, 1.0);
418 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BACK_R, 90.0);
419 }
420
421 protected float GetAnimationPhaseForFrontPart(EntityAI hierarchyParent, bool reversed)
422 {
423 float animationPhase = 0.0;
424 if (hierarchyParent.IsInherited(House))
425 {
426 if (reversed)
427 {
428 animationPhase = 0.50;
429 }
430 }
431
432 return animationPhase;
433 }
434
435 protected float GetAnimationPhaseForBackPart(EntityAI hierarchyParent, bool reversed)
436 {
437 float animationPhase = 0;
438 if (hierarchyParent.IsInherited(House))
439 {
440 if (reversed)
441 {
442 animationPhase = 0.50;
443 }
444 else
445 {
446 animationPhase = 0.60;
447 }
448 }
449 else if (hierarchyParent.IsInherited(BaseBuildingBase))
450 {
451 animationPhase = 0.92;
452 }
453
454 return animationPhase;
455 }
456
457 // Update animations when detached
459 {
462
463 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_FRONT, 0);
464 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BACK, 0);
465 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_ZIP, 0);
466 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_R, 0);
467 m_CodeLock.SetAnimationPhase(CODELOCK_ANIMATED_BACK_R, 0);
468 }
469
470 // Update battery level indicator
471 protected void UpdateBatteryIndicator()
472 {
473 float animationPhase;
474 float energyPercent = m_CodeLock.GetBatteryEnergy();
475 int visibleBars = CalculateVisibleBars(energyPercent);
476
477 if (visibleBars > 0)
478 animationPhase = 0;
479 else
480 animationPhase = 1.0;
481
482 SetBatteryLight(animationPhase);
483
484 for (int i = 0; i < BATTERY_BAR_SELECTIONS.Count(); ++i)
485 {
486 if (i < visibleBars)
487 animationPhase = 0; // visible
488 else
489 animationPhase = 1.0; // hidden
490
491 m_CodeLock.SetAnimationPhase(BATTERY_BAR_SELECTIONS[i], animationPhase);
492 }
493
494 m_LastVisibleBars = visibleBars;
495 m_LastBatteryPercent = energyPercent;
496 }
497
498 // Calculate how many battery bars should be visible
499 protected int CalculateVisibleBars(float batteryPercent)
500 {
501 if (!m_CodeLock.HasValidParent())
502 return 0;
503
504 if (batteryPercent <= 0)
505 return 0;
506
507 const int maxBars = 6;
508 float barsFloat = Math.Ceil((batteryPercent / 100.0) * maxBars);
509 return Math.Max(0, Math.Min(maxBars, barsFloat));
510 }
511
512 // Get current light state (for debugging/external access)
517
518 // Check if currently blinking
520 {
521 return m_IsBlinking;
522 }
523}
class EconomyOutputStrings OFF
void CodeLockComponent(notnull EntityAI parent, int minLockPinLength=MIN_LOCK_PIN_LENGTH)
Определения CodeLockComponent.c:51
CodeLockStage
Определения CodeLockComponent.c:5
const string CODELOCK_ANIMATED_FRONT
Определения CodeLockVisualManager.c:43
const string CODELOCK_ANIMATED_BUTTON_GREEN_LIGHT
Определения CodeLockVisualManager.c:50
void SetMainLights(float redPhase, float greenPhase)
Определения CodeLockVisualManager.c:253
float GetAnimationPhaseForFrontPart(EntityAI hierarchyParent, bool reversed)
Определения CodeLockVisualManager.c:421
CodeLockComponent m_Component
Определения CodeLockVisualManager.c:14
void CodeLockVisualManager(DigitalCodeLock codeLock, CodeLockComponent component)
Определения CodeLockVisualManager.c:63
void SetButtonLightColor(bool isRed)
Определения CodeLockVisualManager.c:366
void UpdateAnimations()
Определения CodeLockVisualManager.c:385
void ApplyBlinkState()
Определения CodeLockVisualManager.c:324
const float BLINK_INTERVAL
Определения CodeLockVisualManager.c:36
bool m_FullVisualUpdate
Определения CodeLockVisualManager.c:28
float GetAnimationPhaseForBackPart(EntityAI hierarchyParent, bool reversed)
Определения CodeLockVisualManager.c:435
enum CodeLockLightState m_CodeLock
bool m_LastReversedState
Определения CodeLockVisualManager.c:22
void UpdateVisuals()
Определения CodeLockVisualManager.c:91
bool HasBatteryLevelChanged()
Определения CodeLockVisualManager.c:157
const string CODELOCK_ANIMATED_R
Определения CodeLockVisualManager.c:46
void StartBlinking(CodeLockLightState blinkState)
Определения CodeLockVisualManager.c:279
ref Timer m_BlinkTimer
Определения CodeLockVisualManager.c:31
void UpdateDetachedAnimations()
Определения CodeLockVisualManager.c:458
float m_BlinkTime
Определения CodeLockVisualManager.c:32
CodeLockLightState
Определения CodeLockVisualManager.c:3
@ BRUTE_FORCE_PROTECTION
Определения CodeLockVisualManager.c:8
@ UNLOCKED
Определения CodeLockVisualManager.c:6
@ LOCKED
Определения CodeLockVisualManager.c:5
@ SETTING_MODE
Определения CodeLockVisualManager.c:7
void StopBlinking()
Определения CodeLockVisualManager.c:293
bool m_IsBlinking
Определения CodeLockVisualManager.c:18
float m_LastAnimationPhaseFront
Определения CodeLockVisualManager.c:23
void SetButtonLights(float greenButtonPhase, float redButtonPhase)
Определения CodeLockVisualManager.c:260
const string CODELOCK_ANIMATED_GREEN_LIGHT
Определения CodeLockVisualManager.c:49
void ~CodeLockVisualManager()
Определения CodeLockVisualManager.c:81
const float LIGHT_HIDDEN
Определения CodeLockVisualManager.c:41
bool HasAnimationsChanged()
Определения CodeLockVisualManager.c:131
const float BLINK_CYCLE_TIME
Определения CodeLockVisualManager.c:37
const string CODELOCK_ANIMATED_ZIP
Определения CodeLockVisualManager.c:47
const string CODELOCK_ANIMATED_BACK_R
Определения CodeLockVisualManager.c:45
const string CODELOCK_ANIMATED_BUTTON_RED_LIGHT
Определения CodeLockVisualManager.c:51
int m_LastVisibleBars
Определения CodeLockVisualManager.c:25
const string CODELOCK_ANIMATED_BACK
Определения CodeLockVisualManager.c:44
bool m_BlinkPhase
Определения CodeLockVisualManager.c:33
void SetBatteryLight(float phase)
Определения CodeLockVisualManager.c:266
float m_LastBatteryPercent
Определения CodeLockVisualManager.c:21
const float LIGHT_VISIBLE
Определения CodeLockVisualManager.c:40
CodeLockLightState m_CurrentLightState
Определения CodeLockVisualManager.c:17
const ref array< string > BATTERY_BAR_SELECTIONS
Определения CodeLockVisualManager.c:54
void UpdateBatteryIndicator()
Определения CodeLockVisualManager.c:471
bool IsBlinking()
Определения CodeLockVisualManager.c:519
int CalculateVisibleBars(float batteryPercent)
Определения CodeLockVisualManager.c:499
const string CODELOCK_ANIMATED_RED_LIGHT
Определения CodeLockVisualManager.c:48
void SetAllLights(float phase)
Определения CodeLockVisualManager.c:272
CodeLockLightState DetermineRequiredLightState()
Определения CodeLockVisualManager.c:176
void UpdateBlinking()
Определения CodeLockVisualManager.c:307
void SetButtonLightsOff()
Определения CodeLockVisualManager.c:379
void UpdateAttachedAnimations(EntityAI hierarchyParent)
Определения CodeLockVisualManager.c:399
float m_LastAnimationPhaseBack
Определения CodeLockVisualManager.c:24
void SetLightState(CodeLockLightState newState)
Определения CodeLockVisualManager.c:212
const string CODELOCK_ANIMATED_BATTERY_LIGHT
Определения CodeLockVisualManager.c:52
void MarkDirty()
Определения CodeLockVisualManager.c:86
CodeLockLightState GetCurrentLightState()
Определения CodeLockVisualManager.c:513
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
Определения Fence.c:2
Определения CodeLock.c:2
Определения CrashBase.c:2
Определения EnMath.c:7
Определения DayZPlayerImplement.c:39
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Min(float x, float y)
Returns smaller of two given values.
static proto float Ceil(float f)
Returns ceil of value.
const int CALL_CATEGORY_SYSTEM
Определения 3_Game/DayZ/tools/tools.c:8