Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
4  protected LocalizedString m_sRestartTimerFormat;
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;
17  protected WorldTimestamp m_GameEndTimeStamp = null;
18  protected int m_iPreviousRestartTime;
19 
20  //~ References
21  protected ChimeraWorld m_World;
22  protected TextWidget m_wRestartTimer;
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())
41  m_wRestartTimer = TextWidget.Cast(m_wRoot.FindAnyWidget(m_sRestartTimerName));
42  else
43  m_wRestartTimer = TextWidget.Cast(m_wRoot);
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 
56  m_fAutoReloadDelay = gameMode.GetAutoReloadDelay();
57  m_GameEndTimeStamp = gameMode.GetGameEndTimeStamp();
58  }
59 
60  //------------------------------------------------------------------------------------------------
63  void StartTimer(bool checkIfValid = true)
64  {
65  if (checkIfValid && !IsValid())
66  return;
67 
68  UpdateTimer();
69  GetGame().GetCallqueue().CallLater(UpdateTimer, UPDATE_TIME, true);
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  protected void UpdateTimer()
74  {
75  if (!m_World || !m_wRestartTimer)
76  return;
77 
78  //~ Call function which knows everythime the time changes a second with current restart time left
79  OnTimeUpdate(Math.Clamp(m_fAutoReloadDelay - ((m_World.GetLocalTimestamp().DiffMilliseconds(m_GameEndTimeStamp)) * 0.001), 0, float.MAX));
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  protected void OnTimeUpdate(float currentRestartTimer)
84  {
85  //~ Value did not change
86  if ((int)currentRestartTimer == m_iPreviousRestartTime)
87  return;
88 
89  //~ Set current timer as previous timer
90  m_iPreviousRestartTime = currentRestartTimer;
91 
92  //~ Hide leading 0 of seconds if less than 1 minute
93  ETimeFormatParam hideLeadingZero;
94  if (currentRestartTimer < 60)
95  hideLeadingZero = ETimeFormatParam.SECONDS;
96 
97  //~ Update the timer widget
98  m_wRestartTimer.SetTextFormat(m_sRestartTimerFormat, SCR_FormatHelper.GetTimeFormatting(currentRestartTimer, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES, hideLeadingZero));
99 
100  //~ Countdown SFX
101  if (m_bEnableCountDownSfx)
102  {
103  if ((int)currentRestartTimer > 0)
104  {
105  SCR_UISoundEntity.SetSignalValueStr("countdownValue", currentRestartTimer);
106  SCR_UISoundEntity.SetSignalValueStr("maxCountdownValue", m_fAutoReloadDelay);
107  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RESPAWN_COUNTDOWN);
108  }
109  else
110  {
111  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_RESPAWN_COUNTDOWN_END);
112  }
113  }
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override void HandlerAttached(Widget w)
118  {
119  super.HandlerAttached(w);
120 
121  if (SCR_Global.IsEditMode())
122  return;
123 
124  Init();
125 
126  if (!IsValid())
127  w.SetVisible(false);
128  else if (m_bStartOnInit)
129  StartTimer(false);
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  override void HandlerDeattached(Widget w)
134  {
135  super.HandlerDeattached(w);
136 
137  if (m_fAutoReloadDelay <= 0)
138  return;
139 
140  GetGame().GetCallqueue().Remove(UpdateTimer);
141  }
142 }
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
Attribute
typedef Attribute
Post-process effect of scripted camera.
ETimeFormatParam
ETimeFormatParam
Definition: ETimeFormatParam.c:4
SCR_ServerRestartTimerUIComponent
Definition: SCR_ServerRestartTimerUIComponent.c:1
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
SCR_Global
Definition: Functions.c:6
UPDATE_TIME
const protected float UPDATE_TIME
Definition: SCR_HelicopterSoundComponent.c:18
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
LocalizedString
Definition: LocalizedString.c:21