Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ServerRestartTimerUIComponent.c
Go to the documentation of this file.
2{
3 [Attribute("#AR-Endscreen_RestartTimer_Format-UC", desc: "Restart timer format %1 is the time")]
5
6 [Attribute(desc: "Widget name of restart timer text. Leave empty to take root as the TextWidget")]
7 protected string m_sRestartTimerName;
8
9 [Attribute("1", desc: "Countdown sfx will play if true")]
10 protected bool m_bEnableCountDownSfx;
11
12 [Attribute("1", desc: "Start timer on init, note that it will be hidden if the game has not ended or it is not set up correctly")]
13 protected bool m_bStartOnInit;
14
15 //~ Timer values
16 protected float m_fAutoReloadDelay = -1;
19
20 //~ References
23
25 protected const int UPDATE_TIME = 100;
26
27 //------------------------------------------------------------------------------------------------
29 bool IsValid()
30 {
31 if (!m_wRestartTimer)
32 Init();
33
34 return m_fAutoReloadDelay > 0;
35 }
36
37 //------------------------------------------------------------------------------------------------
38 protected void Init()
39 {
40 if (!m_sRestartTimerName.IsEmpty())
42 else
44
45 if (!m_wRestartTimer)
46 return;
47
49 if (!gameMode)
50 return;
51
52 m_World = GetGame().GetWorld();
53 if (!m_World)
54 return;
55
58 }
59
60 //------------------------------------------------------------------------------------------------
63 void StartTimer(bool checkIfValid = true)
64 {
65 if (checkIfValid && !IsValid())
66 return;
67
69 GetGame().GetCallqueue().CallLater(UpdateTimer, UPDATE_TIME, true);
70 }
71
72 //------------------------------------------------------------------------------------------------
74 void StopTimer()
75 {
76 if (m_fAutoReloadDelay <= 0)
77 return;
78
79 GetGame().GetCallqueue().Remove(UpdateTimer);
80 }
81
82 //------------------------------------------------------------------------------------------------
83 protected void UpdateTimer()
84 {
85 if (!m_World || !m_wRestartTimer || !m_wRoot.IsVisible())
86 return;
87
88 //~ Call function which knows everythime the time changes a second with current restart time left
89 OnTimeUpdate(Math.Clamp(m_fAutoReloadDelay - ((m_World.GetLocalTimestamp().DiffMilliseconds(m_GameEndTimeStamp)) * 0.001), 0, float.MAX));
90 }
91
92 //------------------------------------------------------------------------------------------------
93 protected void OnTimeUpdate(float currentRestartTimer)
94 {
95 //~ Value did not change
96 if ((int)currentRestartTimer == m_iPreviousRestartTime)
97 return;
98
99 //~ Set current timer as previous timer
100 m_iPreviousRestartTime = currentRestartTimer;
101
102 //~ Update the timer widget
103 string timerText = string.Format("<color rgba='%1'>%2</color>", UIColors.FormatColor(GUIColors.ENABLED), SCR_FormatHelper.GetTimeFormatting(currentRestartTimer, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS));
104 m_wRestartTimer.SetTextFormat(m_sRestartTimerFormat, timerText);
105
106 //~ Countdown SFX
108 {
109 if ((int)currentRestartTimer > 0)
110 {
111 SCR_UISoundEntity.SetSignalValueStr("countdownValue", currentRestartTimer);
112 SCR_UISoundEntity.SetSignalValueStr("maxCountdownValue", m_fAutoReloadDelay);
113 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RESPAWN_COUNTDOWN);
114 }
115 else
116 {
117 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RESPAWN_COUNTDOWN_END);
118 }
119 }
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override void HandlerAttached(Widget w)
124 {
125 super.HandlerAttached(w);
126
128 return;
129
130 Init();
131
132 if (!IsValid())
133 w.SetVisible(false);
134 else if (m_bStartOnInit)
135 StartTimer(false);
136 }
137
138 //------------------------------------------------------------------------------------------------
139 override void HandlerDeattached(Widget w)
140 {
141 super.HandlerDeattached(w);
142
143 if (m_fAutoReloadDelay <= 0)
144 return;
145
146 GetGame().GetCallqueue().Remove(UpdateTimer);
147 }
148}
ETimeFormatParam
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
WorldTimestamp GetGameEndTimeStamp()
static bool IsEditMode()
Definition Functions.c:1566
bool IsValid()
return If the restart timer is set up correctly
const int UPDATE_TIME
Refresh time of timer (in milliseconds).
SCR_FieldOfViewSettings Attribute