Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapMarkerSquadLeader.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Markers")]
4 {}
5 
6 //------------------------------------------------------------------------------------------------
8 class SCR_MapMarkerSquadLeader : SCR_MapMarkerEntity
9 {
10  [RplProp(onRplName: "OnPlayerIdUpdate")]
11  protected int m_PlayerID; // target ID, needed for visibility rules and fetching group
12 
13  const float SL_UPDATE_DELAY = 1; // seconds
14  const float ASPECT_RATIO_FLAG = 1.45; // temp -> force aspect ratio of a military symbol
15  const int SIZE_FLAG = 56; // temp -> required due to aspect ratio's need to be set
16 
17  bool m_bDoGroupTextUpdate; // group text update flag
18  protected bool m_bDoGroupSymbolUpdate; // group symbol update flag
19  protected SCR_AIGroup m_Group;
20  protected SCR_MapMarkerSquadLeaderComponent m_SquadLeaderWidgetComp;
21 
22  //------------------------------------------------------------------------------------------------
23  // RPL EVENTS
24  //------------------------------------------------------------------------------------------------
25  void OnPlayerIdUpdate()
26  {
27  PlayerController pController = GetGame().GetPlayerController();
28  if (!pController)
29  return;
30 
31  if (m_PlayerID == pController.GetPlayerId()) // if this is us, dont display
32  SetLocalVisible(false);
33  else
34  {
35  SetLocalVisible(true);
36  }
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  // API SERVER
41  //------------------------------------------------------------------------------------------------
42  void SetPlayerID(int id)
43  {
44  m_PlayerID = id;
45  m_MarkerFaction = SCR_FactionManager.SGetPlayerFaction(id);
46 
47  Replication.BumpMe();
48 
49  if (!System.IsConsoleApp())
50  OnPlayerIdUpdate();
51 
52  UpdateTarget();
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  // EVENTS & OTHERS
57  //------------------------------------------------------------------------------------------------
59  {
60  m_bDoGroupTextUpdate = true;
61  }
62 
63  //------------------------------------------------------------------------------------------------
65  {
66  return m_Group;
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  protected void AssignGroup()
71  {
73  if (!comp)
74  return;
75 
76  m_Group = comp.GetPlayerGroup(m_PlayerID);
77 
78  if (m_Group)
79  SCR_MapMarkerEntrySquadLeader.Cast(m_ConfigEntry).RegisterMarker(this, m_Group);
80  }
81 
82  //------------------------------------------------------------------------------------------------
85  protected void UpdateTarget()
86  {
87  IEntity ent = GetGame().GetPlayerManager().GetPlayerControlledEntity(m_PlayerID);
88  if (ent)
89  {
91  if (!charController.IsDead())
92  {
93  SetTarget(ent);
94  SetGlobalVisible(true);
95 
96  return;
97  }
98  }
99 
100  SetTarget(null);
101  SetGlobalVisible(false);
102  }
103 
104  //------------------------------------------------------------------------------------------------
106  protected void UpdateGroupMilitarySymbol()
107  {
108  if (!m_Group)
109  {
110  AssignGroup();
111  return;
112  }
113 
114  string company, platoon, squad, character, format;
115  m_Group.GetCallsigns(company, platoon, squad, character, format);
116 
117  SCR_Faction faction = SCR_Faction.Cast(m_Group.GetFaction());
118  if (faction)
119  {
120  string flag = m_Group.GetGroupFlag();
121  if (flag == string.Empty)
122  flag = faction.GetFlagName(0);
123 
124  SetImage(faction.GetGroupFlagImageSet(), flag);
125  }
126 
127  if (m_SquadLeaderWidgetComp)
128  m_SquadLeaderWidgetComp.SetImage(m_sImageset, m_sIconName, ASPECT_RATIO_FLAG, SIZE_FLAG);
129 
131  m_bDoGroupSymbolUpdate = false;
132  }
133 
134  //------------------------------------------------------------------------------------------------
136  protected void UpdateGroupText()
137  {
138  if (!m_Group)
139  {
140  AssignGroup();
141  return;
142  }
143 
144  string customName = m_Group.GetCustomName();
145  if (customName != string.Empty)
146  SetText(customName);
147  else
148  {
149  string company, platoon, squad, character, format;
150  m_Group.GetCallsigns(company, platoon, squad, character, format);
151 
152  SetText(WidgetManager.Translate(format, company, platoon, squad, character));
153  }
154 
155  if (m_SquadLeaderWidgetComp)
156  m_SquadLeaderWidgetComp.SetText(m_sText);
157 
158  m_bDoGroupTextUpdate = false;
159  }
160 
161  //------------------------------------------------------------------------------------------------
164  {
165  if (!m_wRoot)
166  return;
167 
168  if (m_Group.IsPlayerInGroup(GetGame().GetPlayerController().GetPlayerId()))
169  m_SquadLeaderWidgetComp.SetGroupActive(true, m_Group.GetFactionName());
170  else
171  m_SquadLeaderWidgetComp.SetGroupActive(false);
172  }
173 
174  //------------------------------------------------------------------------------------------------
176  protected void OnUserSettingsChanged()
177  {
178  m_bDoGroupTextUpdate = true;
179  }
180 
181  //------------------------------------------------------------------------------------------------
184  protected void OnFlagSelected()
185  {
186  m_bDoGroupSymbolUpdate = true;
187  }
188 
189  //------------------------------------------------------------------------------------------------
190  // OVERRIDES
191  //------------------------------------------------------------------------------------------------
192  override protected void OnMapLayerChanged(int layerID)
193  {
194  super.OnMapLayerChanged(layerID);
195 
196  if (m_SquadLeaderWidgetComp)
197  m_SquadLeaderWidgetComp.SetLayerID(layerID);
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  override void OnCreateMarker()
202  {
203  RplComponent rplComp = RplComponent.Cast(FindComponent(RplComponent));
204  if (rplComp.IsOwner()) // authority only
205  {
206  IEntity ent = GetGame().GetPlayerManager().GetPlayerControlledEntity(m_PlayerID);
207  if (ent)
208  SetTarget(ent);
209  }
210 
211  Faction markerFaction = SCR_FactionManager.SGetPlayerFaction(m_PlayerID);
212  Faction localFaction = SCR_FactionManager.SGetLocalPlayerFaction();
213  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
214  return;
215 
216  super.OnCreateMarker();
217 
218  m_bDoGroupSymbolUpdate = true;
219  m_bDoGroupTextUpdate = true;
220 
221  m_SquadLeaderWidgetComp = SCR_MapMarkerSquadLeaderComponent.Cast(m_MarkerWidgetComp);
222 
223  GetGame().OnUserSettingsChangedInvoker().Insert(OnUserSettingsChanged);
224  SCR_AIGroup.GetOnFlagSelected().Insert(OnFlagSelected);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  override void OnDelete()
229  {
230  super.OnDelete();
231 
232  GetGame().OnUserSettingsChangedInvoker().Remove(OnUserSettingsChanged);
233  SCR_AIGroup.GetOnFlagSelected().Remove(OnFlagSelected);
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  override void OnUpdate()
238  {
239  if (!m_wRoot)
240  return;
241 
242  super.OnUpdate();
243 
244  if (m_bDoGroupSymbolUpdate)
246 
247  if (m_bDoGroupTextUpdate)
248  UpdateGroupText();
249 
250  if (m_SquadLeaderWidgetComp.m_bIsHovered)
251  m_SquadLeaderWidgetComp.UpdateGroupInfoPosition(m_iScreenX, m_iScreenY);
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  override protected void EOnInit(IEntity owner)
256  {
257  super.EOnInit(owner);
258 
259  m_fUpdateDelay = SL_UPDATE_DELAY;
260  }
261 
262  //------------------------------------------------------------------------------------------------
264  {
265  if (m_ConfigEntry)
266  SCR_MapMarkerEntrySquadLeader.Cast(m_ConfigEntry).UnregisterMarker(m_Group);
267  }
268 }
m_fUpdateDelay
protected float m_fUpdateDelay
Definition: SCR_MotorExhaustEffectGeneralComponent.c:25
UpdateTarget
protected void UpdateTarget()
Definition: SCR_MapMarkerSquadLeader.c:85
OnMapLayerChanged
override protected void OnMapLayerChanged(int layerID)
Definition: SCR_MapMarkerSquadLeader.c:192
SetTextUpdate
void SetTextUpdate()
Definition: SCR_MapMarkerSquadLeader.c:58
SetImage
void SetImage(BackendImage image)
image can be null
Definition: SCR_BackendImageComponent.c:36
OnUpdate
override void OnUpdate()
Definition: SCR_MapMarkerSquadLeader.c:237
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
OnFlagSelected
protected void OnFlagSelected()
Definition: SCR_MapMarkerSquadLeader.c:184
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
~SCR_MapMarkerSquadLeader
void ~SCR_MapMarkerSquadLeader()
Definition: SCR_MapMarkerSquadLeader.c:263
UpdateGroupMilitarySymbol
protected void UpdateGroupMilitarySymbol()
Set military symbol image, can change during lifetime.
Definition: SCR_MapMarkerSquadLeader.c:106
m_Group
protected SCR_AIGroup m_Group
Definition: SCR_CallsignGroupComponent.c:10
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
AssignGroup
protected void AssignGroup()
Definition: SCR_MapMarkerSquadLeader.c:70
SCR_MapMarkerEntity
Definition: SCR_MapMarkerEntity.c:10
GetGroup
SCR_AIGroup GetGroup()
Definition: SCR_MapMarkerSquadLeader.c:64
SetPlayerID
void SetPlayerID(int id)
Definition: SCR_MapMarkerSquadLeader.c:42
OnUserSettingsChanged
protected void OnUserSettingsChanged()
Update names when user settings are changed (f.e. xbox UGC)
Definition: SCR_MapMarkerSquadLeader.c:176
RplProp
SCR_MapMarkerSquadLeaderClass SCR_MapMarkerEntityClass RplProp(onRplName:"OnPlayerIdUpdate")
Dynamic map marker -> squad leader.
Definition: SCR_MapMarkerSquadLeader.c:10
SCR_MapMarkerEntityClass
Definition: SCR_MapMarkerEntity.c:3
EOnInit
override protected void EOnInit(IEntity owner)
Initialise this component with data from FactionsManager.
Definition: SCR_MapMarkerSquadLeader.c:255
SCR_MapMarkerSquadLeaderClass
Definition: SCR_MapMarkerSquadLeader.c:3
Faction
Definition: Faction.c:12
OnDelete
override void OnDelete()
Definition: SCR_MapMarkerSquadLeader.c:228
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_MapMarkerEntrySquadLeader
Squad leader marker entry.
Definition: SCR_MapMarkerEntrySquadLeader.c:4
UpdateGroupText
protected void UpdateGroupText()
Set group text, can change during lifetime.
Definition: SCR_MapMarkerSquadLeader.c:136
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_MapMarkerSquadLeaderComponent
Definition: SCR_MapMarkerSquadLeaderComponent.c:1
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
UpdatePlayerAffiliation
void UpdatePlayerAffiliation()
Check whether we are in a squad and if it should be visible on map.
Definition: SCR_MapMarkerSquadLeader.c:163
SCR_Faction
Definition: SCR_Faction.c:6
OnCreateMarker
override void OnCreateMarker()
Definition: SCR_MapMarkerSquadLeader.c:201
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
m_sText
class SCR_BaseEditorAttribute m_sText
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180