Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnPointRequestUIComponent.c
Go to the documentation of this file.
2 {
3  [Attribute("Selector")]
4  protected string m_sSpawnPointSelector;
5  protected Widget m_wSpawnPointSelector;
6 
7  protected RplId m_SelectedSpawnPointId = RplId.Invalid();
8  protected SCR_SpawnPointSpinBox m_SpawnPointSelector;
9 
10  protected ref ScriptInvoker<RplId> m_OnSpawnPointSelected;
11  static ref ScriptInvoker<RplId> s_OnSpawnPointSelected;
12 
13  //------------------------------------------------------------------------------------------------
14  override void HandlerAttached(Widget w)
15  {
16  m_wSpawnPointSelector = w.FindAnyWidget(m_sSpawnPointSelector);
17  if (m_wSpawnPointSelector)
18  m_SpawnPointSelector = SCR_SpawnPointSpinBox.Cast(m_wSpawnPointSelector.FindHandler(SCR_SpawnPointSpinBox));
19 
20  if (!m_SpawnPointSelector)
21  return;
22 
23  m_SpawnPointSelector.m_OnChanged.Insert(SelectSpawnPoint);
24  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Insert(OnSpawnPointFactionChange);
25  SCR_SpawnPoint.Event_SpawnPointAdded.Insert(OnSpawnPointAdded);
26  SCR_SpawnPoint.Event_SpawnPointRemoved.Insert(RemoveSpawnPoint);
27  SCR_SpawnPoint.OnSpawnPointNameChanged.Insert(UpdateSpawnPointName);
28  }
29 
30  override void HandlerDeattached(Widget w)
31  {
32  if (m_SpawnPointSelector)
33  m_SpawnPointSelector.m_OnChanged.Remove(SelectSpawnPoint);
34 
35  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Remove(OnSpawnPointFactionChange);
36  SCR_SpawnPoint.Event_SpawnPointAdded.Remove(OnSpawnPointAdded);
37  SCR_SpawnPoint.Event_SpawnPointRemoved.Remove(RemoveSpawnPoint);
38  SCR_SpawnPoint.OnSpawnPointNameChanged.Remove(UpdateSpawnPointName);
39  }
40 
41  protected void SelectSpawnPoint(SCR_SpawnPointSpinBox spinbox, int itemId)
42  {
43  if (spinbox.IsEmpty())
44  return;
45 
46  if (spinbox.GetSpawnPointId(itemId) != m_SelectedSpawnPointId)
47  {
48  m_SelectedSpawnPointId = spinbox.GetSpawnPointId(itemId);
49  GetOnSpawnPointSelected().Invoke(m_SelectedSpawnPointId, true);
50  SGetOnSpawnPointSelected().Invoke(m_SelectedSpawnPointId, true);
51  }
52  }
53 
54  protected void SetSpawnPoint(RplId spawnPointId)
55  {
56  m_SelectedSpawnPointId = spawnPointId;
57  GetOnSpawnPointSelected().Invoke(spawnPointId);
58  }
59 
60  void CycleSpawnPoints(bool next = true) // false for previous spawn
61  {
62  int currentIndex = m_SpawnPointSelector.GetCurrentIndex();
63  int nextIndex = currentIndex + 1;
64  if (!next)
65  nextIndex = currentIndex - 1;
66 
67  int itemCount = m_SpawnPointSelector.m_aElementNames.Count();
68  if (nextIndex >= itemCount)
69  nextIndex = 0;
70  else if (nextIndex < 0)
71  nextIndex = itemCount - 1;
72 
73  m_SpawnPointSelector.SetCurrentItem(nextIndex);
74  }
75 
76  protected void AddSpawnPoint(SCR_SpawnPoint spawnPoint)
77  {
78  if (spawnPoint && spawnPoint.IsSpawnPointVisibleForPlayer(SCR_PlayerController.GetLocalPlayerId()))
79  {
80  RplId currentSpawnPointId = m_SelectedSpawnPointId;
81  string name = spawnPoint.GetSpawnPointName();
82  m_SpawnPointSelector.AddItem(name, spawnPoint.GetRplId());
83 
84  if (spawnPoint.GetRplId() != currentSpawnPointId)
85  {
86  int itemId = m_SpawnPointSelector.GetItemId(currentSpawnPointId);
87  if (itemId > -1)
88  m_SpawnPointSelector.SetCurrentItem(itemId); // make sure currently selected spawn point stays selected after new point is added
89  }
90  }
91  }
92 
93  protected void RemoveSpawnPoint(SCR_SpawnPoint spawnPoint)
94  {
95  RplId currentSpawnPointId = m_SelectedSpawnPointId;
96  int itemId = m_SpawnPointSelector.GetItemId(spawnPoint.GetRplId());
97  if (itemId == -1)
98  return;
99 
100  m_SpawnPointSelector.RemoveItem(itemId);
101 
102  if (spawnPoint.GetRplId() != currentSpawnPointId)
103  {
104  itemId = m_SpawnPointSelector.GetItemId(currentSpawnPointId);
105  m_SpawnPointSelector.SetCurrentItem(itemId);
106  m_SelectedSpawnPointId = GetCurrentRplId();
107  }
108  }
109 
110  protected void UpdateSpawnPointName(RplId id, string name)
111  {
112  int itemId = m_SpawnPointSelector.GetItemId(id);
113  m_SpawnPointSelector.SetItemName(itemId, name);
114  }
115 
116  protected void OnSpawnPointAdded(SCR_SpawnPoint spawnPoint)
117  {
118  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
119  if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
120  AddSpawnPoint(spawnPoint);
121  }
122 
123  protected void OnSpawnPointFactionChange(SCR_SpawnPoint spawnPoint)
124  {
125  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
126  if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
127  AddSpawnPoint(spawnPoint);
128  else
129  RemoveSpawnPoint(spawnPoint);
130  }
131 
132  protected void ClearSpawnPoints()
133  {
134  m_SpawnPointSelector.ClearAll();
135  // todo@lk: show warning
136  }
137 
138  void ShowAvailableSpawnPoints(Faction faction)
139  {
140  if (!faction)
141  return;
142 
143  ClearSpawnPoints();
144 
145  array<SCR_SpawnPoint> infos = SCR_SpawnPoint.GetSpawnPointsForFaction(faction.GetFactionKey());
146  if (infos.IsEmpty())
147  {
148  SetSpawnPoint(RplId.Invalid());
149  return;
150  }
151 
152  int pid = SCR_PlayerController.GetLocalPlayerId();
153  foreach (SCR_SpawnPoint info : infos)
154  {
155  if (info.IsSpawnPointVisibleForPlayer(pid))
156  AddSpawnPoint(info);
157  }
158  }
159 
160  void UpdateRelevantSpawnPoints()
161  {
162  array<SCR_SpawnPoint> spawnPoints = m_SpawnPointSelector.GetSpawnPointsInList();
163  PlayerController pc = GetGame().GetPlayerController();
165  array<SCR_SpawnPoint> playerSpawnPoints = SCR_SpawnPoint.GetSpawnPointsForFaction(plyFactionComp.GetAffiliatedFaction().GetFactionKey());
166 
167  foreach (SCR_SpawnPoint sp : spawnPoints)
168  {
169  if (!sp.IsSpawnPointVisibleForPlayer(pc.GetPlayerId()))
170  RemoveSpawnPoint(sp);
171  }
172 
173  foreach (SCR_SpawnPoint sp : playerSpawnPoints)
174  {
175  if (spawnPoints.Contains(sp))
176  continue;
177 
178  if (sp.IsSpawnPointVisibleForPlayer(pc.GetPlayerId()))
179  AddSpawnPoint(sp);
180  }
181  }
182 
183  void SelectSpawnPointExt(RplId id)
184  {
185  int itemId = m_SpawnPointSelector.GetItemId(id);
186  if (itemId > -1)
187  m_SpawnPointSelector.SetCurrentItem(itemId);
188  }
189 
190  ScriptInvoker GetOnSpawnPointSelected()
191  {
192  if (!m_OnSpawnPointSelected)
193  m_OnSpawnPointSelected = new ScriptInvoker();
194 
195  return m_OnSpawnPointSelected;
196  }
197 
198  static ScriptInvoker SGetOnSpawnPointSelected()
199  {
200  if (!s_OnSpawnPointSelected)
201  s_OnSpawnPointSelected = new ScriptInvoker();
202 
203  return s_OnSpawnPointSelected;
204  }
205 
206  RplId GetCurrentRplId()
207  {
208  return m_SpawnPointSelector.GetSpawnPointId(m_SpawnPointSelector.GetCurrentIndex());
209  }
210 
211  bool IsSelectorFocused()
212  {
213  return m_SpawnPointSelector && m_SpawnPointSelector.IsFocused();
214  }
215 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_SpawnPointRequestUIComponent
Definition: SCR_SpawnPointRequestUIComponent.c:1
SCR_SpawnPointSpinBox
Definition: SCR_SpawnPointSpinBox.c:1
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_DeployRequestUIBaseComponent
Definition: SCR_DeployRequestUIBaseComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
Faction
Definition: Faction.c:12
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461