10 [
Attribute(
"",
UIWidgets.ResourcePickerThumbnail,
"Entity to spawn as communication entity.",
"et")]
15 private SCR_FiringRangeScoringComponent m_ScoringSystem;
16 private ref array<int> m_aPlayerScores =
new array<int>;
17 private ref array<int> m_aPlayerScoresMax =
new array<int>;
18 private ref array<string> m_aPlayerNames =
new array<string>;
19 private ref array<SCR_PlayerScoreInfoFiringRange> m_aAllPlayersInfo =
new array<SCR_PlayerScoreInfoFiringRange>;
20 private ref array<Widget> m_aPlayerWidgets =
new array<Widget>;
22 private ref array<int> m_aPlayersInArea =
new array<int>;
25 private ref array<IEntity> m_aFiringLineControllers =
new array<IEntity>;
27 private int m_iLocalPlayerID = -1;
28 private int m_iLastSelectedTargetId = -1;
29 private int m_iSelectedIndex = -1;
35 private RplComponent m_RplComponent;
37 private int m_iPlayersInGameCount = -1;
38 private int m_iPlayersInAreaCount = -1;
43 void ClearPlayerScore(
int playerID)
53 m_ScoringSystem.ClearScore(playerID);
57 void CountPlayerScore(
int scoringPlayer,
int scorePoints)
67 m_ScoringSystem.AddScore(scoringPlayer,scorePoints);
71 void SetPlayerScoreMax(
int playerID,
float maxScore)
81 m_ScoringSystem.SetScoreMax(playerID,maxScore);
85 void UpdateScoreboardData()
90 if (m_aPlayerWidgets.IsEmpty())
93 if (m_aPlayerWidgets.Count() != m_aAllPlayersInfo.Count())
96 foreach (
int i, SCR_PlayerScoreInfoFiringRange info : m_aAllPlayersInfo)
98 TextWidget nameWidget = TextWidget.Cast(m_aPlayerWidgets[i].FindAnyWidget(
"Name"));
100 nameWidget.SetText(info.GetName());
102 TextWidget scoreWidget = TextWidget.Cast(m_aPlayerWidgets[i].FindAnyWidget(
"Score"));
104 scoreWidget.SetText(info.GetScore(m_ScoringSystem).ToString());
107 TextWidget maxScoreWidget = TextWidget.Cast(m_aPlayerWidgets[i].FindAnyWidget(
"MaxScore"));
109 maxScoreWidget.SetText(info.GetScoreMax().ToString());
114 int GetHighScoreInfo(array<SCR_PlayerScoreInfoFiringRange> infos)
116 int highScore =
int.MIN;
119 foreach (
int i, SCR_PlayerScoreInfoFiringRange info : infos)
123 int score = info.GetScore();
124 if (score > highScore)
138 int count = m_aAllPlayersInfo.Count();
139 if (count != m_aPlayerScores.Count())
142 m_aPlayerScores.Clear();
143 foreach (SCR_PlayerScoreInfoFiringRange info : m_aAllPlayersInfo)
148 score = info.GetScore();
151 m_aPlayerScores.Insert(score);
157 bool changed =
false;
158 for (
int i = 0; i < count; i++)
160 SCR_PlayerScoreInfoFiringRange info = m_aAllPlayersInfo.Get(i);
164 int score = info.GetScore();
165 if (score != m_aPlayerScores.Get(i))
167 m_aPlayerScores.Set(i, score);
176 bool ScoreMaxChanged()
178 int count = m_aAllPlayersInfo.Count();
179 if (count != m_aPlayerScoresMax.Count())
182 m_aPlayerScoresMax.Clear();
183 foreach (SCR_PlayerScoreInfoFiringRange info : m_aAllPlayersInfo)
185 int scoreMax = -1000;
188 scoreMax = info.GetScoreMax();
191 m_aPlayerScoresMax.Insert(scoreMax);
197 bool changed =
false;
198 for (
int i = 0; i < count; i++)
200 SCR_PlayerScoreInfoFiringRange info = m_aAllPlayersInfo.Get(i);
204 int scoreMax = info.GetScoreMax();
205 if (scoreMax != m_aPlayerScoresMax.Get(i))
207 m_aPlayerScoresMax.Set(i, scoreMax);
218 int count = m_aAllPlayersInfo.Count();
219 if (count != m_aPlayerNames.Count())
222 m_aPlayerNames.Clear();
223 foreach (SCR_PlayerScoreInfoFiringRange info : m_aAllPlayersInfo)
227 name = info.GetName();
229 m_aPlayerNames.Insert(name);
235 bool changed =
false;
236 for (
int i = 0; i < count; i++)
238 SCR_PlayerScoreInfoFiringRange info = m_aAllPlayersInfo.Get(i);
242 string name = info.GetName();
243 if (name != m_aPlayerNames.Get(i))
245 m_aPlayerNames.Set(i, name);
255 bool PlayerCountChangedInArea()
258 if (!m_aPlayersInArea)
262 int currentPlayersCountInArea = m_aPlayersInArea.Count();
263 if (currentPlayersCountInArea == m_iPlayersInAreaCount)
266 m_iPlayersInAreaCount = currentPlayersCountInArea;
273 override void EOnFrame(
IEntity owner,
float timeSlice)
276 if (!m_ScoringSystem)
279 m_ScoringSystem.GetAllPlayersScoreInfo(m_aAllPlayersInfo);
281 if (PlayerCountChangedInArea())
284 UpdateScoreboardData();
287 if (ScoreChanged() || NameChanged() || ScoreMaxChanged())
288 UpdateScoreboardData();
295 int iLocalPlayerID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
296 RegisterPlayerInArea(iLocalPlayerID);
299 IEntity playerEnt = SCR_PlayerController.GetLocalControlledEntity();
301 if (playerEnt == ent)
304 m_wRoot =
GetGame().GetWorkspace().CreateWidgets(
"{1B8C7223B314408B}UI/layouts/HUD/FiringRangeScoreboard/FireRangeTable.layout");
308 m_wTable =
m_wRoot.FindAnyWidget(
"Table");
315 int iLocalPlayerID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
316 RemovePlayerFromArea(iLocalPlayerID);
319 int playerID = SCR_PlayerController.GetLocalPlayerId();
322 IEntity playerEnt = SCR_PlayerController.GetLocalControlledEntity();
324 if (playerEnt == ent)
327 PlayerController playerController =
GetGame().GetPlayerController();
328 if (!playerController)
332 SCR_FiringRangeNetworkEntity firingRangeNetworkEntity = SCR_FiringRangeNetworkEntity.GetInstance();
333 if (!firingRangeNetworkEntity)
343 m_RplComponent = RplComponent.Cast(FindComponent(RplComponent));
345 return (m_RplComponent && m_RplComponent.IsProxy());
355 foreach (Widget w : m_aPlayerWidgets)
357 w.RemoveFromHierarchy();
359 m_aPlayerWidgets.Clear();
362 foreach (SCR_PlayerScoreInfoFiringRange info : m_aAllPlayersInfo)
364 Widget w =
GetGame().GetWorkspace().CreateWidgets(
"{8643D226A0A0A299}UI/layouts/HUD/FiringRangeScoreboard/FireRangeRow.layout", m_wTable);
365 m_aPlayerWidgets.Insert(w);
368 int id = info.GetPlayerID();
369 if (!IsPlayerInFiringRangeArea(
id))
374 UpdateScoreboardData();
378 override void EOnInit(
IEntity owner)
388 m_ScoringSystem = SCR_FiringRangeScoringComponent.Cast(owner.
FindComponent(SCR_FiringRangeScoringComponent));
394 array<int> playerIds =
new array<int>();
395 GetGame().GetPlayerManager().GetPlayers(playerIds);
397 foreach (
int id : playerIds)
399 SpawnCommunicationPrefab(
id);
407 void RegisterFiringRangeController(
IEntity firingLineController)
409 m_aFiringLineControllers.Insert(firingLineController);
414 void RemoveAssignedPlayerFromFireline(
int playerID)
417 foreach (
IEntity currentElement: m_aFiringLineControllers)
419 SCR_FiringRangeController controller = SCR_FiringRangeController.Cast(currentElement);
420 if (controller.GetFiringLineOwnerId() == playerID)
421 controller.BackToDefaultTarget();
429 return GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
434 void RegisterPlayerInArea(
int playerID)
436 m_aPlayersInArea.Insert(playerID);
437 Replication.BumpMe();
442 void RemovePlayerFromArea(
int playerID)
444 m_aPlayersInArea.RemoveItem(playerID);
445 Replication.BumpMe();
453 bool IsPlayerInFiringRangeArea(
int playerID)
455 if (m_aPlayersInArea.Find(playerID) != -1)
483 string GetPlayerName(
IEntity ent)
485 auto pm =
GetGame().GetPlayerManager();
486 int iPlayerID = pm.GetPlayerIdFromControlledEntity(ent);
487 return SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(iPlayerID);
491 void SpawnCommunicationPrefab(
int playerID)
494 Resource resource = Resource.Load(m_ComEnt);
495 if (!resource.IsValid())
502 RplComponent rpl = RplComponent.Cast(ent.
FindComponent(RplComponent));
506 SCR_FiringRangeNetworkEntity firingRangeNetworkEntity = SCR_FiringRangeNetworkEntity.Cast(ent);
507 if (!firingRangeNetworkEntity)
510 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
511 if (!playerController)
514 RplIdentity playerRplID = playerController.GetRplIdentity();
515 if (playerRplID == Replication.INVALID_IDENTITY)
518 rpl.Give(playerRplID);
526 void AddIndicator(vector localCoordOfHit, vector localVectorOfHit,
IEntity pOwnerEntity)
531 if (!firingRangeController)
535 Rpc(
RpcAsk_AddIndicator, Replication.FindItemId(firingRangeController), localCoordOfHit, localVectorOfHit);
536 RpcAsk_AddIndicator(Replication.FindItemId(firingRangeController),localCoordOfHit,localVectorOfHit);
540 void RemoveIndicators(
RplId controllerReplicationId)
585 if (localPlayerID == playerID)
588 m_aPlayerWidgets.Clear();
618 Print(
"Master-only method (SCR_FiringRangeController." + methodName +
") called on proxy. Some functionality might be broekn!",
LogLevel.WARNING);