4 protected string m_sSpawnPointSelector;
5 protected Widget m_wSpawnPointSelector;
7 protected RplId m_SelectedSpawnPointId = RplId.Invalid();
10 protected ref ScriptInvoker<RplId> m_OnSpawnPointSelected;
11 static ref ScriptInvoker<RplId> s_OnSpawnPointSelected;
14 override void HandlerAttached(Widget w)
16 m_wSpawnPointSelector = w.FindAnyWidget(m_sSpawnPointSelector);
17 if (m_wSpawnPointSelector)
20 if (!m_SpawnPointSelector)
23 m_SpawnPointSelector.m_OnChanged.Insert(SelectSpawnPoint);
24 SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Insert(OnSpawnPointFactionChange);
27 SCR_SpawnPoint.OnSpawnPointNameChanged.Insert(UpdateSpawnPointName);
30 override void HandlerDeattached(Widget w)
32 if (m_SpawnPointSelector)
33 m_SpawnPointSelector.m_OnChanged.Remove(SelectSpawnPoint);
35 SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Remove(OnSpawnPointFactionChange);
38 SCR_SpawnPoint.OnSpawnPointNameChanged.Remove(UpdateSpawnPointName);
43 if (spinbox.IsEmpty())
46 if (spinbox.GetSpawnPointId(itemId) != m_SelectedSpawnPointId)
48 m_SelectedSpawnPointId = spinbox.GetSpawnPointId(itemId);
49 GetOnSpawnPointSelected().Invoke(m_SelectedSpawnPointId,
true);
50 SGetOnSpawnPointSelected().Invoke(m_SelectedSpawnPointId,
true);
54 protected void SetSpawnPoint(RplId spawnPointId)
56 m_SelectedSpawnPointId = spawnPointId;
57 GetOnSpawnPointSelected().Invoke(spawnPointId);
60 void CycleSpawnPoints(
bool next =
true)
62 int currentIndex = m_SpawnPointSelector.GetCurrentIndex();
63 int nextIndex = currentIndex + 1;
65 nextIndex = currentIndex - 1;
67 int itemCount = m_SpawnPointSelector.m_aElementNames.Count();
68 if (nextIndex >= itemCount)
70 else if (nextIndex < 0)
71 nextIndex = itemCount - 1;
73 m_SpawnPointSelector.SetCurrentItem(nextIndex);
78 if (spawnPoint && spawnPoint.IsSpawnPointVisibleForPlayer(
SCR_PlayerController.GetLocalPlayerId()))
80 RplId currentSpawnPointId = m_SelectedSpawnPointId;
81 string name = spawnPoint.GetSpawnPointName();
82 m_SpawnPointSelector.AddItem(name, spawnPoint.GetRplId());
84 if (spawnPoint.GetRplId() != currentSpawnPointId)
86 int itemId = m_SpawnPointSelector.GetItemId(currentSpawnPointId);
88 m_SpawnPointSelector.SetCurrentItem(itemId);
95 RplId currentSpawnPointId = m_SelectedSpawnPointId;
96 int itemId = m_SpawnPointSelector.GetItemId(spawnPoint.GetRplId());
100 m_SpawnPointSelector.RemoveItem(itemId);
102 if (spawnPoint.GetRplId() != currentSpawnPointId)
104 itemId = m_SpawnPointSelector.GetItemId(currentSpawnPointId);
105 m_SpawnPointSelector.SetCurrentItem(itemId);
106 m_SelectedSpawnPointId = GetCurrentRplId();
110 protected void UpdateSpawnPointName(RplId
id,
string name)
112 int itemId = m_SpawnPointSelector.GetItemId(
id);
113 m_SpawnPointSelector.SetItemName(itemId, name);
119 if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
120 AddSpawnPoint(spawnPoint);
123 protected void OnSpawnPointFactionChange(
SCR_SpawnPoint spawnPoint)
126 if (playerFaction && playerFaction.GetFactionKey() == spawnPoint.GetFactionKey())
127 AddSpawnPoint(spawnPoint);
129 RemoveSpawnPoint(spawnPoint);
132 protected void ClearSpawnPoints()
134 m_SpawnPointSelector.ClearAll();
138 void ShowAvailableSpawnPoints(
Faction faction)
145 array<SCR_SpawnPoint> infos =
SCR_SpawnPoint.GetSpawnPointsForFaction(faction.GetFactionKey());
148 SetSpawnPoint(RplId.Invalid());
155 if (info.IsSpawnPointVisibleForPlayer(pid))
160 void UpdateRelevantSpawnPoints()
162 array<SCR_SpawnPoint> spawnPoints = m_SpawnPointSelector.GetSpawnPointsInList();
163 PlayerController pc =
GetGame().GetPlayerController();
165 array<SCR_SpawnPoint> playerSpawnPoints =
SCR_SpawnPoint.GetSpawnPointsForFaction(plyFactionComp.GetAffiliatedFaction().GetFactionKey());
169 if (!sp.IsSpawnPointVisibleForPlayer(pc.GetPlayerId()))
170 RemoveSpawnPoint(sp);
175 if (spawnPoints.Contains(sp))
178 if (sp.IsSpawnPointVisibleForPlayer(pc.GetPlayerId()))
183 void SelectSpawnPointExt(RplId
id)
185 int itemId = m_SpawnPointSelector.GetItemId(
id);
187 m_SpawnPointSelector.SetCurrentItem(itemId);
190 ScriptInvoker GetOnSpawnPointSelected()
192 if (!m_OnSpawnPointSelected)
193 m_OnSpawnPointSelected =
new ScriptInvoker();
195 return m_OnSpawnPointSelected;
198 static ScriptInvoker SGetOnSpawnPointSelected()
200 if (!s_OnSpawnPointSelected)
201 s_OnSpawnPointSelected =
new ScriptInvoker();
203 return s_OnSpawnPointSelected;
206 RplId GetCurrentRplId()
208 return m_SpawnPointSelector.GetSpawnPointId(m_SpawnPointSelector.GetCurrentIndex());
211 bool IsSelectorFocused()
213 return m_SpawnPointSelector && m_SpawnPointSelector.IsFocused();