Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapWeatherUI.c
Go to the documentation of this file.
2{
3 [Attribute(defvalue: "1", desc: "Wind Speed Precision[m/s]", params: "0.01 inf")]
4 protected float m_fWindSpeedPrecision;
5
6 [Attribute(defvalue: "5", desc: "Wind Direction Precision[°]", params: "1 inf")]
7 protected int m_iWindDirectionPrecision;
8
9 [Attribute(defvalue: "60", desc: "Wind Data Update Cooldown[s]", params: "1 inf")]
10 protected int m_iDataUpdateCooldown;
11
12 [Attribute(defvalue: "40 0 0", desc: "Position offset of the layout from the position of the button[px]", params: "0 inf")]
13 protected vector m_vPositionOffset;
14
15 [Attribute("MapWeatherFrame", desc: "Map Weather root widget name")]
16 protected string m_sMapWeatherFrame;
17
18 protected const ResourceName ICON = "{857DD01860810AE9}UI/Textures/Editor/Attributes/Categories/Attribute_Category_Weather.edds";
19 protected const ResourceName LAYOUT = "{E360A5329459869F}UI/layouts/Menus/DeployMenu/MapWeatherData.layout";
20 protected const string LABEL_DIRECTION = "#AR-MapInfo_WeatherData_WindDirection";
21 protected const string LABEL_SPEED = "#AR-MapInfo_WeatherData_WindSpeed";
22 protected const string WIDGET_NAME_ICON = "StateIcon";
23 protected const string WIDGET_NAME_TITLE = "StateTitle";
24 protected const string WIDGET_NAME_TIME = "Time";
25 protected const string FORMAT_HOUR = "%1:00";
26
27 protected bool m_bVisible;
29 protected float m_fLastWindSpeed;
30 protected float m_fLastWindDirection;
43
44 //------------------------------------------------------------------------------------------------
45 protected void ToggleVisibility(SCR_ButtonBaseComponent button = null)
46 {
48 }
49
50 //------------------------------------------------------------------------------------------------
51 protected void SetVsibilityState(bool state)
52 {
54 return;
55
56 m_bVisible = state;
57 m_ToolMenuEntry.SetActive(m_bVisible);
59
60 // if it is meant to be visible, then reposition the layout so it is next to the button, but not outside of the window
61 if (m_bVisible)
63 }
64
65 //------------------------------------------------------------------------------------------------
67 protected void UpdateLayoutPosition()
68 {
69 if (!m_ToolMenuEntry || !m_ToolMenuEntry.m_ButtonComp)
70 return;
71
72 Widget toolButton = m_ToolMenuEntry.m_ButtonComp.GetRootWidget();
73 if (!toolButton)
74 return;
75
76 WorkspaceWidget workspace = GetGame().GetWorkspace();
77 if (!workspace)
78 return;
79
80 float buttonPosX, buttonPosY, buttonSizeX, buttonSizeY;
81 toolButton.GetScreenPos(buttonPosX, buttonPosY);
82 toolButton.GetScreenSize(buttonSizeX, buttonSizeY);
83
84 FrameSlot.SetPosY(m_wWeatherDataRoot, workspace.DPIUnscale(buttonPosY - buttonSizeY + m_vPositionOffset[1]));
85 }
86
87 //------------------------------------------------------------------------------------------------
88 override void Update(float timeSlice)
89 {
90 if (!m_bVisible)
91 return;
92
93 if (!m_World)
94 return;
95
96#ifdef ENABLE_DIAG
97 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_UI_MAP_FORECAST_COOLDOWN))
98 {
101 return;
102 }
103#endif
104
105 WorldTimestamp currentTS = m_World.GetServerTimestamp();
107 return;
108
109 m_NextWindUpdateCooldown = currentTS.PlusSeconds(m_iDataUpdateCooldown);
111 }
112
113 //------------------------------------------------------------------------------------------------
115 protected void UpdateWindData()
116 {
118 return;
119
120 m_bLastAutomaticWindState = m_WeatherManager.IsAutomatedWindDisabled();
122
123 m_fLastWindSpeed = Math.Round(m_WeatherManager.GetWindSpeed() / m_fWindSpeedPrecision) * m_fWindSpeedPrecision;
124 m_fLastWindDirection = Math.Repeat(Math.Round(m_WeatherManager.GetWindDirection() / m_iWindDirectionPrecision) * m_iWindDirectionPrecision + 180, 360);
127 }
128
129 //------------------------------------------------------------------------------------------------
130 protected void OnWeatherChanged(notnull TimeAndWeatherManagerEntity manager, int currentStateId, int nextStateId, bool transitioning)
131 {
132 if (transitioning)
133 return;
134
136 }
137
138 //------------------------------------------------------------------------------------------------
139 protected void OnWindOverrideDataChanged(notnull TimeAndWeatherManagerEntity manager, bool currentState, float currentSpeed, float currentDirection)
140 {
142 }
143
144 //------------------------------------------------------------------------------------------------
147 {
149 return;
150
151 bool isAutomaticWeatherDisabled = m_WeatherManager.IsWeatherLooping();
152 m_wWeatherOverrideInfo.SetVisible(isAutomaticWeatherDisabled);
153 m_wUpcomingWeatherHolder.SetVisible(!isAutomaticWeatherDisabled);
154
155 WeatherState state = m_WeatherManager.GetCurrentWeatherState();
156 if (!state)
157 return;
158
159 ImageWidget stateIcon = ImageWidget.Cast(m_wCurrentWeatherHolder.FindAnyWidget(WIDGET_NAME_ICON));
160 if (stateIcon)
161 stateIcon.LoadImageTexture(0, state.GetIconPath());
162
163 TextWidget stateTitle = TextWidget.Cast(m_wCurrentWeatherHolder.FindAnyWidget(WIDGET_NAME_TITLE));
164 if (stateTitle)
165 stateTitle.SetText(state.GetLocalizedName());
166
167 if (isAutomaticWeatherDisabled)
168 return;
169
170 BaseWeatherStateTransitionManager transitionMgr = m_WeatherManager.GetTransitionManager();
171 if (!transitionMgr)
172 return;
173
174 state = transitionMgr.GetNextState();
175 if (!state)
176 return;
177
179 if (time)
180 {
181 int currentHour, hour, currentMin, min, sec;
182 m_WeatherManager.GetHoursMinutesSeconds(currentHour, currentMin, sec);
183 m_WeatherManager.TimeToHoursMinutesSeconds(transitionMgr.GetTimeLeftUntilNextState(), hour, min, sec);
184 float roundUp = Math.Round((currentMin + min) / 60);
185 hour = Math.Repeat(currentHour + hour + roundUp, 24);
186 time.SetTextFormat(FORMAT_HOUR, hour.ToString(2));
187 }
188
189 stateIcon = ImageWidget.Cast(m_wUpcomingWeatherHolder.FindAnyWidget(WIDGET_NAME_ICON));
190 if (stateIcon)
191 stateIcon.LoadImageTexture(0, state.GetIconPath());
192
193 stateTitle = TextWidget.Cast(m_wUpcomingWeatherHolder.FindAnyWidget(WIDGET_NAME_TITLE));
194 if (stateTitle)
195 stateTitle.SetText(state.GetLocalizedName());
196 }
197
198 //------------------------------------------------------------------------------------------------
199 override protected void OnMapOpen(MapConfiguration config)
200 {
201 super.OnMapOpen(config);
202
203 bool previousState = m_ToolMenuEntry.IsEntryActive();
204 SetVsibilityState(previousState);
205
206 // delayed as it takes about a frame for the button to find its place, thus imidiate call would position it at 0 0 + offset
207 if (previousState)
208 GetGame().GetCallqueue().CallLater(UpdateLayoutPosition);
209
210 Update(0);
212
213 bool automaticWindState = m_WeatherManager.IsAutomatedWindDisabled();
214 if (automaticWindState || m_bLastAutomaticWindState != automaticWindState)
215 {
217 }
218 else
219 {
222
225 }
226
227 m_WeatherManager.GetOnWindOverrideDataChanged().Insert(OnWindOverrideDataChanged);
228 m_WeatherManager.GetOnWeatherChanged().Insert(OnWeatherChanged);
229
230#ifdef ENABLE_DIAG
231 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_UI_MAP_FORECAST_COOLDOWN, "", "Update map weather report", "Weather");
232#endif
233 }
234
235 //------------------------------------------------------------------------------------------------
236 override protected void OnMapClose(MapConfiguration config)
237 {
238 super.OnMapClose(config);
239
240 m_WeatherManager.GetOnWindOverrideDataChanged().Remove(OnWindOverrideDataChanged);
241 m_WeatherManager.GetOnWeatherChanged().Remove(OnWeatherChanged);
242
243#ifdef ENABLE_DIAG
244 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_UI_MAP_FORECAST_COOLDOWN);
245#endif
246 }
247
248 //------------------------------------------------------------------------------------------------
249 override void Init()
250 {
251 SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
252 if (!toolMenu)
253 return;
254
255 m_World = ChimeraWorld.CastFrom(GetGame().GetWorld());
256 if (!m_World)
257 return;
258
259 m_WeatherManager = m_World.GetTimeAndWeatherManager();
260 if (!m_WeatherManager)
261 return;
262
263 m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry(ICON, string.Empty, 20);
264 m_ToolMenuEntry.m_OnClick.Insert(ToggleVisibility);
265 m_ToolMenuEntry.SetEnabled(true);
266 }
267
268 //------------------------------------------------------------------------------------------------
269 protected bool CreateLayout()
270 {
273 return false;
274
275 m_wWeatherDataRoot = GetGame().GetWorkspace().CreateWidgets(LAYOUT, m_wMapWeatherFrame);
277 return false;
278
279 m_wCurrentWeatherHolder = m_wWeatherDataRoot.FindAnyWidget("Now");
280 m_wUpcomingWeatherHolder = m_wWeatherDataRoot.FindAnyWidget("Upcoming");
281 m_wWeatherOverrideInfo = m_wWeatherDataRoot.FindAnyWidget("WeatherOverrideInfo");
282 m_wWindOverrideInfo = m_wWeatherDataRoot.FindAnyWidget("WindOverrideInfo");
283 m_wCurrentWindDirection = TextWidget.Cast(m_wWeatherDataRoot.FindAnyWidget("Direction"));
284 m_wCurrentWindSpeed = TextWidget.Cast(m_wWeatherDataRoot.FindAnyWidget("Speed"));
285 return true;
286 }
287}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_MapToolMenuUI()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Math.c:13
Base class for any button, regardless its own content.
Map tool menu entry data class.
const ResourceName LAYOUT
void OnWindOverrideDataChanged(notnull TimeAndWeatherManagerEntity manager, bool currentState, float currentSpeed, float currentDirection)
const string LABEL_DIRECTION
TextWidget m_wCurrentWindSpeed
const string WIDGET_NAME_TITLE
void OnMapOpen(MapConfiguration config)
void SetVsibilityState(bool state)
ChimeraWorld m_World
SCR_MapToolEntry m_ToolMenuEntry
void OnMapClose(MapConfiguration config)
const string WIDGET_NAME_TIME
TextWidget m_wCurrentWindDirection
void UpdateWindData()
Updates the information about current wind conditions.
const ResourceName ICON
void OnWeatherChanged(notnull TimeAndWeatherManagerEntity manager, int currentStateId, int nextStateId, bool transitioning)
override void Init()
TimeAndWeatherManagerEntity m_WeatherManager
const string FORMAT_HOUR
Widget m_wUpcomingWeatherHolder
void ToggleVisibility(SCR_ButtonBaseComponent button=null)
void UpdateWeatherData()
Updates the information about current and upcoming weather.
const string WIDGET_NAME_ICON
WorldTimestamp m_NextWindUpdateCooldown
void UpdateLayoutPosition()
Changes the Y position of the layout to be next to the weather button.
const string LABEL_SPEED
override void Update(float timeSlice)
SCR_FieldOfViewSettings Attribute