Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_MapWeatherUI.c
Go to the documentation of this file.
1
class
SCR_MapWeatherUI
:
SCR_MapUIBaseComponent
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
;
28
protected
bool
m_bLastAutomaticWindState
;
29
protected
float
m_fLastWindSpeed
;
30
protected
float
m_fLastWindDirection
;
31
protected
Widget
m_wMapWeatherFrame
;
32
protected
Widget
m_wWeatherDataRoot
;
33
protected
Widget
m_wWindOverrideInfo
;
34
protected
Widget
m_wWeatherOverrideInfo
;
35
protected
Widget
m_wCurrentWeatherHolder
;
36
protected
Widget
m_wUpcomingWeatherHolder
;
37
protected
TextWidget
m_wCurrentWindSpeed
;
38
protected
TextWidget
m_wCurrentWindDirection
;
39
protected
ChimeraWorld
m_World
;
40
protected
WorldTimestamp
m_NextWindUpdateCooldown
;
41
protected
SCR_MapToolEntry
m_ToolMenuEntry
;
42
protected
TimeAndWeatherManagerEntity
m_WeatherManager
;
43
44
//------------------------------------------------------------------------------------------------
45
protected
void
ToggleVisibility
(
SCR_ButtonBaseComponent
button = null)
46
{
47
SetVsibilityState
(!
m_bVisible
);
48
}
49
50
//------------------------------------------------------------------------------------------------
51
protected
void
SetVsibilityState
(
bool
state)
52
{
53
if
(!
m_wWeatherDataRoot
&& !
CreateLayout
())
54
return
;
55
56
m_bVisible
= state;
57
m_ToolMenuEntry
.SetActive(
m_bVisible
);
58
m_wWeatherDataRoot
.SetVisible(
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
)
62
UpdateLayoutPosition
();
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
{
99
UpdateWeatherData
();
100
UpdateWindData
();
101
return
;
102
}
103
#endif
104
105
WorldTimestamp
currentTS =
m_World
.GetServerTimestamp();
106
if
(
m_NextWindUpdateCooldown
&& currentTS.Less(
m_NextWindUpdateCooldown
))
107
return
;
108
109
m_NextWindUpdateCooldown
= currentTS.PlusSeconds(m_iDataUpdateCooldown);
110
UpdateWindData
();
111
}
112
113
//------------------------------------------------------------------------------------------------
115
protected
void
UpdateWindData
()
116
{
117
if
(!
m_wWindOverrideInfo
|| !
m_wCurrentWindSpeed
|| !
m_wCurrentWindDirection
)
118
return
;
119
120
m_bLastAutomaticWindState
=
m_WeatherManager
.IsAutomatedWindDisabled();
121
m_wWindOverrideInfo
.SetVisible(
m_bLastAutomaticWindState
);
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);
125
m_wCurrentWindSpeed
.SetTextFormat(
LABEL_SPEED
,
m_fLastWindSpeed
);
126
m_wCurrentWindDirection
.SetTextFormat(
LABEL_DIRECTION
,
m_fLastWindDirection
);
127
}
128
129
//------------------------------------------------------------------------------------------------
130
protected
void
OnWeatherChanged
(notnull
TimeAndWeatherManagerEntity
manager,
int
currentStateId,
int
nextStateId,
bool
transitioning)
131
{
132
if
(transitioning)
133
return
;
134
135
UpdateWeatherData
();
136
}
137
138
//------------------------------------------------------------------------------------------------
139
protected
void
OnWindOverrideDataChanged
(notnull
TimeAndWeatherManagerEntity
manager,
bool
currentState,
float
currentSpeed,
float
currentDirection)
140
{
141
UpdateWindData
();
142
}
143
144
//------------------------------------------------------------------------------------------------
146
void
UpdateWeatherData
()
147
{
148
if
(!
m_wWeatherOverrideInfo
|| !
m_wCurrentWeatherHolder
|| !
m_wUpcomingWeatherHolder
)
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
178
TextWidget
time =
TextWidget
.Cast(
m_wUpcomingWeatherHolder
.FindAnyWidget(
WIDGET_NAME_TIME
));
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);
211
UpdateWeatherData
();
212
213
bool
automaticWindState =
m_WeatherManager
.IsAutomatedWindDisabled();
214
if
(automaticWindState ||
m_bLastAutomaticWindState
!= automaticWindState)
215
{
216
UpdateWindData
();
217
}
218
else
219
{
220
if
(
m_wCurrentWindSpeed
)
221
m_wCurrentWindSpeed
.SetTextFormat(
LABEL_SPEED
,
m_fLastWindSpeed
);
222
223
if
(
m_wCurrentWindDirection
)
224
m_wCurrentWindDirection
.SetTextFormat(
LABEL_DIRECTION
,
m_fLastWindDirection
);
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
{
271
m_wMapWeatherFrame
=
m_RootWidget
.FindAnyWidget(
m_sMapWeatherFrame
);
272
if
(!
m_wMapWeatherFrame
)
273
return
false
;
274
275
m_wWeatherDataRoot
=
GetGame
().GetWorkspace().CreateWidgets(
LAYOUT
,
m_wMapWeatherFrame
);
276
if
(!
m_wWeatherDataRoot
)
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
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition
DebugMenuID.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition
SCR_MapToolMenuUI.c:484
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
BaseWeatherStateTransitionManager
Definition
BaseWeatherStateTransitionManager.c:8
ChimeraWorld
Definition
ChimeraWorld.c:13
DiagMenu
Diagnostic and developer menu system.
Definition
DiagMenu.c:18
FrameSlot
Definition
FrameSlot.c:13
ImageWidget
Definition
ImageWidget.c:13
MapConfiguration
Definition
MapConfiguration.c:3
Math
Definition
Math.c:13
ResourceName
Definition
ResourceName.c:13
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition
SCR_ButtonBaseComponent.c:7
SCR_MapToolEntry
Map tool menu entry data class.
Definition
SCR_MapToolMenuUI.c:3
SCR_MapUIBaseComponent::SCR_MapUIBaseComponent
void SCR_MapUIBaseComponent()
Definition
SCR_MapUIBaseComponent.c:94
SCR_MapUIBaseComponent::m_MapEntity
SCR_MapEntity m_MapEntity
Definition
SCR_MapUIBaseComponent.c:13
SCR_MapUIBaseComponent::m_RootWidget
Widget m_RootWidget
Definition
SCR_MapUIBaseComponent.c:12
SCR_MapWeatherUI
Definition
SCR_MapWeatherUI.c:2
SCR_MapWeatherUI::m_wWeatherDataRoot
Widget m_wWeatherDataRoot
Definition
SCR_MapWeatherUI.c:32
SCR_MapWeatherUI::m_wWeatherOverrideInfo
Widget m_wWeatherOverrideInfo
Definition
SCR_MapWeatherUI.c:34
SCR_MapWeatherUI::LAYOUT
const ResourceName LAYOUT
Definition
SCR_MapWeatherUI.c:19
SCR_MapWeatherUI::OnWindOverrideDataChanged
void OnWindOverrideDataChanged(notnull TimeAndWeatherManagerEntity manager, bool currentState, float currentSpeed, float currentDirection)
Definition
SCR_MapWeatherUI.c:139
SCR_MapWeatherUI::LABEL_DIRECTION
const string LABEL_DIRECTION
Definition
SCR_MapWeatherUI.c:20
SCR_MapWeatherUI::m_wCurrentWindSpeed
TextWidget m_wCurrentWindSpeed
Definition
SCR_MapWeatherUI.c:37
SCR_MapWeatherUI::WIDGET_NAME_TITLE
const string WIDGET_NAME_TITLE
Definition
SCR_MapWeatherUI.c:23
SCR_MapWeatherUI::OnMapOpen
void OnMapOpen(MapConfiguration config)
Definition
SCR_MapWeatherUI.c:199
SCR_MapWeatherUI::m_sMapWeatherFrame
string m_sMapWeatherFrame
Definition
SCR_MapWeatherUI.c:16
SCR_MapWeatherUI::SetVsibilityState
void SetVsibilityState(bool state)
Definition
SCR_MapWeatherUI.c:51
SCR_MapWeatherUI::m_wWindOverrideInfo
Widget m_wWindOverrideInfo
Definition
SCR_MapWeatherUI.c:33
SCR_MapWeatherUI::CreateLayout
bool CreateLayout()
Definition
SCR_MapWeatherUI.c:269
SCR_MapWeatherUI::m_World
ChimeraWorld m_World
Definition
SCR_MapWeatherUI.c:39
SCR_MapWeatherUI::m_ToolMenuEntry
SCR_MapToolEntry m_ToolMenuEntry
Definition
SCR_MapWeatherUI.c:41
SCR_MapWeatherUI::OnMapClose
void OnMapClose(MapConfiguration config)
Definition
SCR_MapWeatherUI.c:236
SCR_MapWeatherUI::WIDGET_NAME_TIME
const string WIDGET_NAME_TIME
Definition
SCR_MapWeatherUI.c:24
SCR_MapWeatherUI::m_wCurrentWindDirection
TextWidget m_wCurrentWindDirection
Definition
SCR_MapWeatherUI.c:38
SCR_MapWeatherUI::UpdateWindData
void UpdateWindData()
Updates the information about current wind conditions.
Definition
SCR_MapWeatherUI.c:115
SCR_MapWeatherUI::ICON
const ResourceName ICON
Definition
SCR_MapWeatherUI.c:18
SCR_MapWeatherUI::m_bLastAutomaticWindState
bool m_bLastAutomaticWindState
Definition
SCR_MapWeatherUI.c:28
SCR_MapWeatherUI::OnWeatherChanged
void OnWeatherChanged(notnull TimeAndWeatherManagerEntity manager, int currentStateId, int nextStateId, bool transitioning)
Definition
SCR_MapWeatherUI.c:130
SCR_MapWeatherUI::Init
override void Init()
Definition
SCR_MapWeatherUI.c:249
SCR_MapWeatherUI::m_fLastWindSpeed
float m_fLastWindSpeed
Definition
SCR_MapWeatherUI.c:29
SCR_MapWeatherUI::m_WeatherManager
TimeAndWeatherManagerEntity m_WeatherManager
Definition
SCR_MapWeatherUI.c:42
SCR_MapWeatherUI::FORMAT_HOUR
const string FORMAT_HOUR
Definition
SCR_MapWeatherUI.c:25
SCR_MapWeatherUI::m_wCurrentWeatherHolder
Widget m_wCurrentWeatherHolder
Definition
SCR_MapWeatherUI.c:35
SCR_MapWeatherUI::m_wUpcomingWeatherHolder
Widget m_wUpcomingWeatherHolder
Definition
SCR_MapWeatherUI.c:36
SCR_MapWeatherUI::m_fLastWindDirection
float m_fLastWindDirection
Definition
SCR_MapWeatherUI.c:30
SCR_MapWeatherUI::ToggleVisibility
void ToggleVisibility(SCR_ButtonBaseComponent button=null)
Definition
SCR_MapWeatherUI.c:45
SCR_MapWeatherUI::UpdateWeatherData
void UpdateWeatherData()
Updates the information about current and upcoming weather.
Definition
SCR_MapWeatherUI.c:146
SCR_MapWeatherUI::WIDGET_NAME_ICON
const string WIDGET_NAME_ICON
Definition
SCR_MapWeatherUI.c:22
SCR_MapWeatherUI::m_wMapWeatherFrame
Widget m_wMapWeatherFrame
Definition
SCR_MapWeatherUI.c:31
SCR_MapWeatherUI::m_NextWindUpdateCooldown
WorldTimestamp m_NextWindUpdateCooldown
Definition
SCR_MapWeatherUI.c:40
SCR_MapWeatherUI::UpdateLayoutPosition
void UpdateLayoutPosition()
Changes the Y position of the layout to be next to the weather button.
Definition
SCR_MapWeatherUI.c:67
SCR_MapWeatherUI::LABEL_SPEED
const string LABEL_SPEED
Definition
SCR_MapWeatherUI.c:21
SCR_MapWeatherUI::Update
override void Update(float timeSlice)
Definition
SCR_MapWeatherUI.c:88
SCR_MapWeatherUI::m_bVisible
bool m_bVisible
Definition
SCR_MapWeatherUI.c:27
TextWidget
Definition
TextWidget.c:16
TimeAndWeatherManagerEntity
Definition
TimeAndWeatherManagerEntity.c:26
WeatherState
Definition
WeatherState.c:8
Widget
Definition
Widget.c:13
WorkspaceWidget
Definition
WorkspaceWidget.c:16
WorldTimestamp
Definition
WorldTimestamp.c:26
vector
Definition
vector.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
Update
@ Update
Definition
SndComponentCallbacks.c:14
scripts
Game
Map
ComponentsUI
SCR_MapWeatherUI.c
Generated by
1.17.0