Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SessionDurationUIComponent.c
Go to the documentation of this file.
1 
5 {
6  [Attribute("#AR-ValueUnit_Short_Plus", uiwidget: UIWidgets.LocaleEditBox)]
7  protected LocalizedString m_sSessionDurationFormatting;
8 
9  protected TextWidget m_wSessionDurationText;
10 
11  protected SCR_BaseGameMode m_GameMode;
12 
13  //------------------------------------------------------------------------------------------------
14  protected void SetSessionDurationTime()
15  {
16  if (m_GameMode)
17  m_wSessionDurationText.SetTextFormat(m_sSessionDurationFormatting, SCR_FormatHelper.GetTimeFormatting(m_GameMode.GetElapsedTime(), ETimeFormatParam.DAYS));
18  else //~ Fallback if no gamemode
19  {
20  ChimeraWorld world = GetGame().GetWorld();
21  float elapsedMs = world.GetServerTimestamp().DiffMilliseconds(null);
22  m_wSessionDurationText.SetTextFormat(m_sSessionDurationFormatting, SCR_FormatHelper.GetTimeFormatting(elapsedMs * 0.001, ETimeFormatParam.DAYS));
23  }
24  }
25 
26  //======================== ATTACH/DEATTACH HANDLER ========================\\
27  //------------------------------------------------------------------------------------------------
28  override void HandlerAttachedScripted(Widget w)
29  {
31  if (!m_GameMode)
32  {
33  //~ Only show error if replication is running else using replication time is fine
34  if (Replication.IsRunning())
35  Print("'SCR_SessionDurationUIComponent' could not find 'SCR_BaseGameMode' so will show replication time instead which is not synced with players", LogLevel.WARNING);
36  }
37 
38  m_wSessionDurationText = TextWidget.Cast(w);
39  if (!m_wSessionDurationText)
40  {
41  Print("'SCR_SessionDurationUIComponent' needs to be attached to a 'TextWidget'!", LogLevel.ERROR);
42  return;
43  }
44 
45  SetSessionDurationTime();
46 
47  //~ Called every frame to update session duration
48  GetGame().GetCallqueue().CallLater(SetSessionDurationTime, 1000, true);
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  //On Destroy
53  override void HandlerDeattached(Widget w)
54  {
55  if (!m_wSessionDurationText)
56  return;
57 
58  GetGame().GetCallqueue().Remove(SetSessionDurationTime);
59  }
60 };
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
MenuRootSubComponent
Definition: MenuRootSubComponent.c:5
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
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_SessionDurationUIComponent
Definition: SCR_SessionDurationUIComponent.c:4
m_GameMode
protected SCR_BaseGameMode m_GameMode
Definition: SCR_DeployMenuBase.c:111
LocalizedString
Definition: LocalizedString.c:21