Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeatherForecastUIComponent.c
Go to the documentation of this file.
1 class SCR_WeatherForecastUIComponent: ScriptedWidgetComponent
2 {
3  [Attribute("Current_Icon")]
4  protected string m_sCurrentWeatherIconName;
5 
6  [Attribute("Current_Name")]
7  protected string m_sCurrentWeatherTextName;
8 
9  [Attribute("Forecast_Icon")]
10  protected string m_sNextWeatherIconName;
11 
12  [Attribute("Forecast_Title")]
13  protected string m_sNextWeatherTimeName;
14 
15  [Attribute("Forecast_Name")]
16  protected string m_sNextWeatherTextName;
17 
18  [Attribute("GameInfo_Weather_Forecast")]
19  protected string m_sNextWeatherHolderName;
20 
21  [Attribute("#AR-Weather_Forecast_Looping", uiwidget: UIWidgets.LocaleEditBox)]
22  protected LocalizedString m_sLoopingWeatherText;
23 
24  [Attribute("1", "Update freq of weather UI in seconds")]
25  protected float m_fUIUpdateFreq;
26 
27  [Attribute("MISSING NAME", desc: "Text shown if weather State has no weather name assigned")]
28  protected LocalizedString m_sUnknownWeatherName;
29 
30  [Attribute("{4B4B51FACB828BF9}UI/Textures/Tasks/TaskIcons/96/Icon_Task_Unknown.edds", desc: "Icon used when weather is unknown")]
31  protected ResourceName m_sUnknownWeatherIcon;
32 
33  protected bool m_bListeningToUpdate;
34 
35  protected TimeAndWeatherManagerEntity m_TimeAndWeatherEntity;
36  protected WeatherStateTransitionManager m_WeatherStateManager;
37  protected ref array<ref WeatherState> m_WeatherStates = new array<ref WeatherState>;
38 
39  protected ImageWidget m_wCurrentWeatherIcon;
40  protected TextWidget m_wCurrentWeatherText;
41  protected TextWidget m_wNextWeatherText;
42  protected TextWidget m_wNextWeatherTimeText;
43  protected ImageWidget m_wNextWeatherIcon;
44  protected Widget m_wNextWeatherHolder;
45  protected Widget m_wRoot;
46 
47  //~Todo: Update using TimeAndWeather callback once implemented
48  protected void CheckWeatherUpdate()
49  {
50  if (m_WeatherStateManager.IsPreviewingState())
51  return;
52 
53  WeatherState currentWeather = m_WeatherStateManager.GetCurrentState();
54 
55  //~ Get weather name
56  string weatherName = currentWeather.GetLocalizedName();
57  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherName))
58  weatherName = m_sUnknownWeatherName;
59 
60  //~ Get weather Icon
61  string weatherIcon = currentWeather.GetIconPath();
62  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherIcon))
63  weatherIcon = m_sUnknownWeatherIcon;
64 
65  m_wCurrentWeatherText.SetText(weatherName);
66  m_wCurrentWeatherIcon.LoadImageTexture(0, weatherIcon);
67 
68  WeatherState nextWeather = m_WeatherStateManager.GetNextState();
69  if (!nextWeather)
70  {
71  m_wNextWeatherHolder.SetVisible(false);
72  return;
73  }
74  else
75  {
76  m_wNextWeatherHolder.SetVisible(true);
77  }
78 
79 
80  //~ Looping weather or Time progression disabled
81  if (m_TimeAndWeatherEntity.IsWeatherLooping() || !m_TimeAndWeatherEntity.GetIsDayAutoAdvanced())
82  {
83  m_wNextWeatherTimeText.SetText(m_sLoopingWeatherText);
84  }
85  else
86  {
87  float duration = m_WeatherStateManager.GetTimeLeftUntilNextState();
88  float changeTime = duration + m_TimeAndWeatherEntity.GetTimeOfTheDay();
89  while (changeTime >= 24)
90  changeTime -= 24;
91  int nextWeatherHour = Math.Floor(changeTime);
92  int nextWeatherMinutes = (changeTime - nextWeatherHour) * 60;
93 
94  if (nextWeatherMinutes >= 0 && nextWeatherMinutes <= 15)
95  nextWeatherMinutes = 15;
96  else if (nextWeatherMinutes > 15 && nextWeatherMinutes <= 30)
97  nextWeatherMinutes = 30;
98  else if (nextWeatherMinutes > 30 && nextWeatherMinutes <= 45)
99  nextWeatherMinutes = 45;
100  else if (nextWeatherMinutes > 45)
101  {
102  nextWeatherMinutes = 0;
103  nextWeatherHour++;
104 
105  if (nextWeatherHour >= 24)
106  nextWeatherHour -= 24;
107  }
108 
109  m_wNextWeatherTimeText.SetTextFormat(SCR_FormatHelper.GetTimeFormattingHoursMinutes(nextWeatherHour, nextWeatherMinutes));
110  }
111 
112  weatherName = nextWeather.GetLocalizedName();
113  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherName))
114  weatherName = m_sUnknownWeatherName;
115 
116 
117  weatherIcon = nextWeather.GetIconPath();
118  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherIcon))
119  weatherIcon = m_sUnknownWeatherIcon;
120 
121  m_wNextWeatherText.SetText(weatherName);
122  m_wNextWeatherIcon.LoadImageTexture(0, weatherIcon);
123  }
124 
125  protected void ShowWeatherUI(bool show)
126  {
127  m_wRoot.SetVisible(show);
128  }
129 
130 
131  override void HandlerAttached(Widget w)
132  {
133  if (SCR_Global.IsEditMode())
134  return;
135 
136  m_wRoot = w;
137  m_wCurrentWeatherIcon = ImageWidget.Cast(w.FindAnyWidget(m_sCurrentWeatherIconName));
138  m_wCurrentWeatherText = TextWidget.Cast(w.FindAnyWidget(m_sCurrentWeatherTextName));
139 
140  if (!m_wCurrentWeatherIcon || !m_wCurrentWeatherText)
141  {
142  Print("'SCR_WeatherForecastUIComponent' is missing current weather widgets and won't work.", LogLevel.WARNING);
143  return;
144  }
145 
146  m_wNextWeatherIcon = ImageWidget.Cast(w.FindAnyWidget(m_sNextWeatherIconName));
147  m_wNextWeatherText = TextWidget.Cast(w.FindAnyWidget(m_sNextWeatherTextName));
148  m_wNextWeatherTimeText = TextWidget.Cast(w.FindAnyWidget(m_sNextWeatherTimeName));
149 
150  if (!m_wNextWeatherIcon || !m_wNextWeatherText || !m_wNextWeatherTimeText)
151  {
152  Print("'SCR_WeatherForecastUIComponent' is missing next weather widgets and won't work.", LogLevel.WARNING);
153  return;
154  }
155 
156  m_wNextWeatherHolder = w.FindAnyWidget(m_sNextWeatherHolderName);
157 
158  ChimeraWorld world = GetGame().GetWorld();
159  m_TimeAndWeatherEntity = world.GetTimeAndWeatherManager();
160 
161  if (!m_TimeAndWeatherEntity)
162  {
163  ShowWeatherUI(false);
164  return;
165  }
166 
167 
168  m_TimeAndWeatherEntity.GetWeatherStatesList(m_WeatherStates);
169  if (m_WeatherStates.IsEmpty())
170  {
171  ShowWeatherUI(false);
172  return;
173  }
174 
175  m_WeatherStateManager = m_TimeAndWeatherEntity.GetTransitionManager();
176 
177  if (!m_WeatherStateManager)
178  {
179  ShowWeatherUI(false);
180  return;
181  }
182 
183  CheckWeatherUpdate();
184  m_bListeningToUpdate = true;
185  GetGame().GetCallqueue().CallLater(CheckWeatherUpdate, m_fUIUpdateFreq * 1000, true);
186  }
187  override void HandlerDeattached(Widget w)
188  {
189  if (m_bListeningToUpdate)
190  GetGame().GetCallqueue().Remove(CheckWeatherUpdate);
191  }
192 };
WeatherStateTransitionManager
Definition: WeatherStateTransitionManager.c:7
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_WeatherForecastUIComponent
Definition: SCR_WeatherForecastUIComponent.c:1
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_StringHelper
Definition: SCR_StringHelper.c:1
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_Global
Definition: Functions.c:6
LocalizedString
Definition: LocalizedString.c:21