Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapMarkerEntrySquadLeader.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
5 {
6  protected SCR_GroupsManagerComponent m_GroupsManager;
7  protected SCR_MapToolEntry m_ToolMenuEntry;
8  protected SCR_AIGroup m_bCurrentSquad; // saved active squad of the current player
9 
10  protected ref map<SCR_AIGroup, SCR_MapMarkerSquadLeader> m_mGroupMarkers = new map<SCR_AIGroup, SCR_MapMarkerSquadLeader>();
11 
12  //------------------------------------------------------------------------------------------------
14  void RegisterMarker(SCR_MapMarkerSquadLeader marker, SCR_AIGroup group)
15  {
16  m_mGroupMarkers.Insert(group, marker);
17  }
18 
19  //------------------------------------------------------------------------------------------------
20  void UnregisterMarker(SCR_AIGroup group)
21  {
22  m_mGroupMarkers.Remove(group);
23  }
24 
25  //------------------------------------------------------------------------------------------------
27  protected void FocusCurrentSquad()
28  {
29  if (!m_bCurrentSquad || !m_ToolMenuEntry.IsEntryEnabled())
30  return;
31 
32  SCR_MapMarkerSquadLeader leaderEnt = m_mGroupMarkers.Get(m_bCurrentSquad);
33  if (leaderEnt)
34  {
35  vector wPos = leaderEnt.GetWorldPos();
36  int screenX, screenY;
37 
38  SCR_MapEntity.GetMapInstance().WorldToScreen(wPos[0], wPos[2], screenX, screenY);
39  SCR_MapEntity.GetMapInstance().PanSmooth(screenX, screenY);
40  }
41  }
42 
43  //------------------------------------------------------------------------------------------------
45  protected void UpdateToolEntryState()
46  {
47  if (m_ToolMenuEntry)
48  {
49  if (m_bCurrentSquad != null && GetGame().GetPlayerController().GetPlayerId() != m_bCurrentSquad.GetLeaderID()) // currently squad in squad && we are not the leader
50  m_ToolMenuEntry.SetEnabled(true);
51  else
52  m_ToolMenuEntry.SetEnabled(false);
53  }
54  }
55 
56  //------------------------------------------------------------------------------------------------
58  protected void OnPlayableGroupCreated(SCR_AIGroup group)
59  {
60  SCR_MapMarkerSquadLeader marker = SCR_MapMarkerSquadLeader.Cast(m_MarkerMgr.InsertDynamicMarker(SCR_EMapMarkerType.SQUAD_LEADER, group));
61  if (!marker)
62  return;
63 
64  marker.SetFaction(group.GetFaction());
65  RegisterMarker(marker, group);
66  }
67 
68  //------------------------------------------------------------------------------------------------
70  protected void OnPlayableGroupRemoved(SCR_AIGroup group)
71  {
72  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
73  if (marker)
74  m_MarkerMgr.RemoveDynamicMarker(marker);
75 
76  UnregisterMarker(group);
77  }
78 
79  //------------------------------------------------------------------------------------------------
81  protected void OnPlayerLeaderChanged(int groupID, int playerId)
82  {
83  SCR_AIGroup group = m_GroupsManager.FindGroup(groupID);
84  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
85  if (marker)
86  marker.SetPlayerID(playerId);
87  }
88 
89  //------------------------------------------------------------------------------------------------
91  protected void OnPlayerAdded(SCR_AIGroup group, int playerId)
92  {
93  PlayerController playerController = GetGame().GetPlayerController();
94  if (!playerController)
95  return;
96 
97  if (group.IsPlayerInGroup(playerController.GetPlayerId() == playerId))
98  {
99  m_bCurrentSquad = group;
100  UpdateToolEntryState();
101 
102  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
103  if (marker)
104  marker.UpdatePlayerAffiliation();
105  }
106  }
107 
108  //------------------------------------------------------------------------------------------------
110  protected void OnPlayerRemoved(SCR_AIGroup group, int playerId)
111  {
112  PlayerController playerController = GetGame().GetPlayerController();
113  if (!playerController)
114  return;
115 
116  if (m_bCurrentSquad == group && group.IsPlayerInGroup(playerController.GetPlayerId() == playerId))
117  {
118  m_bCurrentSquad = null;
119  UpdateToolEntryState();
120 
121  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
122  if (marker)
123  marker.UpdatePlayerAffiliation();
124  }
125  }
126 
127  //------------------------------------------------------------------------------------------------
129  protected void OnPlayerSpawned(int playerId, IEntity player)
130  {
131  UpdateMarkerTarget(playerId);
132  }
133 
134  //------------------------------------------------------------------------------------------------
136  protected void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
137  {
138  UpdateMarkerTarget(playerId);
139  }
140 
141  //------------------------------------------------------------------------------------------------
143  protected void OnPlayerDeleted(int playerId, IEntity player)
144  {
145  UpdateMarkerTarget(playerId);
146  }
147 
148  //------------------------------------------------------------------------------------------------
150  protected void OnGroupCustomNameChanged(SCR_AIGroup group)
151  {
152  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
153  if (marker)
154  marker.SetTextUpdate();
155  }
156 
157  //------------------------------------------------------------------------------------------------
159  protected void UpdateMarkerTarget(int playerID)
160  {
161  SCR_AIGroup group = m_GroupsManager.GetPlayerGroup(playerID);
162  if (!group || !group.IsPlayerLeader(playerID)) // ignore if not leader
163  return;
164 
165  SCR_MapMarkerSquadLeader marker = m_mGroupMarkers.Get(group);
166  if (marker)
167  marker.SetPlayerID(playerID);
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  override SCR_EMapMarkerType GetMarkerType()
172  {
173  return SCR_EMapMarkerType.SQUAD_LEADER;
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  override void InitServerLogic()
178  {
179  super.InitServerLogic();
180 
182  if (!gameMode)
183  return;
184 
185  m_GroupsManager = SCR_GroupsManagerComponent.GetInstance();
186  m_GroupsManager.GetOnPlayableGroupCreated().Insert(OnPlayableGroupCreated);
187  m_GroupsManager.GetOnPlayableGroupRemoved().Insert(OnPlayableGroupRemoved);
188 
189  SCR_AIGroup.GetOnPlayerLeaderChanged().Insert(OnPlayerLeaderChanged);
190 
191  gameMode.GetOnPlayerSpawned().Insert(OnPlayerSpawned);
192  gameMode.GetOnPlayerKilled().Insert(OnPlayerKilled);
193  gameMode.GetOnPlayerDeleted().Insert(OnPlayerDeleted);
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  override void InitClientLogic()
198  {
199  SCR_AIGroup.GetOnCustomNameChanged().Insert(OnGroupCustomNameChanged);
200  SCR_AIGroup.GetOnPlayerAdded().Insert(OnPlayerAdded);
201  SCR_AIGroup.GetOnPlayerRemoved().Insert(OnPlayerRemoved);
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  override void OnMapLayerChangedDynamic(notnull SCR_MapMarkerDynamicWComponent widgetComp, int layerID)
206  {
207  if (layerID > 1)
208  widgetComp.SetTextVisible(false);
209  else
210  widgetComp.SetTextVisible(true);
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  override void OnMapOpen(notnull SCR_MapEntity mapEnt, notnull SCR_MapMarkersUI markerUIComp)
215  {
216  super.OnMapOpen(mapEnt, markerUIComp);
217 
218  UpdateToolEntryState();
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  override void OnMapInit(notnull SCR_MapEntity mapEnt, notnull SCR_MapMarkersUI markerUIComp)
223  {
224  super.OnMapInit(mapEnt, markerUIComp);
225 
226  SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(mapEnt.GetMapUIComponent(SCR_MapToolMenuUI));
227  if (!toolMenu)
228  return;
229 
230  m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry("{3262679C50EF4F01}UI/Textures/Icons/icons_wrapperUI.imageset", "squad", 20); // add to menu
231  m_ToolMenuEntry.m_OnClick.Insert(FocusCurrentSquad);
232  m_ToolMenuEntry.SetEnabled(true);
233  }
234 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_MapMarkerDynamicWComponent
Attached to root of marker dynamic base layout.
Definition: SCR_MapMarkerDynamicWComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapDrawingUI.c:182
SCR_MapMarkerTitle
Definition: SCR_MapMarkerEntryPlaced.c:189
SCR_MapMarkerEntryDynamic
Marker dynamic entry base.
Definition: SCR_MapMarkerEntryDynamic.c:4
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
Instigator
Definition: Instigator.c:6
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_EMapMarkerType
SCR_EMapMarkerType
Definition: SCR_MapMarkerConfig.c:5
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_MapMarkersUI
Markers UI map component.
Definition: SCR_MapMarkersUI.c:6
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
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468