Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapUIElementContainer.c
Go to the documentation of this file.
2{
3 [Attribute("UIIconsContainer")]
4 protected string m_sIconsContainer;
5
7
8 [Attribute("{E78DE3FD19654C1B}UI/layouts/Campaign/SpawnPointElement.layout", params: "layout")]
10
11 [Attribute("{8CA518E4D3AE9F28}UI/layouts/Task/TaskMap.layout", params: "layout")]
13
14 [Attribute("{C013EB43E812F9C1}UI/layouts/Menus/DeployMenu/WarningHintTemp.layout")]
16
18
19 [Attribute("0")]
20 protected bool m_bShowSpawnPointsHint;
21
22 [Attribute("1")]
23 protected bool m_bShowSpawnPoints;
24
25 [Attribute("1")]
26 protected bool m_bShowTasks;
27
28 [Attribute("1", desc: "Show all task types")]
30
31 [Attribute("", UIWidgets.Auto, "Show only task typenames, which is in the list, only if m_bShowAllTaskType is false")]
32 protected ref array<string> m_aAllowedTaskTypenames;
33
34 protected bool m_bIsEditor; // Map opened in editor with gamemaster rights (!limited)
35 protected bool m_bIsDeployMap;
36
38
40 protected SCR_PlayerControllerGroupComponent m_PlyGroupComp;
42
44
47
48 //------------------------------------------------------------------------------------------------
49 override void Init()
50 {
52 m_bIsEditor = SCR_EditorManagerEntity.IsOpenedInstance(false);
53 }
54
55 //------------------------------------------------------------------------------------------------
56 protected void AddSpawnPoint(SCR_SpawnPoint spawnPoint)
57 {
58 Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
60 return;
61
62 if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
63 {
64 ShowSpawnPoint(spawnPoint);
66 }
67 }
68
69 //------------------------------------------------------------------------------------------------
70 protected void RemoveSpawnPoint(SCR_SpawnPoint spawnPoint)
71 {
72 RplId pointId = spawnPoint.GetRplId();
73 HideSpawnPoint(pointId);
75 }
76
77 //------------------------------------------------------------------------------------------------
78 protected void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
79 {
80 if (spawnPoint.GetFactionKey() == m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey())
81 AddSpawnPoint(spawnPoint);
82 else
83 RemoveSpawnPoint(spawnPoint);
84 }
85
86 //------------------------------------------------------------------------------------------------
87 protected void UpdateSpawnPointName(RplId id, string name)
88 {
89 foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
90 {
91 if (icon && icon.GetSpawnPointId() == id)
92 {
93 icon.SetName(name);
94 break;
95 }
96 }
97 }
98
99 //------------------------------------------------------------------------------------------------
100 protected void HideSpawnPoint(RplId spawnPointId)
101 {
102 foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
103 {
104 if (icon && icon.GetSpawnPointId() == spawnPointId)
105 {
106 m_mIcons.Remove(w);
107 w.RemoveFromHierarchy();
108 }
109 }
110 }
111
112 //------------------------------------------------------------------------------------------------
113 protected void OnPlayerFactionResponse(SCR_PlayerFactionAffiliationComponent component, int factionIndex, bool response)
114 {
115 if (response)
116 {
118
121
122 if (m_bShowTasks)
124 }
125 }
126
127 //------------------------------------------------------------------------------------------------
128 override void OnMapOpen(MapConfiguration config)
129 {
130 PlayerController pc = GetGame().GetPlayerController();
131 if (pc)
132 {
135 m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Insert(OnPlayerFactionResponse);
136
137 m_PlyGroupComp = SCR_PlayerControllerGroupComponent.Cast(pc.FindComponent(SCR_PlayerControllerGroupComponent));
138 if (m_PlyGroupComp)
139 m_PlyGroupComp.GetOnGroupChanged().Insert(OnPlayerGroupChanged);
140 }
141
142 SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Insert(OnSpawnPointFactionChange);
143 SCR_SpawnPoint.Event_SpawnPointAdded.Insert(AddSpawnPoint);
144 SCR_SpawnPoint.Event_SpawnPointRemoved.Insert(RemoveSpawnPoint);
145
146 m_TaskSystem = SCR_TaskSystem.GetInstance();
147 if (m_TaskSystem)
148 {
149 m_TaskSystem.GetOnTaskAdded().Insert(OnTaskAdded);
150 m_TaskSystem.GetOnTaskRemoved().Insert(OnTaskRemoved);
151 }
152
153 m_bIsDeployMap = (config.MapEntityMode == EMapEntityMode.SPAWNSCREEN);
154
156 m_wIconsContainer.SetVisible(true);
157
158 Widget child = m_wIconsContainer.GetChildren();
159 while (child)
160 {
161 Widget sibling = child.GetSibling();
162 delete child;
163 child = sibling;
164 }
165
168
169 if (m_bShowTasks)
171
172 m_MapEntity.GetOnMapPan().Insert(OnMapPan);
174 }
175
176 //------------------------------------------------------------------------------------------------
177 override void OnMapClose(MapConfiguration config)
178 {
180 m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Remove(OnPlayerFactionResponse);
181
182 if (m_PlyGroupComp)
183 m_PlyGroupComp.GetOnGroupChanged().Remove(OnPlayerGroupChanged);
184
185 SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Remove(OnSpawnPointFactionChange);
186 SCR_SpawnPoint.Event_SpawnPointAdded.Remove(AddSpawnPoint);
187 SCR_SpawnPoint.Event_SpawnPointRemoved.Remove(RemoveSpawnPoint);
188
189 if (m_TaskSystem)
190 {
191 m_TaskSystem.GetOnTaskAdded().Remove(OnTaskAdded);
192 m_TaskSystem.GetOnTaskRemoved().Remove(OnTaskRemoved);
193 }
194
195 m_MapEntity.GetOnMapPan().Remove(OnMapPan);
197
198 foreach (Widget w, SCR_MapUIElement e : m_mIcons)
199 {
200 if (!w)
201 continue;
202 w.RemoveFromHierarchy();
203 }
204
205 m_mIcons.Clear();
206 }
207
208 //------------------------------------------------------------------------------------------------
212 void OnMapPan(float panX, float panY, bool adjustedPan)
213 {
214 UpdateIcons();
215 }
216
217 //------------------------------------------------------------------------------------------------
218 protected void UpdateIcons()
219 {
220 WorkspaceWidget workspace = GetGame().GetWorkspace();
221 foreach (Widget widget, SCR_MapUIElement icon : m_mIcons)
222 {
223 if (!icon || !widget)
224 continue;
225
226 vector pos = icon.GetPos();
227 float x, y;
228 m_MapEntity.WorldToScreen(pos[0], pos[2], x, y, true);
229
230 x = GetGame().GetWorkspace().DPIUnscale(x);
231 y = GetGame().GetWorkspace().DPIUnscale(y);
232
234 {
235 if (!m_wWarningWidget)
236 m_wWarningWidget = GetGame().GetWorkspace().CreateWidgets(m_sWarningWidget, m_wIconsContainer);
237
238 // just a hint indicating icons outside of the view
239 float screenWidth = workspace.GetWidth();
240 float screenHeight = workspace.GetHeight();
241 float screenWUnscaled = workspace.DPIUnscale(screenWidth);
242 float screenHUnscaled = workspace.DPIUnscale(screenHeight);
243 float ctverecWidth, ctverecHeight;
244 m_wWarningWidget.GetScreenSize(ctverecWidth, ctverecHeight);
245
246 if (x < 0)
247 FrameSlot.SetPos(m_wWarningWidget, 0, y);
248 if (x > screenWUnscaled)
249 FrameSlot.SetPos(m_wWarningWidget, screenWUnscaled - ctverecWidth * 2, y);
250
251 if (y < 0)
252 FrameSlot.SetPos(m_wWarningWidget, x, 0);
253 if (y > screenHUnscaled)
254 FrameSlot.SetPos(m_wWarningWidget, x, screenHUnscaled - ctverecHeight * 2);
255
256 m_wWarningWidget.SetVisible(x < 0 || x > screenWUnscaled || y < 0 || y > screenHUnscaled);
257 }
258
259 UpdateIconPosition(widget, icon, x, y);
260 }
261 }
262
263 //------------------------------------------------------------------------------------------------
264 protected void UpdateIconPosition(Widget widget, SCR_MapUIElement icon, float x, float y)
265 {
266 FrameSlot.SetPos(widget, x, y);
267 }
268
269 //------------------------------------------------------------------------------------------------
270 protected void InitSpawnPoints()
271 {
272 array<SCR_SpawnPoint> infos = {};
273 if (!m_bIsEditor)
274 {
275 Faction playerFaction = m_PlyFactionAffilComp.GetAffiliatedFaction();
276 if (!playerFaction)
277 return;
278
279 infos = SCR_SpawnPoint.GetSpawnPointsForFaction(playerFaction.GetFactionKey());
280 }
281 else
282 {
283 infos = SCR_SpawnPoint.GetSpawnPoints();
284 }
285
286 foreach (SCR_SpawnPoint info : infos)
287 {
288 ShowSpawnPoint(info);
289 }
290
291 UpdateIcons();
292 }
293
294 //------------------------------------------------------------------------------------------------
295 protected void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
296 {
297 if (!m_bIsDeployMap && spawnPoint.GetVisibleInDeployMapOnly())
298 return;
299
300 if (!spawnPoint.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
301 return;
302
303 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPointElement, m_wIconsContainer);
304 SCR_MapUISpawnPoint handler = SCR_MapUISpawnPoint.Cast(w.FindHandler(SCR_MapUISpawnPoint));
305 if (!handler)
306 return;
307
308 handler.Init(spawnPoint);
309 handler.SetParent(this);
310 m_mIcons.Set(w, handler);
311
312 FrameSlot.SetSizeToContent(w, true);
313 FrameSlot.SetAlignment(w, 0.5, 0.5);
314 }
315
316 //------------------------------------------------------------------------------------------------
318 protected void InitTaskMarkers()
319 {
320 if (!m_TaskSystem)
321 return;
322
323 int playerID = SCR_PlayerController.GetLocalPlayerId();
324 SCR_TaskExecutor executor = SCR_TaskExecutor.FromPlayerID(playerID);
325 if (!executor)
326 return;
327
328 //## Get all tasks visible for player or all tasks if player is GM.
329 array<SCR_Task> availableTasks = {};
330 if (m_bIsEditor)
331 m_TaskSystem.GetTasks(availableTasks);
332 else
333 m_TaskSystem.GetTasksVisibleFor(availableTasks, executor);
334
335 foreach (SCR_Task task : availableTasks)
336 {
337 if (!m_TaskSystem.IsTaskVisibleOnMap(task))
338 continue;
339
341 }
342
343 UpdateIcons();
344 }
345
346 //------------------------------------------------------------------------------------------------
349 protected void InitTaskIcon(SCR_Task task)
350 {
351 // a task that is not allowed will not be shown
353 {
354 if (!m_aAllowedTaskTypenames.Contains(task.Type().ToString()))
355 return;
356 }
357
358 //## Don't create icon for completed and cancelled tasks.
359 //if (SCR_Enum.HasPartialFlag(SCR_ETaskState.COMPLETED | SCR_ETaskState.CANCELLED, m_TaskSystem.GetTaskState(task)))
360 // return;
361
362 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sTaskElement, m_wIconsContainer);
363 if (!w)
364 return;
365
367 if (!handler)
368 return;
369
370 handler.SetParent(this);
371 handler.InitTask(task);
372
373 m_mIcons.Set(w, handler);
374
375 FrameSlot.SetSizeToContent(w, true);
376 FrameSlot.SetAlignment(w, 0.5, 0.5);
377 }
378
379 //------------------------------------------------------------------------------------------------
382 protected void OnTaskAdded(SCR_Task task)
383 {
384 if (!m_bShowTasks || !task || !m_TaskSystem)
385 return;
386
387 string factionKey = SCR_FactionManager.SGetLocalPlayerFaction().GetFactionKey();
388 array<string> factions = m_TaskSystem.GetTaskFactions(task);
389 if (factions && !factions.IsEmpty() && !factions.Contains(factionKey))
390 return;
391
392 SCR_TaskMapUIComponent component;
393 foreach (Widget w, SCR_MapUIElement element : m_mIcons)
394 {
395 component = SCR_TaskMapUIComponent.Cast(element);
396 if (!component)
397 continue;
398
399 if (component.GetTask() == task)
400 return;
401 }
402
404 UpdateIcons();
405 }
406
407 //------------------------------------------------------------------------------------------------
410 protected void OnTaskRemoved(notnull SCR_Task task)
411 {
412 SCR_TaskMapUIComponent component;
413 foreach (Widget w, SCR_MapUIElement element : m_mIcons)
414 {
415 component = SCR_TaskMapUIComponent.Cast(element);
416 if (!component)
417 continue;
418
419 if (component.GetTask() == task)
420 component.GetRootWidget().RemoveFromHierarchy();
421 }
422 }
423
424 //------------------------------------------------------------------------------------------------
425 protected void RemoveAllIcons()
426 {
427 Widget child = m_wIconsContainer.GetChildren();
428 while (child)
429 {
430 Widget sibling = child.GetSibling();
431 delete child;
432 child = sibling;
433 }
434
435 m_mIcons.Clear();
436 }
437
438 //------------------------------------------------------------------------------------------------
442 {
443 delete SCR_MapHelper<Widget, SCR_MapUIElement>.GetKeyByValue(m_mIcons, icon);
444 }
445
446 //------------------------------------------------------------------------------------------------
448 {
449 foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
450 {
451 if (icon && icon.GetSpawnPointId() == id)
452 return icon;
453 }
454
455 return null;
456 }
457
458 //------------------------------------------------------------------------------------------------
460 void OnSpawnPointSelectedExt(RplId id) // called when selected via deploy menu spinbox
461 {
463 if (icon)
464 icon.SelectIcon(false);
465 }
466
467 //------------------------------------------------------------------------------------------------
470 {
471 GetOnElementSelected().Invoke(element);
472 }
473
474 //------------------------------------------------------------------------------------------------
477 void OnSpawnPointSelected(RplId spId = RplId.Invalid())
478 {
479 GetOnSpawnPointSelected().Invoke(spId);
480 }
481
482 //------------------------------------------------------------------------------------------------
483 protected void OnPlayerGroupChanged(SCR_AIGroup group)
484 {
486 foreach (Widget w, SCR_MapUIElement e : m_mIcons)
487 {
489 if (!spIcon)
490 continue;
491
493 if (!sp)
494 continue;
495
496 if (!sp.IsSpawnPointVisibleForPlayer(pid))
498 }
499
500 array<SCR_SpawnPoint> playerSpawnPoints = SCR_SpawnPoint.GetSpawnPointsForFaction(m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey());
501 foreach (SCR_SpawnPoint sp : playerSpawnPoints)
502 {
503 SCR_MapUISpawnPoint spIcon = FindSpawnPoint(sp.GetRplId()); // this is pretty bad sorry
504 if (spIcon)
505 continue;
506
507 if (sp.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
508 AddSpawnPoint(sp);
509 }
510 }
511
512 //------------------------------------------------------------------------------------------------
517 {
518 foreach (Widget w, SCR_MapUIElement e : m_mIcons)
519 {
521 if (!sp)
522 continue;
523
524 if (sp.GetSpawnPointId() == id)
525 return sp;
526 }
527
528 return null;
529 }
530
531 //------------------------------------------------------------------------------------------------
540
541 //------------------------------------------------------------------------------------------------
550
551 //------------------------------------------------------------------------------------------------
555 {
556 SCR_TaskMapUIComponent taskComponent;
557 foreach (Widget w, SCR_MapUIElement element : m_mIcons)
558 {
559 taskComponent = SCR_TaskMapUIComponent.Cast(element);
560 if (!taskComponent)
561 continue;
562
563 if (taskComponent.GetTask().GetTaskID() == taskID)
564 return taskComponent;
565 }
566
567 return null;
568 }
569}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
void SCR_FactionManager(IEntitySource src, IEntity parent)
EMapEntityMode
Mode of the map.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
Replication item identifier.
Definition RplId.c:14
override void OnMapClose(MapConfiguration config)
SCR_MapUISpawnPoint FindSpawnPoint(RplId id)
void OnElementSelected(notnull SCR_MapUIElement element)
void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
ref ScriptInvoker< SCR_MapUIElement > m_OnElementSelected
void OnSpawnPointSelected(RplId spId=RplId.Invalid())
void OnMapPan(float panX, float panY, bool adjustedPan)
void OnPlayerGroupChanged(SCR_AIGroup group)
void InitTaskMarkers()
Creates task icon for every task which is visible on map for player.
void HideSpawnPoint(RplId spawnPointId)
override void OnMapOpen(MapConfiguration config)
void OnPlayerFactionResponse(SCR_PlayerFactionAffiliationComponent component, int factionIndex, bool response)
ref map< Widget, SCR_MapUIElement > m_mIcons
ref ScriptInvoker< RplId > m_OnSpawnPointSelected
SCR_MapUIElement FindSpawnPointIconById(RplId id)
ref array< string > m_aAllowedTaskTypenames
void UpdateIconPosition(Widget widget, SCR_MapUIElement icon, float x, float y)
void UpdateSpawnPointName(RplId id, string name)
void OnTaskRemoved(notnull SCR_Task task)
void RemoveIcon(SCR_MapUIElement icon)
void RemoveSpawnPoint(SCR_SpawnPoint spawnPoint)
void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
void AddSpawnPoint(SCR_SpawnPoint spawnPoint)
SCR_PlayerControllerGroupComponent m_PlyGroupComp
SCR_TaskMapUIComponent GetTaskFromID(string taskID)
void SelectIcon(bool invoke=true)
override RplId GetSpawnPointId()
void Init(notnull SCR_SpawnPoint spawnPoint)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
Spawn point entity defines positions on which players can possibly spawn.
bool IsSpawnPointVisibleForPlayer(int pid)
static ref SCR_SpawnPointNameChanged_Invoker OnSpawnPointNameChanged
static SCR_SpawnPoint GetSpawnPointByRplId(RplId id)
string GetFactionKey()
void InitTask(notnull SCR_Task task)
Definition Types.c:486
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134