Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_IngameClockUIComponent.c
Go to the documentation of this file.
3 {
4  [Attribute("Time", desc: "Clock needs at least the Time icon, time multiplier or Time Text to function")]
5  protected string m_sTimeTextName;
6 
7  [Attribute("DayTime_Icon", desc: "Clock needs at least the Time icon, time multiplier or Time Text to function")]
8  protected string m_sTimeIconName;
9 
10  [Attribute("Time_Multiplier", desc: "Clock needs at least the Time icon, time multiplier or Time Text to function")]
11  protected string m_sTimeMultiplierName;
12 
13  [Attribute("#AR-ValueUnit_Short_Multiplier", uiwidget: UIWidgets.LocaleEditBox)]
14  protected string m_sTimeMultiplierFormat;
15 
16  [Attribute("#AR-Weather_Forecast_NoTimeProgression", uiwidget: UIWidgets.LocaleEditBox)]
17  protected string m_sNoTimeProgression;
18 
19  [Attribute("1", desc: "Time until the UI will update in seconds")]
20  protected float m_fUpdateFreq;
21 
22  [Attribute("1", desc: "If true will hide the time multiplier if one (and assigned)")]
23  protected bool m_bHideTimeMultiplierIfOne;
24 
25  [Attribute(desc: "If the current time of day is in this Phase show moonphase instead of daytimeIcon", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EDayTimeEnums))]
26  protected ref array<EDayTimeEnums> m_aShowMoonphaseAtDayTimes;
27 
28  //~ References
29  protected TextWidget m_TimeText;
30  protected ImageWidget m_TimeIcon;
31  protected TextWidget m_TimeMultiplier;
32  protected TimeAndWeatherManagerEntity m_TimeAndWeatherManagerEntity;
33 
34  //======================== CLOCK UPDATE ========================\\
35 
36  //------------------------------------------------------------------------------------------------
37  protected void UpdateIngameClock()
38  {
39  //Get time
40  if (m_TimeText)
41  {
42  int hour, minute, sec;
43  m_TimeAndWeatherManagerEntity.GetHoursMinutesSeconds(hour, minute, sec);
44  m_TimeText.SetTextFormat(SCR_FormatHelper.GetTimeFormattingHoursMinutes(hour, minute));
45  }
46 
47  if (m_TimeIcon)
48  {
49  SCR_UIInfo dayTimeUIInfo;
50  EDayTimeEnums dayTimePhase = m_TimeAndWeatherManagerEntity.GetCurrentDayTimeUIInfoAndPhase(dayTimeUIInfo);
51 
52  if (m_aShowMoonphaseAtDayTimes.Contains(dayTimePhase))
53  {
54  SCR_MoonPhaseUIInfo moonPhase = m_TimeAndWeatherManagerEntity.GetCurrentMoonPhaseInfoForDate();
55  m_TimeIcon.SetRotation(moonPhase.GetMoonphaseImageRotation());
56  moonPhase.SetIconTo(m_TimeIcon);
57  }
58  else
59  {
60  m_TimeIcon.SetRotation(0);
61  dayTimeUIInfo.SetIconTo(m_TimeIcon);
62  }
63  }
64 
65  if (m_TimeMultiplier)
66  {
67  if (m_TimeAndWeatherManagerEntity.GetIsDayAutoAdvanced())
68  {
69  float timeMultiplier = 86400 / m_TimeAndWeatherManagerEntity.GetDayDuration();
70  int TimeMultiplierInt = timeMultiplier;
71 
72  bool visible = !(m_bHideTimeMultiplierIfOne && (TimeMultiplierInt == 1 && (timeMultiplier - TimeMultiplierInt) < 0.1));
73  m_TimeMultiplier.SetVisible(visible);
74 
75  if (visible)
76  {
77  if ((timeMultiplier - TimeMultiplierInt) != 0)
78  m_TimeMultiplier.SetTextFormat(m_sTimeMultiplierFormat, timeMultiplier.ToString(-1, 1));
79  else
80  m_TimeMultiplier.SetTextFormat(m_sTimeMultiplierFormat, TimeMultiplierInt);
81  }
82  }
83  else
84  {
85  m_TimeMultiplier.SetText(m_sNoTimeProgression);
86  m_TimeMultiplier.SetVisible(true);
87  }
88  }
89 
90  }
91 
92  //======================== ATTACH/DEATTACH HANDLER ========================\\
93 
94  //------------------------------------------------------------------------------------------------
95  //On Init
96  override void HandlerAttachedScripted(Widget w)
97  {
98  if (SCR_Global.IsEditMode())
99  return;
100 
101  m_TimeText = TextWidget.Cast(w.FindAnyWidget(m_sTimeTextName));
102  m_TimeIcon = ImageWidget.Cast(w.FindAnyWidget(m_sTimeIconName));
103  m_TimeMultiplier = TextWidget.Cast(w.FindAnyWidget(m_sTimeMultiplierName));
104 
105  if (!m_TimeText && !m_TimeIcon && !m_TimeMultiplier)
106  {
107  Print("'SCR_IngameClockUIComponent' is has no time time widgets and therefore won't function", LogLevel.ERROR);
108  return;
109  }
110 
111  ChimeraWorld world = GetGame().GetWorld();
112  m_TimeAndWeatherManagerEntity = world.GetTimeAndWeatherManager();
113  if (!m_TimeAndWeatherManagerEntity)
114  {
115  Print("'SCR_IngameClockUIComponent' could not find the TimeAndWeatherManager", LogLevel.ERROR);
116  return;
117  }
118 
119  UpdateIngameClock();
120  GetGame().GetCallqueue().CallLater(UpdateIngameClock, m_fUpdateFreq * 1000, true);
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  //On Destroy
125  override void HandlerDeattached(Widget w)
126  {
127  if (m_TimeAndWeatherManagerEntity)
128  GetGame().GetCallqueue().Remove(UpdateIngameClock);
129 
130  }
131 }
ChimeraWorld
Definition: ChimeraWorld.c:12
MenuRootSubComponent
Definition: MenuRootSubComponent.c:5
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_IngameClockUIComponent
Gets the Ingame time and displays it on a UI text element.
Definition: SCR_IngameClockUIComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_MoonPhaseUIInfo
Definition: SCR_MoonPhaseUIInfo.c:2
SCR_Global
Definition: Functions.c:6