Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapCampaignUI.c
Go to the documentation of this file.
3typedef ScriptInvokerBase<BaseHovered> BaseHoveredInvoker;
4
5//------------------------------------------------------------------------------
7{
8 [Attribute("{E48F14D6D3C54BE5}UI/layouts/Campaign/BaseElement.layout", params: "layout")]
10
11 [Attribute("{94F1E2223D7E0588}UI/layouts/Campaign/ServiceHint.layout", params: "layout")]
13
14 [Attribute("{FD71287E68006A26}UI/layouts/Campaign/CampaignPlayerMapIndicator.layout", params: "layout")]
16
17 protected static const int TASK_ICON_Y_OFFSET = 10;
18
23
24 //------------------------------------------------------------------------------
25 void InitMobileAssembly(string factionKey, bool deployed)
26 {
28 {
29 m_wMobileAssembly.SetVisible(deployed);
30 return;
31 }
32
33 FactionManager fm = GetGame().GetFactionManager();
34 if (!fm)
35 return;
36
37 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(fm.GetFactionByKey(factionKey));
38 if (!faction)
39 return;
40
41 SCR_CampaignFaction playerFaction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
42 if (faction != playerFaction)
43 return;
44
45 SCR_CampaignMobileAssemblyStandaloneComponent assembly = faction.GetMobileAssembly();
46 if (!assembly)
47 return;
48
49 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sBaseElement, m_wIconsContainer);
50 if (!w)
51 return;
52
54
56 if (!handler)
57 return;
58
59 handler.SetParent(this);
60 handler.InitMobile(assembly);
61 m_mIcons.Set(w, handler);
62
63 FrameSlot.SetSizeToContent(w, true);
64 FrameSlot.SetAlignment(w, 0.5, 0.5);
65 }
66
67 //------------------------------------------------------------------------------
68 protected void InitBases()
69 {
71 array<SCR_MilitaryBaseComponent> bases = {};
72 baseManager.GetBases(bases);
73 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
74
75 if (!faction)
76 return;
77
79
80 for (int i = 0, count = bases.Count(); i < count; ++i)
81 {
83
84 if (!base || !base.IsInitialized())
85 continue;
86
87 // Don't display enemy HQs and established bases which are out of radio range
88 if (base.GetFaction() != faction && (base.IsHQ() || (base.GetBuiltByPlayers() && !base.IsHQRadioTrafficPossible(faction))))
89 continue;
90
91 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sBaseElement, m_wIconsContainer);
93
94 if (!handler)
95 return;
96
97 handler.SetParent(this);
98 handler.InitBase(base);
99 m_mIcons.Set(w, handler);
100 base.SetBaseUI(handler);
101 base.UpdateCaptureUI();
102
103 FrameSlot.SetSizeToContent(w, true);
104 FrameSlot.SetAlignment(w, 0.5, 0.5);
105 }
106
107 if (faction)
108 {
109 string factionKey = faction.GetFactionKey();
110 InitMobileAssembly(factionKey, faction.GetMobileAssembly() != null);
111 }
112
113 UpdateIcons();
114
115 if (m_OnBasesInited)
116 m_OnBasesInited.Invoke();
117 }
118
119 //------------------------------------------------------------------------------------------------
121 override void UpdateIconPosition(Widget widget, SCR_MapUIElement icon, float x, float y)
122 {
123 SCR_TaskMapUIComponent taskComponent = SCR_TaskMapUIComponent.Cast(icon);
124
125 if (taskComponent)
126 {
127 SCR_CampaignMilitaryBaseTaskEntity task = SCR_CampaignMilitaryBaseTaskEntity.Cast(taskComponent.GetTask());
128
129 if (task)
130 {
131 SCR_CampaignMilitaryBaseComponent base = task.GetMilitaryBase();
132
133 if (base)
134 {
135 SCR_CampaignMapUIBase baseIcon = base.GetMapUI();
136
137 if (baseIcon)
138 {
139 FrameSlot.SetPos(widget, x + (baseIcon.GetBaseIconSize() * 0.5), y + TASK_ICON_Y_OFFSET);
140 return;
141 }
142 }
143 }
144 }
145
146 super.UpdateIconPosition(widget, icon, x, y);
147 }
148
149 //------------------------------------------------------------------------------------------------
150 protected override void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
151 {
152 if (!m_bIsDeployMap && spawnPoint.GetVisibleInDeployMapOnly())
153 return;
154
155 SCR_GameModeCampaign gameMode = SCR_GameModeCampaign.GetInstance();
156
157 if (!gameMode)
158 return;
159
160 if (spawnPoint.Type() != SCR_CampaignSpawnPointGroup)
161 {
162 IEntity owner = spawnPoint.GetParent();
163
164 // Mobile HQ icon is already shown
165 SCR_CampaignMobileAssemblyStandaloneComponent westMHQ = gameMode.GetFactionByEnum(SCR_ECampaignFaction.BLUFOR).GetMobileAssembly();
166 SCR_CampaignMobileAssemblyStandaloneComponent eastMHQ = gameMode.GetFactionByEnum(SCR_ECampaignFaction.OPFOR).GetMobileAssembly();
167
168 if ((westMHQ && westMHQ.GetOwner() == spawnPoint) || (eastMHQ && eastMHQ.GetOwner() == spawnPoint))
169 return;
170
171 super.ShowSpawnPoint(spawnPoint); // when spawn point is placed by game master, use default spawn point visualization
172 return;
173 }
174
175 // todo: hotfix for icon duplicates in conflict, figure out a proper solution :wink:
176
177 if (spawnPoint.Type() == SCR_SpawnPoint || spawnPoint.Type() == SCR_CampaignSpawnPointGroup)
178 return;
179
180 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPointElement, m_wIconsContainer);
181 SCR_MapUISpawnPoint handler = SCR_MapUISpawnPoint.Cast(w.FindHandler(SCR_MapUISpawnPoint));
182 if (!handler)
183 return;
184
185 handler.Init(spawnPoint);
186 handler.SetParent(this);
187 m_mIcons.Set(w, handler);
188
189 FrameSlot.SetSizeToContent(w, true);
190 FrameSlot.SetAlignment(w, 0.5, 0.5);
191 }
192
193 //------------------------------------------------------------------------------------------------
195 {
196 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
197
198 if (!comp)
199 return;
200
201 if (!comp.CanShowPlayerSpawn())
202 return;
203
204 comp.SetMapCampaignUI(this);
205
206 vector playerLocation = comp.GetPlayerSpawnPos();
207
208 Widget indicator = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPositionHint, m_wIconsContainer);
209
211
212 if (!highlightHandler)
213 return;
214
215 m_mIcons.Insert(indicator, highlightHandler);
216
217 highlightHandler.SetParent(this);
218 highlightHandler.SetPos(playerLocation);
219
220 FrameSlot.SetPosX(indicator, playerLocation[0]);
221 FrameSlot.SetPosY(indicator, playerLocation[1]);
222 FrameSlot.SetSizeToContent(indicator, true);
223 FrameSlot.SetAlignment(indicator, 0.5, 0.5);
224
225 //Called only after spawn, to center map and zoom to player position.
226 if (!comp.WasMapOpened())
227 {
228 m_MapEntity.ZoomPanSmooth(1.5,playerLocation[0],playerLocation[2]);
229 comp.SetMapOpened(true);
230 }
231
232 // Set image from ImageSet
233 // TODO: check for good const usage
234 const ResourceName imageSet = "{5E8F77F38C2B9B9F}UI/Imagesets/MilitarySymbol/ICO.imageset";
235 ImageWidget image = ImageWidget.Cast(indicator.FindAnyWidget("Image"));
236 if(image)
237 {
238 image.LoadImageFromSet(0, imageSet, "PlayerSpawnHint");
239 image.SetColor(Color.FromInt(Color.ORANGE));
240 }
241
242 //Sets time to spawn icon
243 RichTextWidget timeWidget = RichTextWidget.Cast(indicator.FindAnyWidget("TimeString"));
244 TimeContainer timeContainer = comp.GetSpawnTime();
245 if (timeContainer)
246 {
247 string hours = timeContainer.m_iHours.ToString();
248 string minutes = timeContainer.m_iMinutes.ToString();
249
250 if (timeContainer.m_iHours < 10)
251 hours = "0" + hours;
252
253 if (timeContainer.m_iMinutes < 10)
254 minutes = "0" + minutes;
255
256 timeWidget.SetTextFormat("%1:%2",hours, minutes);
257 }
258
259 HideSpawnPositionHint(m_MapEntity.GetLayerIndex());
260 m_MapEntity.GetOnLayerChanged().Insert(HideSpawnPositionHint);
261 }
262
263 //------------------------------------------------------------------------------------------------
266 {
267 SCR_CampaignMapUIPlayerHighlight highlightHandler;
268 foreach (Widget w, SCR_MapUIElement handler: m_mIcons)
269 {
270 highlightHandler = SCR_CampaignMapUIPlayerHighlight.Cast(handler);
271 if(highlightHandler)
272 {
273 w.RemoveFromHierarchy();
274 m_mIcons.Remove(w);
275 break;
276 }
277 }
278 }
279
280 //------------------------------------------------------------------------------------------------
281 protected void HideSpawnPositionHint(int layer)
282 {
283 SCR_CampaignMapUIPlayerHighlight highlightHandler;
284 foreach (Widget w, SCR_MapUIElement handler: m_mIcons)
285 {
286 highlightHandler = SCR_CampaignMapUIPlayerHighlight.Cast(handler);
287 if(highlightHandler)
288 {
289 if(layer > 1)
290 {
291 w.SetVisible(false);
292 return;
293 }
294 w.SetVisible(true);
295 }
296 }
297 }
298
299 //------------------------------------------------------------------------------------------------
301 int GetBases(out notnull array<SCR_CampaignMapUIBase> bases)
302 {
303 bases.Clear();
304 int count;
305 foreach (Widget w, SCR_MapUIElement e : m_mIcons)
306 {
308 if (!base)
309 continue;
310
311 bases.Insert(base);
312 count++;
313 }
314
315 return count;
316 }
317
318 //------------------------------------------------------------------------------------------------
322 {
323 if (m_HoveredBase == base)
324 return;
325
327 if (m_OnBaseHovered)
328 m_OnBaseHovered.Invoke(base);
329 }
330
331 //------------------------------------------------------------------------------------------------
340
341 //------------------------------------------------------------------------------------------------
350
351 //------------------------------------------------------------------------------------------------
352 protected override void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
353 {
354 if (spawnPoint.GetFactionKey() == m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey())
355 {
356 AddSpawnPoint(spawnPoint);
357 }
358 else
359 {
360 if (spawnPoint.Type() != SCR_CampaignSpawnPointGroup) // when changing faction of gm placed spawn points, we want to remove them from the map
361 RemoveSpawnPoint(spawnPoint);
362 }
363 }
364
365 //------------------------------------------------------------------------------------------------
366 void OnMapZoom(float pixelPerUnit)
367 {
368 UpdateIcons();
369 }
370
371 //------------------------------------------------------------------------------------------------
372 override void OnMapOpen(MapConfiguration config)
373 {
374 super.OnMapOpen(config);
375
376 Widget serviceHint = GetGame().GetWorkspace().CreateWidgets(m_sServiceHint, SCR_MapEntity.GetMapInstance().GetMapMenuRoot());
377
378 if (serviceHint)
379 {
380 FrameSlot.SetSizeToContent(serviceHint, true);
381 serviceHint.SetName("ServiceHintRoot");
382 serviceHint.SetVisible(false);
383 }
384
385 SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
386
387 if (comp)
388 comp.SetMapCampaignUI(this);
389
390 InitBases();
392
395 }
396
397 //------------------------------------------------------------------------------------------------
398 override void OnMapClose(MapConfiguration config)
399 {
400 super.OnMapClose(config);
401
404
405 delete m_wMobileAssembly;
406
407 foreach (Widget w, SCR_MapUIElement i : m_mIcons)
408 {
409 w.RemoveFromHierarchy();
410 delete w;
411 }
412
413 m_mIcons.Clear();
414 m_MapEntity.GetOnLayerChanged().Remove(HideSpawnPositionHint);
415 }
416
417 //------------------------------------------------------------------------------------------------
419 {
420 delete m_wMobileAssembly;
421 foreach (Widget w, SCR_MapUIElement i : m_mIcons)
422 {
423 delete w;
424 }
425 }
426};
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
func BaseHovered
ScriptInvokerBase< BaseHovered > BaseHoveredInvoker
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
void TimeContainer(int hours=0, int minutes=0, int seconds=0)
Definition Color.c:13
proto external IEntity GetParent()
SCR_CampaignMobileAssemblyStandaloneComponent GetMobileAssembly()
void InitMobile(SCR_CampaignMobileAssemblyStandaloneComponent assembly)
void InitBase(SCR_CampaignMilitaryBaseComponent base)
override void OnMapClose(MapConfiguration config)
ref ScriptInvokerVoid m_OnBasesInited
ref BaseHoveredInvoker m_OnBaseHovered
override void UpdateIconPosition(Widget widget, SCR_MapUIElement icon, float x, float y)
Offset task icon so it doesn't overlap with base icon.
BaseHoveredInvoker GetOnBaseHovered()
void SetHoveredBase(SCR_CampaignMilitaryBaseComponent base)
int GetBases(out notnull array< SCR_CampaignMapUIBase > bases)
Get all bases elements.
ScriptInvokerVoid GetOnBasesInited()
ResourceName m_sServiceHint
override void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
ResourceName m_sSpawnPositionHint
void InitMobileAssembly(string factionKey, bool deployed)
void HideSpawnPositionHint(int layer)
override void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
static const int TASK_ICON_Y_OFFSET
void OnMapZoom(float pixelPerUnit)
override void OnMapOpen(MapConfiguration config)
ResourceName m_sBaseElement
void RemoveSpawnPositionHint()
Called to hide Spawn Position hint if player is killed (or his entity disappear for some reason).
SCR_CampaignMilitaryBaseComponent m_HoveredBase
Widget GetMapMenuRoot()
Get map menu root widget.
static ScriptInvokerBase< ScriptInvokerFloat2Bool > GetOnMapPan()
Get on map pan invoker.
static ScriptInvokerFloat GetOnMapZoom()
Get on map zoom invoker.
static SCR_MapEntity GetMapInstance()
Get map entity instance.
SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
void OnMapPan(float panX, float panY, bool adjustedPan)
ref map< Widget, SCR_MapUIElement > m_mIcons
void RemoveSpawnPoint(SCR_SpawnPoint spawnPoint)
void AddSpawnPoint(SCR_SpawnPoint spawnPoint)
void Init(notnull SCR_SpawnPoint spawnPoint)
int GetBases(notnull out array< SCR_MilitaryBaseComponent > bases)
static SCR_MilitaryBaseSystem GetInstance()
Spawn point entity defines positions on which players can possibly spawn.
string GetFactionKey()
SCR_FieldOfViewSettings Attribute