4 protected string m_sCurrentWeatherIconName;
7 protected string m_sCurrentWeatherTextName;
10 protected string m_sNextWeatherIconName;
13 protected string m_sNextWeatherTimeName;
16 protected string m_sNextWeatherTextName;
19 protected string m_sNextWeatherHolderName;
21 [
Attribute(
"#AR-Weather_Forecast_Looping", uiwidget: UIWidgets.LocaleEditBox)]
24 [
Attribute(
"1",
"Update freq of weather UI in seconds")]
25 protected float m_fUIUpdateFreq;
27 [
Attribute(
"MISSING NAME",
desc:
"Text shown if weather State has no weather name assigned")]
30 [
Attribute(
"{4B4B51FACB828BF9}UI/Textures/Tasks/TaskIcons/96/Icon_Task_Unknown.edds",
desc:
"Icon used when weather is unknown")]
31 protected ResourceName m_sUnknownWeatherIcon;
33 protected bool m_bListeningToUpdate;
35 protected TimeAndWeatherManagerEntity m_TimeAndWeatherEntity;
37 protected ref array<ref WeatherState> m_WeatherStates =
new array<ref WeatherState>;
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;
48 protected void CheckWeatherUpdate()
50 if (m_WeatherStateManager.IsPreviewingState())
53 WeatherState currentWeather = m_WeatherStateManager.GetCurrentState();
56 string weatherName = currentWeather.GetLocalizedName();
58 weatherName = m_sUnknownWeatherName;
61 string weatherIcon = currentWeather.GetIconPath();
63 weatherIcon = m_sUnknownWeatherIcon;
65 m_wCurrentWeatherText.SetText(weatherName);
66 m_wCurrentWeatherIcon.LoadImageTexture(0, weatherIcon);
68 WeatherState nextWeather = m_WeatherStateManager.GetNextState();
71 m_wNextWeatherHolder.SetVisible(
false);
76 m_wNextWeatherHolder.SetVisible(
true);
81 if (m_TimeAndWeatherEntity.IsWeatherLooping() || !m_TimeAndWeatherEntity.GetIsDayAutoAdvanced())
83 m_wNextWeatherTimeText.SetText(m_sLoopingWeatherText);
87 float duration = m_WeatherStateManager.GetTimeLeftUntilNextState();
88 float changeTime = duration + m_TimeAndWeatherEntity.GetTimeOfTheDay();
89 while (changeTime >= 24)
91 int nextWeatherHour = Math.Floor(changeTime);
92 int nextWeatherMinutes = (changeTime - nextWeatherHour) * 60;
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)
102 nextWeatherMinutes = 0;
105 if (nextWeatherHour >= 24)
106 nextWeatherHour -= 24;
109 m_wNextWeatherTimeText.SetTextFormat(
SCR_FormatHelper.GetTimeFormattingHoursMinutes(nextWeatherHour, nextWeatherMinutes));
112 weatherName = nextWeather.GetLocalizedName();
114 weatherName = m_sUnknownWeatherName;
117 weatherIcon = nextWeather.GetIconPath();
119 weatherIcon = m_sUnknownWeatherIcon;
121 m_wNextWeatherText.SetText(weatherName);
122 m_wNextWeatherIcon.LoadImageTexture(0, weatherIcon);
125 protected void ShowWeatherUI(
bool show)
131 override void HandlerAttached(Widget w)
137 m_wCurrentWeatherIcon = ImageWidget.Cast(w.FindAnyWidget(m_sCurrentWeatherIconName));
138 m_wCurrentWeatherText = TextWidget.Cast(w.FindAnyWidget(m_sCurrentWeatherTextName));
140 if (!m_wCurrentWeatherIcon || !m_wCurrentWeatherText)
142 Print(
"'SCR_WeatherForecastUIComponent' is missing current weather widgets and won't work.", LogLevel.WARNING);
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));
150 if (!m_wNextWeatherIcon || !m_wNextWeatherText || !m_wNextWeatherTimeText)
152 Print(
"'SCR_WeatherForecastUIComponent' is missing next weather widgets and won't work.", LogLevel.WARNING);
156 m_wNextWeatherHolder = w.FindAnyWidget(m_sNextWeatherHolderName);
159 m_TimeAndWeatherEntity = world.GetTimeAndWeatherManager();
161 if (!m_TimeAndWeatherEntity)
163 ShowWeatherUI(
false);
168 m_TimeAndWeatherEntity.GetWeatherStatesList(m_WeatherStates);
169 if (m_WeatherStates.IsEmpty())
171 ShowWeatherUI(
false);
175 m_WeatherStateManager = m_TimeAndWeatherEntity.GetTransitionManager();
177 if (!m_WeatherStateManager)
179 ShowWeatherUI(
false);
183 CheckWeatherUpdate();
184 m_bListeningToUpdate =
true;
185 GetGame().GetCallqueue().CallLater(CheckWeatherUpdate, m_fUIUpdateFreq * 1000,
true);
187 override void HandlerDeattached(Widget w)
189 if (m_bListeningToUpdate)
190 GetGame().GetCallqueue().Remove(CheckWeatherUpdate);