Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapUIElementContainer.c
Go to the documentation of this file.
2 {
3  [Attribute("UIIconsContainer")];
4  protected string m_sIconsContainer;
5 
6  protected Widget m_wIconsContainer;
7 
8  [Attribute("{E78DE3FD19654C1B}UI/layouts/Campaign/SpawnPointElement.layout", params: "layout")]
9  protected ResourceName m_sSpawnPointElement;
10 
11  [Attribute("{EAB5D9841F081D07}UI/layouts/Campaign/TaskElementNew.layout", params: "layout")]
12  protected ResourceName m_sTaskElement;
13 
14  [Attribute("{C013EB43E812F9C1}UI/layouts/Menus/DeployMenu/WarningHintTemp.layout")]
15  protected ResourceName m_sWarningWidget;
16 
17  protected Widget m_wWarningWidget;
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  protected bool m_bIsEditor; // Map opened in editor with gamemaster rights (!limited)
29  protected bool m_bIsDeployMap;
30 
31  protected ref map<Widget, SCR_MapUIElement> m_mIcons = new map<Widget, SCR_MapUIElement>();
32 
33  protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp;
34  protected SCR_PlayerControllerGroupComponent m_PlyGroupComp;
35  protected SCR_BaseGameMode m_GameMode;
36 
37  protected ref ScriptInvoker<SCR_MapUIElement> m_OnElementSelected;
38  protected ref ScriptInvoker<RplId> m_OnSpawnPointSelected;
39 
40  //------------------------------------------------------------------------------------------------
41  override void Init()
42  {
44  m_bIsEditor = SCR_EditorManagerEntity.IsOpenedInstance(false);
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  protected void AddSpawnPoint(SCR_SpawnPoint spawnPoint)
49  {
50  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
51  if (!spawnPoint.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
52  return;
53 
54  if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
55  {
56  ShowSpawnPoint(spawnPoint);
57  UpdateIcons();
58  }
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected void RemoveSpawnPoint(SCR_SpawnPoint spawnPoint)
63  {
64  RplId pointId = spawnPoint.GetRplId();
65  HideSpawnPoint(pointId);
66  UpdateIcons();
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  protected void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
71  {
72  if (spawnPoint.GetFactionKey() == m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey())
73  AddSpawnPoint(spawnPoint);
74  else
75  RemoveSpawnPoint(spawnPoint);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  protected void UpdateSpawnPointName(RplId id, string name)
80  {
81  foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
82  {
83  if (icon && icon.GetSpawnPointId() == id)
84  {
85  icon.SetName(name);
86  break;
87  }
88  }
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  protected void HideSpawnPoint(RplId spawnPointId)
93  {
94  foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
95  {
96  if (icon && icon.GetSpawnPointId() == spawnPointId)
97  {
98  m_mIcons.Remove(w);
99  w.RemoveFromHierarchy();
100  }
101  }
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  protected void OnPlayerFactionResponse(SCR_PlayerFactionAffiliationComponent component, int factionIndex, bool response)
106  {
107  if (response)
108  {
109  RemoveAllIcons();
110 
111  if (m_bShowSpawnPoints)
112  InitSpawnPoints();
113 
114  if (m_bShowTasks)
115  InitTaskMarkers();
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  override void OnMapOpen(MapConfiguration config)
121  {
122  PlayerController pc = GetGame().GetPlayerController();
123  if (pc)
124  {
127  m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Insert(OnPlayerFactionResponse);
128 
129  m_PlyGroupComp = SCR_PlayerControllerGroupComponent.Cast(pc.FindComponent(SCR_PlayerControllerGroupComponent));
130  if (m_PlyGroupComp)
131  m_PlyGroupComp.GetOnGroupChanged().Insert(OnPlayerGroupChanged);
132  }
133 
134  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Insert(OnSpawnPointFactionChange);
135  SCR_SpawnPoint.Event_SpawnPointAdded.Insert(AddSpawnPoint);
136  SCR_SpawnPoint.Event_SpawnPointRemoved.Insert(RemoveSpawnPoint);
137 
138  SCR_BaseTaskManager.s_OnTaskUpdate.Insert(OnTaskAdded);
139 
140  m_bIsDeployMap = (config.MapEntityMode == EMapEntityMode.SPAWNSCREEN);
141 
142  m_wIconsContainer = m_RootWidget.FindAnyWidget(m_sIconsContainer);
143  m_wIconsContainer.SetVisible(true);
144 
145  Widget child = m_wIconsContainer.GetChildren();
146  while (child)
147  {
148  Widget sibling = child.GetSibling();
149  delete child;
150  child = sibling;
151  }
152 
153  if (m_bShowSpawnPoints)
154  InitSpawnPoints();
155 
156  if (m_bShowTasks)
157  InitTaskMarkers();
158 
159  m_MapEntity.GetOnMapPan().Insert(OnMapPan);
160  SCR_SpawnPoint.OnSpawnPointNameChanged.Insert(UpdateSpawnPointName);
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  override void OnMapClose(MapConfiguration config)
165  {
167  m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Remove(OnPlayerFactionResponse);
168 
169  if (m_PlyGroupComp)
170  m_PlyGroupComp.GetOnGroupChanged().Remove(OnPlayerGroupChanged);
171 
172  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Remove(OnSpawnPointFactionChange);
173  SCR_SpawnPoint.Event_SpawnPointAdded.Remove(AddSpawnPoint);
174  SCR_SpawnPoint.Event_SpawnPointRemoved.Remove(RemoveSpawnPoint);
175 
176  SCR_BaseTaskManager.s_OnTaskUpdate.Remove(OnTaskAdded);
177 
178  m_MapEntity.GetOnMapPan().Remove(OnMapPan);
179  SCR_SpawnPoint.OnSpawnPointNameChanged.Remove(UpdateSpawnPointName);
180 
181  foreach(Widget w, SCR_MapUIElement e : m_mIcons)
182  {
183  if (!w)
184  continue;
185  w.RemoveFromHierarchy();
186  }
187 
188  m_mIcons.Clear();
189  }
190 
191  //------------------------------------------------------------------------------------------------
195  void OnMapPan(float panX, float panY, bool adjustedPan)
196  {
197  UpdateIcons();
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  protected void UpdateIcons()
202  {
203  foreach (Widget widget, SCR_MapUIElement icon : m_mIcons)
204  {
205  if (!icon || !widget)
206  continue;
207 
208  vector pos = icon.GetPos();
209  float x, y;
210  m_MapEntity.WorldToScreen(pos[0], pos[2], x, y, true);
211 
212  x = GetGame().GetWorkspace().DPIUnscale(x);
213  y = GetGame().GetWorkspace().DPIUnscale(y);
214 
215  if (m_bShowSpawnPointsHint)
216  {
217  if (!m_wWarningWidget)
218  m_wWarningWidget = GetGame().GetWorkspace().CreateWidgets(m_sWarningWidget, m_wIconsContainer);
219 
220  // just a hint indicating icons outside of the view
221  float screenWidth = GetGame().GetWorkspace().GetWidth();
222  float screenHeight = GetGame().GetWorkspace().GetHeight();
223  float screenWUnscaled = GetGame().GetWorkspace().DPIUnscale(screenWidth);
224  float screenHUnscaled = GetGame().GetWorkspace().DPIUnscale(screenHeight);
225  float ctverecWidth, ctverecHeight;
226  m_wWarningWidget.GetScreenSize(ctverecWidth, ctverecHeight);
227 
228  if (x < 0)
229  FrameSlot.SetPos(m_wWarningWidget, 0, y);
230  if (x > screenWUnscaled)
231  FrameSlot.SetPos(m_wWarningWidget, screenWUnscaled - ctverecWidth * 2, y);
232 
233  if (y < 0)
234  FrameSlot.SetPos(m_wWarningWidget, x, 0);
235  if (y > screenHUnscaled)
236  FrameSlot.SetPos(m_wWarningWidget, x, screenHUnscaled - ctverecHeight * 2);
237 
238  m_wWarningWidget.SetVisible(x < 0 || x > screenWUnscaled || y < 0 || y > screenHUnscaled);
239  }
240 
241  FrameSlot.SetPos(widget, x, y);
242  }
243  }
244 
245  protected void InitSpawnPoints()
246  {
247  array<SCR_SpawnPoint> infos = {};
248  if (!m_bIsEditor)
249  {
250  Faction playerFaction = m_PlyFactionAffilComp.GetAffiliatedFaction();
251  if (!playerFaction)
252  return;
253 
254  infos = SCR_SpawnPoint.GetSpawnPointsForFaction(playerFaction.GetFactionKey());
255  }
256  else
257  {
258  infos = SCR_SpawnPoint.GetSpawnPoints();
259  }
260 
261  foreach (SCR_SpawnPoint info : infos)
262  {
263  ShowSpawnPoint(info);
264  }
265 
266  UpdateIcons();
267  }
268 
269  protected void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
270  {
271  if (!m_bIsDeployMap && spawnPoint.GetVisibleInDeployMapOnly())
272  return;
273 
274  if (!spawnPoint.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
275  return;
276 
277  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPointElement, m_wIconsContainer);
278  SCR_MapUISpawnPoint handler = SCR_MapUISpawnPoint.Cast(w.FindHandler(SCR_MapUISpawnPoint));
279  if (!handler)
280  return;
281 
282  handler.Init(spawnPoint);
283  handler.SetParent(this);
284  m_mIcons.Set(w, handler);
285 
286  FrameSlot.SetSizeToContent(w, true);
287  FrameSlot.SetAlignment(w, 0.5, 0.5);
288  }
289 
290  //------------------------------------------------------------------------------------------------
291  protected void InitTaskMarkers()
292  {
293  SCR_BaseTaskManager taskManager = GetTaskManager();
294  if (!taskManager)
295  return;
296 
297  int taskCount;
298  array<SCR_BaseTask> availableTasks = {};
299  if (m_bIsEditor)
300  {
301  taskCount = taskManager.GetTasks(availableTasks);
302  }
303  else
304  {
305  taskCount = taskManager.GetFilteredTasks(availableTasks, SCR_FactionManager.SGetLocalPlayerFaction());
306  }
307 
308  for (int i = 0; i < taskCount; ++i)
309  {
310  InitTaskIcon(availableTasks[i]);
311  }
312 
313  UpdateIcons();
314  }
315 
316  protected void InitTaskIcon(SCR_BaseTask task)
317  {
318  if (task.GetTaskState() == SCR_TaskState.FINISHED || task.GetTaskState() == SCR_TaskState.CANCELLED)
319  return;
320 
321  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sTaskElement, m_wIconsContainer);
322  if (!w)
323  return;
324 
325  SCR_MapUITask handler = SCR_MapUITask.Cast(w.FindHandler(SCR_MapUITask));
326  if (!handler)
327  return;
328 
329  handler.SetParent(this);
330  handler.InitTask(task);
331  m_mIcons.Set(w, handler);
332 
333  FrameSlot.SetSizeToContent(w, true);
334  FrameSlot.SetAlignment(w, 0.5, 0.5);
335  }
336 
337  protected void OnTaskAdded(SCR_BaseTask task)
338  {
339  if (!m_bShowTasks || !task)
340  return;
341 
342  if (task.GetTargetFaction() != SCR_FactionManager.SGetLocalPlayerFaction())
343  return;
344 
345  foreach (Widget w, SCR_MapUIElement e : m_mIcons)
346  {
347  SCR_MapUITask t = SCR_MapUITask.Cast(e);
348  if (!t)
349  continue;
350 
351  if (t.GetTask() == task)
352  return;
353  }
354 
355  InitTaskIcon(task);
356  UpdateIcons();
357  }
358 
359  protected void RemoveAllIcons()
360  {
361  Widget child = m_wIconsContainer.GetChildren();
362  while (child)
363  {
364  Widget sibling = child.GetSibling();
365  delete child;
366  child = sibling;
367  }
368 
369  m_mIcons.Clear();
370  }
371 
372  //------------------------------------------------------------------------------------------------
375  void RemoveIcon(SCR_MapUIElement icon)
376  {
377  delete m_mIcons.GetKeyByValue(icon);
378  }
379 
380  protected SCR_MapUIElement FindSpawnPointIconById(RplId id)
381  {
382  foreach (Widget w, SCR_MapUIElement icon : m_mIcons)
383  {
384  if (icon && icon.GetSpawnPointId() == id)
385  return icon;
386  }
387 
388  return null;
389  }
390 
391  //------------------------------------------------------------------------------------------------
393  void OnSpawnPointSelectedExt(RplId id) // called when selected via deploy menu spinbox
394  {
395  SCR_MapUIElement icon = FindSpawnPointIconById(id);
396  if (icon)
397  icon.SelectIcon(false);
398  }
399 
400  //------------------------------------------------------------------------------------------------
402  void OnElementSelected(notnull SCR_MapUIElement element)
403  {
404  GetOnElementSelected().Invoke(element);
405  }
406 
407  //------------------------------------------------------------------------------------------------
410  void OnSpawnPointSelected(RplId spId = RplId.Invalid())
411  {
412  GetOnSpawnPointSelected().Invoke(spId);
413  }
414 
415  //------------------------------------------------------------------------------------------------
416  protected void OnPlayerGroupChanged(SCR_AIGroup group)
417  {
418  int pid = SCR_PlayerController.GetLocalPlayerId();
419  foreach (Widget w, SCR_MapUIElement e : m_mIcons)
420  {
421  SCR_MapUISpawnPoint spIcon = SCR_MapUISpawnPoint.Cast(e);
422  if (!spIcon)
423  continue;
424 
425  SCR_SpawnPoint sp = SCR_SpawnPoint.GetSpawnPointByRplId(spIcon.GetSpawnPointId());
426  if (!sp)
427  continue;
428 
429  if (!sp.IsSpawnPointVisibleForPlayer(pid))
430  RemoveSpawnPoint(sp);
431  }
432 
433  array<SCR_SpawnPoint> playerSpawnPoints = SCR_SpawnPoint.GetSpawnPointsForFaction(m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey());
434  foreach (SCR_SpawnPoint sp : playerSpawnPoints)
435  {
436  SCR_MapUISpawnPoint spIcon = FindSpawnPoint(sp.GetRplId()); // this is pretty bad sorry
437  if (spIcon)
438  continue;
439 
440  if (sp.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
441  AddSpawnPoint(sp);
442  }
443  }
444 
445  //------------------------------------------------------------------------------------------------
449  SCR_MapUISpawnPoint FindSpawnPoint(RplId id)
450  {
451  foreach (Widget w, SCR_MapUIElement e : m_mIcons)
452  {
454  if (!sp)
455  continue;
456 
457  if (sp.GetSpawnPointId() == id)
458  return sp;
459  }
460 
461  return null;
462  }
463 
464  //------------------------------------------------------------------------------------------------
466  ScriptInvoker GetOnSpawnPointSelected()
467  {
468  if (!m_OnSpawnPointSelected)
469  m_OnSpawnPointSelected = new ScriptInvoker();
470 
471  return m_OnSpawnPointSelected;
472  }
473 
474  //------------------------------------------------------------------------------------------------
476  ScriptInvoker GetOnElementSelected()
477  {
478  if (!m_OnElementSelected)
479  m_OnElementSelected = new ScriptInvoker();
480 
481  return m_OnElementSelected;
482  }
483 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_RootWidget
protected Widget m_RootWidget
Definition: SCR_BinocularsComponent.c:10
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
m_PlyFactionAffilComp
protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
Definition: SCR_DeployMenuBase.c:119
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_MapUISpawnPoint
Definition: SCR_MapUISpawnPoint.c:1
SCR_MapUITask
Definition: SCR_MapUITask.c:2
m_GameMode
protected SCR_BaseGameMode m_GameMode
Definition: SCR_DeployMenuBase.c:111
SCR_MapUIElement
Definition: SCR_MapUIElement.c:12
Faction
Definition: Faction.c:12
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
SCR_TaskState
SCR_TaskState
Definition: SCR_TaskState.c:2
SCR_AIGroup
Definition: SCR_AIGroup.c:68
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_MapUIElementContainer
Definition: SCR_MapUIElementContainer.c:1
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
EMapEntityMode
EMapEntityMode
Mode of the map.
Definition: SCR_MapConstants.c:28
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26