Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerDelegateEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 };
5 
10 {
11  [Attribute(params: "et")]
12  protected ResourceName m_PlayerDelegatePrefab;
13 
14  protected int m_iPlayerID;
15  protected SCR_EditablePlayerDelegateComponent m_PlayerDelegate;
16  protected ref map<int, SCR_EditablePlayerDelegateComponent> m_Delegates = new map<int, SCR_EditablePlayerDelegateComponent>;
17  protected ref ScriptInvoker m_OnLimitedEditorChanged = new ScriptInvoker;
18 
23  void RegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
24  {
25  m_Delegates.Set(delegate.GetPlayerID(), delegate);
26 
27  delegate.GetOnLimitedEditorChanged().Insert(OnLimitedEditorChanged);
28  OnLimitedEditorChanged(delegate.GetPlayerID(), delegate.HasLimitedEditor());
29  }
34  void UnegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
35  {
36  m_Delegates.Remove(delegate.GetPlayerID());
37 
38  delegate.GetOnLimitedEditorChanged().Remove(OnLimitedEditorChanged);
39  OnLimitedEditorChanged(delegate.GetPlayerID(), true);
40  }
46  int GetDelegates(out notnull map<int, SCR_EditablePlayerDelegateComponent> outDelegates)
47  {
48  return outDelegates.Copy(m_Delegates);
49  }
55  SCR_EditablePlayerDelegateComponent GetDelegate(int playerID)
56  {
57  SCR_EditablePlayerDelegateComponent delegate;
58  m_Delegates.Find(playerID, delegate);
59  return delegate;
60  }
64  bool HasPlayerWithUnlimitedEditor()
65  {
66  if (!m_Delegates || m_Delegates.IsEmpty())
67  return false;
68 
69  for (int i, count = m_Delegates.Count(); i < count; i++)
70  {
71  if (!m_Delegates.GetElement(i))
72  continue;
73 
74  if (!m_Delegates.GetElement(i).HasLimitedEditor())
75  return true;
76  }
77  return false;
78  }
83  ScriptInvoker GetOnLimitedEditorChanged()
84  {
85  return m_OnLimitedEditorChanged;
86  }
87 
88  protected void OnLimitedEditorChanged(int playerID, bool isLimited)
89  {
90  m_OnLimitedEditorChanged.Invoke(playerID, isLimited);
91  }
92 
93  protected void OnSpawnServer(int playerID, IEntity controlledEntity)
94  {
95  if (m_PlayerDelegate && m_iPlayerID == playerID)
96  m_PlayerDelegate.SetControlledEntity(controlledEntity);
97  }
98  protected void OnDeathServer(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
99  {
100  if (m_PlayerDelegate && m_iPlayerID == playerId)
101  m_PlayerDelegate.SetControlledEntity(null);
102  }
103 
104  protected void OnPlayerDeletedServer(int playerID, IEntity controlledEntity)
105  {
106  OnDeathServer(playerID, controlledEntity, null, Instigator.CreateInstigator(null));
107  }
108 
109  override void EOnEditorInitServer()
110  {
111  Resource entityResource = Resource.Load(m_PlayerDelegatePrefab);
112  IEntityComponentSource componentSource = SCR_EditablePlayerDelegateComponentClass.GetEditableEntitySource(entityResource);
113  if (!componentSource)
114  {
115  Print(string.Format("SCR_EditablePlayerDelegateComponent missing in '%1'!", m_PlayerDelegatePrefab.GetPath()), LogLevel.WARNING);
116  return;
117  }
118 
119  if (!componentSource.GetClassName().ToType().IsInherited(SCR_EditablePlayerDelegateComponent))
120  {
121  Print(string.Format("'%1' contains editable entity entity of type %2, must be SCR_EditablePlayerDelegateComponent!", m_PlayerDelegatePrefab.GetPath(), componentSource.GetClassName()), LogLevel.WARNING);
122  return;
123  }
124 
125  SCR_EditorManagerEntity editorManager = GetManager();
126  m_iPlayerID = editorManager.GetPlayerID();
127 
128  IEntity delegateEntity = GetGame().SpawnEntityPrefab(entityResource);
129  m_PlayerDelegate = SCR_EditablePlayerDelegateComponent.Cast(SCR_EditablePlayerDelegateComponent.GetEditableEntity(delegateEntity));
130  m_PlayerDelegate.InitPlayerDelegate(editorManager, m_iPlayerID);
131  m_PlayerDelegate.RestoreParentEntity();
132 
134  if (gameMode)
135  {
136  gameMode.GetOnPlayerSpawned().Insert(OnSpawnServer);
137  gameMode.GetOnPlayerKilled().Insert(OnDeathServer);
138  gameMode.GetOnPlayerDeleted().Insert(OnPlayerDeletedServer);
139 
140  m_PlayerDelegate.SetControlledEntity(SCR_PossessingManagerComponent.GetPlayerMainEntity(m_iPlayerID));
141  }
142  else
143  {
145  if (playerController && playerController.GetPlayerId() == m_iPlayerID)
146  {
147  m_PlayerDelegate.SetControlledEntity(playerController.GetMainEntity());
148  }
149  }
150  }
151  override void EOnEditorDeleteServer()
152  {
153  if (m_PlayerDelegate)
154  m_PlayerDelegate.Delete();
155 
157  if (gameMode)
158  {
159  gameMode.GetOnPlayerSpawned().Remove(OnSpawnServer);
160  gameMode.GetOnPlayerKilled().Remove(OnDeathServer);
161  gameMode.GetOnPlayerDeleted().Remove(OnPlayerDeletedServer);
162  }
163  }
164 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_EditablePlayerDelegateComponentClass
Definition: SCR_EditablePlayerDelegateComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PlayerDelegateEditorComponent
Definition: SCR_PlayerDelegateEditorComponent.c:9
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_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
m_iPlayerID
SCR_EditorManagerCore m_iPlayerID
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_PlayerDelegateEditorComponentClass
Definition: SCR_PlayerDelegateEditorComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26