1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Manages Highlights on entities. Such as notification icons on Faction UI", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
17 protected ref ScriptInvoker Event_OnAddHighlight =
new ScriptInvoker;
18 protected ref ScriptInvoker Event_OnUpdateHighlight =
new ScriptInvoker;
19 protected ref ScriptInvoker Event_OnRemoveHighlight =
new ScriptInvoker;
22 protected bool m_bReplicationIsRunning;
25 protected ref map<SCR_EditableEntityComponent, EEditableEntityHighlight> m_HighlightedEntities =
new map<SCR_EditableEntityComponent, EEditableEntityHighlight>;
32 RplId entityID = Replication.FindId(entity);
37 if (m_HighlightedEntities.Find(entity, allHighlights))
40 if ((allHighlights & highlight))
44 allHighlights |= highlight;
47 m_HighlightedEntities.Set(entity, allHighlights);
48 Event_OnUpdateHighlight.Invoke(entity, allHighlights, GetHighlightCount(allHighlights));
51 Rpc(AddHighlightRpc, entityID, allHighlights);
58 allHighlights |= highlight;
61 m_HighlightedEntities.Insert(entity, allHighlights);
64 Rpc(AddHighlightToListRpc, entityID, allHighlights);
68 CleanupHighlightedMap();
71 Event_OnAddHighlight.Invoke(entity);
74 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
82 m_HighlightedEntities.Set(entity, allHighlights);
85 CleanupHighlightedMap();
88 Event_OnAddHighlight.Invoke(entity);
89 Event_OnUpdateHighlight.Invoke(entity, allHighlights, GetHighlightCount(allHighlights));
93 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
101 m_HighlightedEntities.Insert(entity, allHighlights);
104 CleanupHighlightedMap();
107 Event_OnAddHighlight.Invoke(entity);
116 RplId entityID = Replication.FindId(entity);
121 if (!m_HighlightedEntities.Find(entity, allHighlights))
125 if (!(allHighlights & highlight))
129 allHighlights &= ~highlight;
132 if (allHighlights == 0)
135 m_HighlightedEntities.Remove(entity);
138 Rpc(RemoveHighlightFromListRpc, entityID);
144 m_HighlightedEntities.Set(entity, allHighlights);
145 Event_OnUpdateHighlight.Invoke(entity, allHighlights, GetHighlightCount(allHighlights));
148 Rpc(RemoveHighlightRpc, entityID, allHighlights);
152 CleanupHighlightedMap();
155 Event_OnRemoveHighlight.Invoke(entity);
159 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
167 m_HighlightedEntities.Set(entity, allHighlights);
170 CleanupHighlightedMap();
173 Event_OnRemoveHighlight.Invoke(entity);
174 Event_OnUpdateHighlight.Invoke(entity, allHighlights, GetHighlightCount(allHighlights));
178 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
179 protected void RemoveHighlightFromListRpc(RplId entityID)
186 m_HighlightedEntities.Remove(entity);
189 CleanupHighlightedMap();
192 Event_OnRemoveHighlight.Invoke(entity);
203 m_HighlightedEntities.Remove(entity);
221 if (!m_HighlightedEntities.Find(entity, allHighlights))
224 return m_HighlightedEntities.Contains(entity);
241 if (!m_HighlightedEntities.Find(entity, allHighlights))
245 if ((allHighlights & (allHighlights - 1)) == 0)
247 highlight = allHighlights;
253 highlightAmount = GetHighlightCount(allHighlights);
272 if (!m_HighlightedEntities.Find(entity, allHighlights))
276 return (allHighlights & highlight);
282 array<int> highlightArray =
new array<int>;
283 SCR_Enum.BitToIntArray(highlight, highlightArray);
284 return highlightArray.Count();
290 if (!m_bReplicationIsRunning)
293 map<Faction, SCR_EditableFactionComponent> factionMap =
new map<Faction, SCR_EditableFactionComponent>;
294 m_DelegateFactionManager.GetFactionDelegates(factionMap);
296 foreach (
Faction faction, SCR_EditableFactionComponent editableFaction: factionMap)
298 if (editableFaction.GetFactionSpawnPointCount() == 0)
303 protected void OnFactionSpawnPointsUpdated(
Faction faction,
int factionSpawnPointCount)
305 if (!m_bReplicationIsRunning)
309 SCR_EditableFactionComponent factionEntity = m_DelegateFactionManager.GetFactionDelegate(faction);
314 if (factionSpawnPointCount == 0)
330 if (!m_bReplicationIsRunning)
333 map<Faction, SCR_EditableFactionComponent> factionMap =
new map<Faction, SCR_EditableFactionComponent>;
334 m_DelegateFactionManager.GetFactionDelegates(factionMap);
336 foreach (
Faction faction, SCR_EditableFactionComponent editableFaction: factionMap)
338 if (editableFaction.GetFactionTasksCount() == 0)
343 protected void OnFactionTasksUpdated(
Faction faction,
int factionTaskCount)
345 if (!m_bReplicationIsRunning)
349 SCR_EditableFactionComponent factionEntity = m_DelegateFactionManager.GetFactionDelegate(faction);
354 if (factionTaskCount == 0)
370 return Event_OnAddHighlight;
373 ScriptInvoker GetOnRemoveHighlight()
375 return Event_OnRemoveHighlight;
378 ScriptInvoker GetOnUpdateHighlight()
380 return Event_OnUpdateHighlight;
386 m_bReplicationIsRunning = Replication.IsRunning();
390 if (m_DelegateFactionManager)
392 FactionSpawnPointsInit();
395 map<Faction, SCR_EditableFactionComponent> factionMap =
new map<Faction, SCR_EditableFactionComponent>;
396 m_DelegateFactionManager.GetFactionDelegates(factionMap);
398 foreach (
Faction faction, SCR_EditableFactionComponent editableFaction: factionMap)
400 editableFaction.GetOnSpawnPointCountChanged().Insert(OnFactionSpawnPointsUpdated);
401 editableFaction.GetOnTaskCountChanged().Insert(OnFactionTasksUpdated);
408 if (m_DelegateFactionManager)
410 map<Faction, SCR_EditableFactionComponent> factionMap =
new map<Faction, SCR_EditableFactionComponent>;
411 m_DelegateFactionManager.GetFactionDelegates(factionMap);
413 foreach (
Faction faction, SCR_EditableFactionComponent editableFaction: factionMap)
415 editableFaction.GetOnSpawnPointCountChanged().Remove(OnFactionSpawnPointsUpdated);
416 editableFaction.GetOnTaskCountChanged().Remove(OnFactionTasksUpdated);
421 m_HighlightedEntities.Clear();