Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MapMarkerSquadLeader.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2[EntityEditorProps(category: "GameScripted/Markers")]
4{
5 [Attribute(defvalue: "1", desc:"Can show other squad leaders to this squad leader")]
7
8 [Attribute(defvalue: "1", desc:"Can show other squad leaders to this squad member, member will see only own leader")]
10
11 //------------------------------------------------------------------------------------------------
16
17 //------------------------------------------------------------------------------------------------
22}
23
24//------------------------------------------------------------------------------------------------
26class SCR_MapMarkerSquadLeader : SCR_MapMarkerEntity
27{
28 [RplProp(onRplName: "OnPlayerIdUpdate")]
29 protected int m_PlayerID; // target ID, needed for visibility rules and fetching group
31 bool m_bDoGroupTextUpdate; // group text update flag
32 protected bool m_bDoGroupSymbolUpdate; // group symbol update flag
34 protected SCR_MapMarkerSquadLeaderComponent m_SquadLeaderWidgetComp;
35 protected bool m_bDoLocalVisibilityUpdate;
37 //------------------------------------------------------------------------------------------------
38 // RPL EVENTS
39 //------------------------------------------------------------------------------------------------
40 void OnPlayerIdUpdate()
41 {
42 m_bDoLocalVisibilityUpdate = true;
43 }
44
45 //------------------------------------------------------------------------------------------------
46 // API SERVER
47 //------------------------------------------------------------------------------------------------
48 void SetPlayerID(int id)
49 {
50 m_PlayerID = id;
51 m_MarkerFaction = SCR_FactionManager.SGetPlayerFaction(id);
52
53 Replication.BumpMe();
54
55 if (!System.IsConsoleApp())
57
59 }
60
61 //------------------------------------------------------------------------------------------------
62 // EVENTS & OTHERS
63 //------------------------------------------------------------------------------------------------
65 {
66 m_bDoGroupTextUpdate = true;
67 }
68
69 //------------------------------------------------------------------------------------------------
71 {
72 return m_Group;
73 }
74
75 //------------------------------------------------------------------------------------------------
76 protected void AssignGroup()
77 {
79 if (!comp)
80 return;
81
82 m_Group = comp.GetPlayerGroup(m_PlayerID);
83
84 if (m_Group)
85 SCR_MapMarkerEntrySquadLeader.Cast(m_ConfigEntry).RegisterMarker(this, m_Group);
86 }
87
88 //------------------------------------------------------------------------------------------------
91 protected void UpdateTarget()
92 {
93 IEntity ent = GetGame().GetPlayerManager().GetPlayerControlledEntity(m_PlayerID);
94 if (ent)
95 {
97 if (!charController.IsDead())
98 {
99 SetTarget(ent);
100 SetGlobalVisible(true);
101
102 return;
103 }
104 }
105
106 SetTarget(null);
107 SetGlobalVisible(false);
108 }
109
110 //------------------------------------------------------------------------------------------------
113 {
114 if (!m_Group)
115 {
116 AssignGroup();
117 return;
118 }
119
120 string company, platoon, squad, character, format;
121 m_Group.GetCallsigns(company, platoon, squad, character, format);
122
123 SCR_Faction faction = SCR_Faction.Cast(m_Group.GetFaction());
124 if (faction)
125 {
126 string flag = m_Group.GetGroupFlag();
127 if (flag == string.Empty)
128 flag = faction.GetFlagName(0);
129
130 SetImage(faction.GetGroupFlagImageSet(), flag);
131 }
132
133 if (m_SquadLeaderWidgetComp)
134 m_SquadLeaderWidgetComp.SetImage(m_sImageset, m_sIconName);
135
137 m_bDoGroupSymbolUpdate = false;
138 }
139
140 //------------------------------------------------------------------------------------------------
142 protected void UpdateGroupText()
143 {
144 if (!m_Group)
145 {
146 AssignGroup();
147 return;
148 }
149
150 // This function can only be used in UI menu, where to change the language you need to close and open the shown menu, so it will be renewed.
152
153 if (m_SquadLeaderWidgetComp)
154 m_SquadLeaderWidgetComp.SetText(m_sText);
155
156 m_bDoGroupTextUpdate = false;
157 }
158
159 //------------------------------------------------------------------------------------------------
162 {
163 if (!m_wRoot)
164 return;
165
166 if (m_Group.IsPlayerInGroup(GetGame().GetPlayerController().GetPlayerId()))
167 m_SquadLeaderWidgetComp.SetGroupActive(true, m_Group.GetFactionName());
168 else
169 m_SquadLeaderWidgetComp.SetGroupActive(false);
170 }
171
172 //------------------------------------------------------------------------------------------------
175 {
176 m_bDoLocalVisibilityUpdate = false;
177
178 PlayerController pController = GetGame().GetPlayerController();
179 if (!pController)
180 return;
181
182 if (m_PlayerID == pController.GetPlayerId())
183 {
184 // if this is us, dont display
185 SetLocalVisible(false);
186 return;
187 }
188
189 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
190 if (!groupManager)
191 return;
192
193 SCR_AIGroup localPlayerGroup = groupManager.GetPlayerGroup(pController.GetPlayerId());
194 if (!localPlayerGroup)
195 {
196 SetLocalVisible(false);
197 return;
198 }
199
200 bool isLocalPlayerLeader = localPlayerGroup.IsPlayerLeader(pController.GetPlayerId());
201
202 if (isLocalPlayerLeader && CanLeaderSeeOtherLeaders())
203 {
204 SetLocalVisible(true);
205 return;
206 }
207
208 if (!isLocalPlayerLeader && (CanMemberSeeOtherLeaders() || localPlayerGroup.IsPlayerInGroup(m_PlayerID)))
209 {
210 SetLocalVisible(true);
211 return;
212 }
213
214 SetLocalVisible(false);
215 }
216
217 //------------------------------------------------------------------------------------------------
218 protected bool CanLeaderSeeOtherLeaders()
219 {
220 if (SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander())
221 return true;
222
223 SCR_MapMarkerSquadLeaderClass prefabData = SCR_MapMarkerSquadLeaderClass.Cast(GetPrefabData());
224 if (!prefabData)
225 return true;
226
227 return prefabData.CanLeaderSeeOtherLeaders();
228 }
229
230 //------------------------------------------------------------------------------------------------
231 protected bool CanMemberSeeOtherLeaders()
232 {
233 if (SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander())
234 return true;
235
236 SCR_MapMarkerSquadLeaderClass prefabData = SCR_MapMarkerSquadLeaderClass.Cast(GetPrefabData());
237 if (!prefabData)
238 return true;
239
240 return prefabData.CanMemberSeeOtherLeaders();
241 }
242
243 //------------------------------------------------------------------------------------------------
244 protected void OnPlayerLeaderChanged(int groupID, int playerId)
245 {
246 if (m_PlayerID <= 0)
247 return;
248
249 m_bDoLocalVisibilityUpdate = true;
250 }
251
252 //------------------------------------------------------------------------------------------------
253 protected void OnPlayerAdded(SCR_AIGroup group, int playerId)
254 {
255 if (m_PlayerID <= 0)
256 return;
257
258 m_bDoLocalVisibilityUpdate = true;
259 }
260
261 //------------------------------------------------------------------------------------------------
262 protected void OnFactionCommanderChanged(SCR_Faction faction, int commanderPlayerId)
263 {
264 if (!faction || faction != SCR_FactionManager.SGetLocalPlayerFaction())
265 return;
266
267 m_bDoLocalVisibilityUpdate = true
268 }
269
270 //------------------------------------------------------------------------------------------------
272 protected void OnUserSettingsChanged()
273 {
274 m_bDoGroupTextUpdate = true;
275 }
276
277 //------------------------------------------------------------------------------------------------
280 protected void OnFlagSelected()
281 {
282 m_bDoGroupSymbolUpdate = true;
283 }
284
285 //------------------------------------------------------------------------------------------------
286 // OVERRIDES
287 //------------------------------------------------------------------------------------------------
288 override protected void OnMapLayerChanged(int layerID)
289 {
290 super.OnMapLayerChanged(layerID);
291
292 if (m_SquadLeaderWidgetComp)
293 m_SquadLeaderWidgetComp.SetLayerID(layerID);
294 }
295
296 //------------------------------------------------------------------------------------------------
297 override void OnCreateMarker()
298 {
299 RplComponent rplComp = RplComponent.Cast(FindComponent(RplComponent));
300 if (rplComp.IsOwner()) // authority only
301 {
302 IEntity ent = GetGame().GetPlayerManager().GetPlayerControlledEntity(m_PlayerID);
303 if (ent)
304 SetTarget(ent);
305 }
306
307 Faction markerFaction = SCR_FactionManager.SGetPlayerFaction(m_PlayerID);
308 Faction localFaction = SCR_FactionManager.SGetLocalPlayerFaction();
309 if (!localFaction || localFaction.IsFactionEnemy(markerFaction)) // markers could still get streamed in rare cases due to distance based streaming, in which case we check for faction and dont display
310 return;
311
312 super.OnCreateMarker();
313
314 m_bDoGroupSymbolUpdate = true;
315 m_bDoGroupTextUpdate = true;
316
317 m_SquadLeaderWidgetComp = SCR_MapMarkerSquadLeaderComponent.Cast(m_MarkerWidgetComp);
318
319 GetGame().OnUserSettingsChangedInvoker().Insert(OnUserSettingsChanged);
321 }
322
323 //------------------------------------------------------------------------------------------------
324 override void OnDelete()
325 {
326 super.OnDelete();
327
328 GetGame().OnUserSettingsChangedInvoker().Remove(OnUserSettingsChanged);
330 }
331
332 //------------------------------------------------------------------------------------------------
333 override void OnUpdate()
334 {
335 // updates only if the marker is visible and when the map is open
336 if (m_bDoLocalVisibilityUpdate)
338
339 if (!m_wRoot)
340 return;
341
342 super.OnUpdate();
343
344 if (m_bDoGroupSymbolUpdate)
346
347 if (m_bDoGroupTextUpdate)
349
350 if (m_SquadLeaderWidgetComp.m_bIsHovered)
351 m_SquadLeaderWidgetComp.UpdateGroupInfoPosition(m_iScreenX, m_iScreenY);
352 }
353
354 //------------------------------------------------------------------------------------------------
355 override protected void EOnInit(IEntity owner)
356 {
357 super.EOnInit(owner);
358
359 if (RplSession.Mode() == RplMode.Dedicated)
360 return;
361
364
365 SCR_FactionCommanderHandlerComponent factionCommanderHandler = SCR_FactionCommanderHandlerComponent.GetInstance();
366 if (factionCommanderHandler)
367 factionCommanderHandler.GetOnFactionCommanderChanged().Insert(OnFactionCommanderChanged);
368 }
369
370 //------------------------------------------------------------------------------------------------
372 {
373 if (m_ConfigEntry)
375
378
379 SCR_FactionCommanderHandlerComponent factionCommanderHandler = SCR_FactionCommanderHandlerComponent.GetInstance();
380 if (factionCommanderHandler)
381 factionCommanderHandler.GetOnFactionCommanderChanged().Remove(OnFactionCommanderChanged);
382 }
383}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
SCR_AIGroupSettingsComponentClass m_Group
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_AIGroup GetGroup()
void OnFactionCommanderChanged(SCR_Faction faction, int commanderPlayerId)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_FactionManager(IEntitySource src, IEntity parent)
Widget m_wRoot
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void UpdateLocalVisibility()
Check whether we are in a squad and if it should be visible on map.
void OnFlagSelected()
void ~SCR_MapMarkerSquadLeader()
void OnPlayerAdded(SCR_AIGroup group, int playerId)
void OnUserSettingsChanged()
Update names when user settings are changed (f.e. xbox UGC).
bool CanMemberSeeOtherLeaders()
void UpdatePlayerAffiliation()
Check whether we are in a squad and if it should be visible on map.
bool CanLeaderSeeOtherLeaders()
void AssignGroup()
void UpdateTarget()
void SetTextUpdate()
void OnPlayerLeaderChanged(int groupID, int playerId)
void UpdateGroupMilitarySymbol()
Set military symbol image, can change during lifetime.
void UpdateGroupText()
Set group text, can change during lifetime.
void OnPlayerIdUpdate()
Rpl event when m_iPlayerID is updated.
void SetPlayerID(int playerID)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external EntityPrefabData GetPrefabData()
Main replication API.
Definition Replication.c:14
bool IsPlayerLeader(int playerID)
static ScriptInvoker GetOnPlayerLeaderChanged()
static ScriptInvoker GetOnPlayerAdded()
static ScriptInvoker GetOnFlagSelected()
bool IsPlayerInGroup(int playerID)
ResourceName GetGroupFlagImageSet()
ResourceName GetFlagName(int index)
static string GetTranslatedGroupNameAndRoleName(notnull SCR_AIGroup group)
void OnMapLayerChanged(int layerID)
void EOnInit(IEntity owner)
void SetTarget(IEntity target)
Set entity this marker is tracking.
void OnUpdate()
Called from SCR_MapMarkerManagerComponent.
void SetLocalVisible(bool state)
void SetGlobalVisible(bool state)
void SetText(string text)
void OnCreateMarker()
Fetch marker definition from config & create widget.
void SetImage(string imageset, string icon)
Squad leader marker entry.
void RegisterMarker(SCR_MapMarkerSquadLeader marker, SCR_AIGroup group)
Register marker here so it can be fetched from the map.
void UnregisterMarker(SCR_AIGroup group)
void UpdateGroupInfoPosition(int screenX, int screenY)
void SetGroupActive(bool state, string factionName=string.Empty)
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()
string m_sText
Definition EnWidgets.c:82