Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapCampaignUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
3 {
4  [Attribute("{E48F14D6D3C54BE5}UI/layouts/Campaign/BaseElement.layout", params: "layout")]
5  protected ResourceName m_sBaseElement;
6 
7  [Attribute("{94F1E2223D7E0588}UI/layouts/Campaign/ServiceHint.layout", params: "layout")]
8  protected ResourceName m_sServiceHint;
9 
10  [Attribute("{FD71287E68006A26}UI/layouts/Campaign/CampaignPlayerMapIndicator.layout", params: "layout")]
11  protected ResourceName m_sSpawnPositionHint;
12 
13  protected Widget m_wMobileAssembly;
14 
15  //------------------------------------------------------------------------------
16  void InitMobileAssembly(string factionKey, bool deployed)
17  {
18  if (m_wMobileAssembly)
19  {
20  m_wMobileAssembly.SetVisible(deployed);
21  return;
22  }
23 
24  FactionManager fm = GetGame().GetFactionManager();
25  if (!fm)
26  return;
27 
28  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(fm.GetFactionByKey(factionKey));
29  if (!faction)
30  return;
31 
32  SCR_CampaignFaction playerFaction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
33  if (faction != playerFaction)
34  return;
35 
36  SCR_CampaignMobileAssemblyStandaloneComponent assembly = faction.GetMobileAssembly();
37  if (!assembly)
38  return;
39 
40  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sBaseElement, m_wIconsContainer);
41  if (!w)
42  return;
43 
44  m_wMobileAssembly = w;
45 
47  if (!handler)
48  return;
49 
50  handler.SetParent(this);
51  handler.InitMobile(assembly);
52  m_mIcons.Set(w, handler);
53 
54  FrameSlot.SetSizeToContent(w, true);
55  FrameSlot.SetAlignment(w, 0.5, 0.5);
56  }
57 
58  //------------------------------------------------------------------------------
59  protected void InitBases()
60  {
61  SCR_MilitaryBaseSystem baseManager = SCR_MilitaryBaseSystem.GetInstance();
62  array<SCR_MilitaryBaseComponent> bases = {};
63  baseManager.GetBases(bases);
64  SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
65 
66  if (!faction)
67  return;
68 
70 
71  for (int i = 0, count = bases.Count(); i < count; ++i)
72  {
73  base = SCR_CampaignMilitaryBaseComponent.Cast(bases[i]);
74 
75  if (!base || !base.IsInitialized())
76  continue;
77 
78  if (base.IsHQ() && base.GetFaction() != faction)
79  continue;
80 
81  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sBaseElement, m_wIconsContainer);
83 
84  if (!handler)
85  return;
86 
87  handler.SetParent(this);
88  handler.InitBase(base);
89  m_mIcons.Set(w, handler);
90  base.SetBaseUI(handler);
91 
92  FrameSlot.SetSizeToContent(w, true);
93  FrameSlot.SetAlignment(w, 0.5, 0.5);
94  }
95 
96  if (faction)
97  {
98  string factionKey = faction.GetFactionKey();
99  InitMobileAssembly(factionKey, faction.GetMobileAssembly() != null);
100  }
101 
102  UpdateIcons();
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected override void ShowSpawnPoint(notnull SCR_SpawnPoint spawnPoint)
107  {
108  if (!m_bIsDeployMap && spawnPoint.GetVisibleInDeployMapOnly())
109  return;
110 
111  SCR_GameModeCampaign gameMode = SCR_GameModeCampaign.GetInstance();
112 
113  if (!gameMode)
114  return;
115 
116  if (spawnPoint.Type() != SCR_CampaignSpawnPointGroup)
117  {
118  IEntity owner = spawnPoint.GetParent();
119 
120  // Mobile HQ icon is already shown
121  SCR_CampaignMobileAssemblyStandaloneComponent westMHQ = gameMode.GetFactionByEnum(SCR_ECampaignFaction.BLUFOR).GetMobileAssembly();
122  SCR_CampaignMobileAssemblyStandaloneComponent eastMHQ = gameMode.GetFactionByEnum(SCR_ECampaignFaction.OPFOR).GetMobileAssembly();
123 
124  if ((westMHQ && westMHQ.GetOwner() == spawnPoint) || (eastMHQ && eastMHQ.GetOwner() == spawnPoint))
125  return;
126 
127  super.ShowSpawnPoint(spawnPoint); // when spawn point is placed by game master, use default spawn point visualization
128  return;
129  }
130 
131  // todo: hotfix for icon duplicates in conflict, figure out a proper solution :wink:
132 
133  if (spawnPoint.Type() == SCR_SpawnPoint || spawnPoint.Type() == SCR_CampaignSpawnPointGroup)
134  return;
135 
136  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPointElement, m_wIconsContainer);
137  SCR_MapUISpawnPoint handler = SCR_MapUISpawnPoint.Cast(w.FindHandler(SCR_MapUISpawnPoint));
138  if (!handler)
139  return;
140 
141  handler.Init(spawnPoint);
142  handler.SetParent(this);
143  m_mIcons.Set(w, handler);
144 
145  FrameSlot.SetSizeToContent(w, true);
146  FrameSlot.SetAlignment(w, 0.5, 0.5);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void CreatePlayerSpawnPositionHint()
151  {
152  SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
153 
154  if (!comp)
155  return;
156 
157  if (!comp.CanShowPlayerSpawn())
158  return;
159 
160  comp.SetMapCampaignUI(this);
161 
162  vector playerLocation = comp.GetPlayerSpawnPos();
163 
164  Widget indicator = GetGame().GetWorkspace().CreateWidgets(m_sSpawnPositionHint, m_wIconsContainer);
165 
167 
168  if (!highlightHandler)
169  return;
170 
171  m_mIcons.Insert(indicator, highlightHandler);
172 
173  highlightHandler.SetParent(this);
174  highlightHandler.SetPos(playerLocation);
175 
176  FrameSlot.SetPosX(indicator, playerLocation[0]);
177  FrameSlot.SetPosY(indicator, playerLocation[1]);
178  FrameSlot.SetSizeToContent(indicator, true);
179  FrameSlot.SetAlignment(indicator, 0.5, 0.5);
180 
181  //Called only after spawn, to center map and zoom to player position.
182  if (!comp.WasMapOpened())
183  {
184  m_MapEntity.ZoomPanSmooth(1.5,playerLocation[0],playerLocation[2]);
185  comp.SetMapOpened(true);
186  }
187 
188  //Set image from ImageSet
189  ResourceName imageSet = "{5E8F77F38C2B9B9F}UI/Imagesets/MilitarySymbol/ICO.imageset";
190  ImageWidget image = ImageWidget.Cast(indicator.FindAnyWidget("Image"));
191  if(image)
192  {
193  image.LoadImageFromSet(0, imageSet, "PlayerSpawnHint");
194  image.SetColor(Color.FromInt(Color.ORANGE));
195  }
196 
197  //Sets time to spawn icon
198  RichTextWidget timeWidget = RichTextWidget.Cast(indicator.FindAnyWidget("TimeString"));
199  TimeContainer timeContainer = comp.GetSpawnTime();
200  if (timeContainer)
201  {
202  string hours = timeContainer.m_iHours.ToString();
203  string minutes = timeContainer.m_iMinutes.ToString();
204 
205  if (timeContainer.m_iHours < 10)
206  hours = "0" + hours;
207 
208  if (timeContainer.m_iMinutes < 10)
209  minutes = "0" + minutes;
210 
211  timeWidget.SetTextFormat("%1:%2",hours, minutes);
212  }
213 
214  HideSpawnPositionHint(m_MapEntity.GetLayerIndex());
215  m_MapEntity.GetOnLayerChanged().Insert(HideSpawnPositionHint);
216  }
217 
218  //------------------------------------------------------------------------------------------------
220  void RemoveSpawnPositionHint()
221  {
222  SCR_CampaignMapUIPlayerHighlight highlightHandler;
223  foreach (Widget w, SCR_MapUIElement handler: m_mIcons)
224  {
225  highlightHandler = SCR_CampaignMapUIPlayerHighlight.Cast(handler);
226  if(highlightHandler)
227  {
228  w.RemoveFromHierarchy();
229  m_mIcons.Remove(w);
230  break;
231  }
232  }
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  protected void HideSpawnPositionHint(int layer)
237  {
238  SCR_CampaignMapUIPlayerHighlight highlightHandler;
239  foreach (Widget w, SCR_MapUIElement handler: m_mIcons)
240  {
241  highlightHandler = SCR_CampaignMapUIPlayerHighlight.Cast(handler);
242  if(highlightHandler)
243  {
244  if(layer > 1)
245  {
246  w.SetVisible(false);
247  return;
248  }
249  w.SetVisible(true);
250  }
251  }
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  protected override void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
256  {
257  if (spawnPoint.GetFactionKey() == m_PlyFactionAffilComp.GetAffiliatedFaction().GetFactionKey())
258  {
259  AddSpawnPoint(spawnPoint);
260  }
261  else
262  {
263  if (spawnPoint.Type() != SCR_CampaignSpawnPointGroup) // when changing faction of gm placed spawn points, we want to remove them from the map
264  RemoveSpawnPoint(spawnPoint);
265  }
266  }
267 
268  //------------------------------------------------------------------------------------------------
269  void OnMapZoom(float pixelPerUnit)
270  {
271  UpdateIcons();
272  }
273 
274  //------------------------------------------------------------------------------------------------
275  override void OnMapOpen(MapConfiguration config)
276  {
277  super.OnMapOpen(config);
278 
279  Widget serviceHint = GetGame().GetWorkspace().CreateWidgets(m_sServiceHint, SCR_MapEntity.GetMapInstance().GetMapMenuRoot());
280 
281  if (serviceHint)
282  {
283  FrameSlot.SetSizeToContent(serviceHint, true);
284  serviceHint.SetName("ServiceHintRoot");
285  serviceHint.SetVisible(false);
286  }
287 
288  SCR_CampaignFeedbackComponent comp = SCR_CampaignFeedbackComponent.GetInstance();
289 
290  if (comp)
291  comp.SetMapCampaignUI(this);
292 
293  InitBases();
294  CreatePlayerSpawnPositionHint();
295 
296  SCR_MapEntity.GetOnMapPan().Insert(OnMapPan);
297  SCR_MapEntity.GetOnMapZoom().Insert(OnMapZoom);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  override void OnMapClose(MapConfiguration config)
302  {
303  super.OnMapClose(config);
304 
305  SCR_MapEntity.GetOnMapPan().Remove(OnMapPan);
306  SCR_MapEntity.GetOnMapZoom().Remove(OnMapZoom);
307 
308  delete m_wMobileAssembly;
309 
310  foreach (Widget w, SCR_MapUIElement i : m_mIcons)
311  {
312  w.RemoveFromHierarchy();
313  delete w;
314  }
315 
316  m_mIcons.Clear();
317  m_MapEntity.GetOnLayerChanged().Remove(HideSpawnPositionHint);
318  }
319 
320  //------------------------------------------------------------------------------------------------
321  void ~SCR_MapCampaignUI()
322  {
323  delete m_wMobileAssembly;
324  foreach (Widget w, SCR_MapUIElement i : m_mIcons)
325  {
326  delete w;
327  }
328  }
329 };
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
RemoveSpawnPoint
protected void RemoveSpawnPoint(int playerID)
Definition: SCR_PlayerSpawnPointManagerComponent.c:102
SCR_ECampaignFaction
SCR_ECampaignFaction
Definition: SCR_CampaignFactionManager.c:130
OnMapPan
protected void OnMapPan(float x, float y, bool adjustedPan)
Definition: SCR_MapDrawingUI.c:330
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CampaignMapUIBase
Definition: SCR_CampaignMapUIBase.c:2
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
m_PlyFactionAffilComp
protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
Definition: SCR_DeployMenuBase.c:119
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
AddSpawnPoint
protected void AddSpawnPoint(int playerID)
Definition: SCR_PlayerSpawnPointManagerComponent.c:75
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_MapCampaignUI
Definition: SCR_MapCampaignUI.c:2
SCR_MapUISpawnPoint
Definition: SCR_MapUISpawnPoint.c:1
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_MapUIElement
Definition: SCR_MapUIElement.c:12
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_CampaignMapUIPlayerHighlight
Definition: SCR_CampaignMapUIPlayerHighlight.c:2
SCR_MapUIElementContainer
Definition: SCR_MapUIElementContainer.c:1
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_CampaignSpawnPointGroup
Definition: SCR_CampaignSpawnPointGroup.c:7
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38