Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DebugEditorComponent.c
Go to the documentation of this file.
1 //#define FAKE_PLAYER //--- Allow placing AIs which are pretending to be players. Used for video capture.
2 
3 [ComponentEditorProps(category: "GameScripted/Editor", description: "Debug editor component. Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5 {
6 };
7 
14 {
15 #ifdef WORKBENCH
16  private SCR_EditableEntityComponent m_TestComponent;
17  private int m_LayerID;
18  private SCR_EditableEntityComponent m_LayerOrig;
19 #endif
20 
21  private SCR_BaseEditableEntityFilter m_FocusedManager;
22  private SCR_HoverEditableEntityFilter m_HoverManager;
23  private SCR_BaseEditableEntityFilter m_SelectedManager;
24 
25 #ifdef FAKE_PLAYER
26  private static int m_iFakePlayerIndex = 0;
27  private SCR_EditableEntityComponent m_FakePlayer;
28 #endif
29 
30  ref set<SCR_EditableEntityComponent> m_LOL = new set<SCR_EditableEntityComponent>;
31 
32 #ifdef FAKE_PLAYER
33  static string GetFakePlayerName(int playerID)
34  {
35  array<string> debugNames = {"", "Hedrik", "Ton", "Roach", "Natasha"};
36  return debugNames[-playerID % debugNames.Count()];
37  }
38  static string GetFakePlayerName()
39  {
40  return GetFakePlayerName(m_iFakePlayerIndex);
41  }
42 
43  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
44  protected void CreateFakePlayerServer()
45  {
46  array<SCR_SpawnPoint> spawnPoints = SCR_SpawnPoint.GetSpawnPointsForFaction("USSR");
47  if (!spawnPoints.IsEmpty())
48  {
49  ResourceName prefab = "{DCB41B3746FDD1BE}Prefabs/Characters/OPFOR/USSR_Army/Character_USSR_Rifleman.et";
50  EntitySpawnParams spawnParams = new EntitySpawnParams();
51  spawnParams.Transform[3] = spawnPoints[0].GetOrigin();
52  IEntity fakePlayer = GetGame().SpawnEntityPrefab(Resource.Load(prefab), GetGame().GetWorld(), spawnParams);
53 
54  prefab = "{69B7035099CEE1FC}Prefabs/AI/Groups/ChimeraGroupNonEditable.et";
55  AIGroup group = AIGroup.Cast(GetGame().SpawnEntityPrefab(Resource.Load(prefab), GetGame().GetWorld(), spawnParams));
56 
57  AIControlComponent aiControl = AIControlComponent.Cast(fakePlayer.FindComponent(AIControlComponent));
58  aiControl.ActivateAI();
59  AIAgent agent = aiControl.GetAIAgent();
60 
61  prefab = "{FFF9518F73279473}PrefabsEditable/Auto/AI/Waypoints/E_AIWaypoint_Move.et";//"{750A8D1695BD6998}Prefabs/AI/Waypoints/AIWaypoint_Move.et";
62  MenuRootBase menu = MenuRootBase.Cast(GetGame().GetMenuManager().GetTopMenu());
63  SCR_CursorEditorUIComponent cursorComponent = SCR_CursorEditorUIComponent.Cast(menu.GetRootComponent().FindComponent(SCR_CursorEditorUIComponent));
64  vector cursorWorldPos;
65  cursorComponent.GetCursorWorldPos(cursorWorldPos);
66  spawnParams.Transform[3] = cursorWorldPos;
67  AIWaypoint wp = AIWaypoint.Cast(GetGame().SpawnEntityPrefab(Resource.Load(prefab), GetGame().GetWorld(), spawnParams));
68 
69  group.AddAgent(agent);
70  group.AddWaypoint(wp);
71 
72  m_FakePlayer = SCR_EditableEntityComponent.GetEditableEntity(fakePlayer);
73 
74  m_iFakePlayerIndex--;
76  gameMode.GetOnPlayerSpawned().Invoke(m_iFakePlayerIndex, fakePlayer);
77  //SCR_NotificationsComponent.SendToEveryone(ENotification.PLAYER_JOINED_FACTION, m_iFakePlayerIndex);
78  }
79  }
80  protected void PingFakePlayer()
81  {
83  Print(m_FakePlayer);
84  pingManager.CallEvents(GetManager(), true, -1, false, false, vector.Zero, m_FakePlayer); //--- Set to public in the class
85  }
86 #endif
87  override void EOnFrame(IEntity owner, float timeSlice)
88  {
89  /* Measure set<> vs array<> (SPOILER: set<> wins!)
90  SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore));
91  core.GetAllEntities(m_LOL);
92 
93  DbgUI.Begin("", 0, 0);
94  DbgUI.Text("Count: " + m_LOL.Count().ToString());
95  DbgUI.End();
96 
97  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>;
98  SCR_EditableEntityComponent entity;
99  for (int i = 0, count = m_LOL.Count(); i < count; i++)
100  {
101  entity = m_LOL[i];
102  if (entities.Find(entity) == -1)
103  {
104  entities.Insert(entity);
105  }
106  }
107  */
108 #ifdef FAKE_PLAYER
109  if (Debug.KeyState(KeyCode.KC_U))
110  {
111  Debug.ClearKey(KeyCode.KC_U);
112 
113  Rpc(CreateFakePlayerServer);
114  }
115  if (Debug.KeyState(KeyCode.KC_K))
116  {
117  Debug.ClearKey(KeyCode.KC_K);
118 
119  PingFakePlayer();
120  }
121 #endif
122 
123 #ifdef WORKBENCH
124  if (m_TestComponent)
125  {
126  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY_TOGGLE))
127  {
128  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY_TOGGLE, false);
129  SCR_AccessKeysEditorComponent accessKeyComponent = SCR_AccessKeysEditorComponent.Cast(SCR_AccessKeysEditorComponent.GetInstance(SCR_AccessKeysEditorComponent));
130  if (!accessKeyComponent) return;
131 
132  typename keysType = EEditableEntityAccessKey;
133  int keyValue;
134  keysType.GetVariableValue(null, DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY), keyValue);
135  if (!m_TestComponent.HasAccessSelf(keyValue))
136  {
137  accessKeyComponent.AddEntityAccessKey(m_TestComponent, keyValue);
138  }
139  else
140  {
141  accessKeyComponent.RemoveEntityAccessKey(m_TestComponent, keyValue);
142  }
143  m_TestComponent.LogAccessKey();
144  }
145  bool show = DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SHOW);
146  if (show != m_TestComponent.GetVisibleSelf())
147  {
148  m_TestComponent.SetVisible(show);
149  }
150  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SELECT))
151  {
152  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SELECT, false);
153  Print(m_SelectedManager);
154  if (m_SelectedManager) m_SelectedManager.Toggle(m_TestComponent);
155  }
156  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_FOCUS))
157  {
158  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_FOCUS, false);
159  if (m_FocusedManager) m_FocusedManager.Toggle(m_TestComponent);
160  }
161  }
162 #endif
163 
164  //--- Ad-hoc debugs
165  /*
166  if (Debug.KeyState(KeyCode.KC_M))
167  {
168  Debug.ClearKey(KeyCode.KC_M);
169  Print("MOVE");
170 
171  SCR_EntitiesManagerEditorComponent entitiesManager = SCR_EntitiesManagerEditorComponent.Cast(GetInstance(SCR_EntitiesManagerEditorComponent));
172  if (entitiesManager)
173  {
174  SCR_SelectedEditableEntityFilter selectedFilter = SCR_SelectedEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.SELECTED));
175  if (selectedFilter)
176  {
177  SCR_EditableEntityComponent entity = selectedFilter.GetFirstEntity();
178  if (entity)
179  {
180  MenuManager menuManager = GetGame().GetMenuManager();
181  if (menuManager)
182  {
183  MenuRootBase menu = MenuRootBase.Cast(menuManager.GetTopMenu());
184  if (menu)
185  {
186  SCR_CursorEditorUIComponent cursorComponent = SCR_CursorEditorUIComponent.Cast(menu.GetRootComponent().FindComponent(SCR_CursorEditorUIComponent));
187  if (cursorComponent)
188  {
189  vector worldPos;
190  if (cursorComponent.GetCursorWorldPos(worldPos))
191  {
192  entity.GetOwner().SetOrigin(worldPos);
193  entity.UpdateStaticPos();
194  }
195  }
196  }
197  }
198  }
199  }
200  }
201  }
202  */
203  /*
204  if (Debug.KeyState(KeyCode.KC_L))
205  {
206  Debug.ClearKey(KeyCode.KC_L);
207 
208  // Custom instance.
209  RplTestPropType instance = new RplTestPropType;
210  instance.iVal = 1138;
211  instance.fVal = 42;
212  instance.bVal = true;
213 
214  // Pure data holder without any index/position. Just capacity and length.
215  SSnapshot s = new SSnapshot(32);
216 
217  // This is your writer. Contains a pointer thats shifted with every write.
218  // Starts at 0 and can be moved by Seek(...) method.
219  SSnapSerializer writer = SSnapSerializer.MakeWriter(s);
220  RplTestPropType.Extract(instance, null, writer);
221 
222  // This is your reader which contains a pointer, also starts at 0 and moves
223  // with every read.
224  SSnapSerializer reader = SSnapSerializer.MakeReader(s);
225 
226  // Comparisons are effectively reads. They do move the pointer. Thats why
227  // you can do ops like: reader.Compare(A, 4).Compare(B, 4);
228  // The memory from A gets compared with the snapshot contents at the
229  // position of the readers pointer. Then the reader increments the pointer.
230  Print(RplTestPropType.PropCompare(instance, reader, null), LogLevel.DEBUG);
231 
232  instance.fVal = 42;
233  reader = SSnapSerializer.MakeReader(s);
234  Print(RplTestPropType.PropCompare(instance, reader, null), LogLevel.WARNING);
235  }
236  */
237 
238  /*
239  if (Debug.KeyState(KeyCode.KC_J))
240  {
241  Debug.ClearKey(KeyCode.KC_J);
242  ArmaReforgerScripted game = GetGame();
243  if (!game) return;
244 
245  PlayerController pc = game.GetPlayerController();
246  if (!pc) return;
247 
248  ChimeraCharacter character = ChimeraCharacter.Cast(pc.GetControlledEntity());
249  if (!character) return;
250 
251  SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.FindComponent(SCR_CharacterControllerComponent));
252  if (!controller) return;
253 
254  Print(controller.GetDisableMovementControls());
255 
256  GetGame().GetInputManager().ActivateContext("CharacterGeneralContext");
257 
258  controller.SetDisableWeaponControls(false);
259  controller.SetDisableMovementControls(false);
260  }
261  */
262  /*
263  if (Debug.KeyState(KeyCode.KC_L))
264  {
265  Debug.ClearKey(KeyCode.KC_L);
266 
267  //--- Init
268  RplTestSerializer instance = new RplTestSerializer;
269  instance.iVal = 1138;
270  instance.fVal = 42;
271  instance.bVal = false;
272 
273  SSnapSerializer snapSerializer = SSnapSerializer.MakeReader(new SSnapshot(32));
274 
275  RplTestSerializer.Extract(instance, null, snapSerializer);
276 
277  bool compare1 = RplTestSerializer.PropCompare(instance, snapSerializer, null);
278  Print(compare1, LogLevel.DEBUG);
279  }
280  */
281  }
282  override void EOnEditorDebug(array<string> debugTexts)
283  {
284  #ifdef WORKBENCH
285  if (!SCR_EditorBaseEntity.Cast(GetOwner()).IsOpened()) return;
286  if (m_HoverManager)
287  {
288  string entityName = "N/A";
289  bool isDelegate
290  SCR_EditableEntityComponent entityUnderCursor = m_HoverManager.GetEntityUnderCursor(isDelegate);
291  if (entityUnderCursor) entityName = entityUnderCursor.GetDisplayName();
292  debugTexts.Insert("Under Cursor: " + entityName + " / " + isDelegate.ToString());
293  }
294  if (m_TestComponent)
295  {
296  debugTexts.Insert("\nTestEntity: " + m_TestComponent.GetDisplayName());
297 
298  SCR_EditableEntityComponent parent = m_TestComponent.GetParentEntity();
299  if (parent)
300  debugTexts.Insert("Parent: " + parent.GetDisplayName());
301  else
302  debugTexts.Insert("Parent: N/A");
303 
304  typename enumType = EEditableEntityState;
305  int enumCount = enumType.GetVariableCount();
306  for (int i = 0; i < enumCount; i++)
307  {
308  int val;
309  if (enumType.GetVariableType(i) == int && enumType.GetVariableValue(null, i, val))
310  {
311  debugTexts.Insert(string.Format("%1: %2", enumType.GetVariableName(i), m_TestComponent.HasEntityState(val) > 0));
312  }
313 
314  }
315  debugTexts.Insert("\n");
316  }
317  #endif
318  }
319  override void EOnEditorPostActivate()
320  {
322  if (entitiesManager)
323  {
324  m_FocusedManager = entitiesManager.GetFilter(EEditableEntityState.FOCUSED);
325  m_HoverManager = SCR_HoverEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.HOVER));
326  m_SelectedManager = entitiesManager.GetFilter(EEditableEntityState.SELECTED);
327  }
328  }
329  override void EOnEditorActivate()
330  {
331 #ifdef FAKE_PLAYER
332  m_iFakePlayerIndex = 0;
333  SetEventMask(GetOwner(), EntityEvent.FRAME);
334 #endif
335 
336 #ifdef WORKBENCH
337  SetEventMask(GetOwner(), EntityEvent.FRAME);
338 
339  GenericEntity testEntity = GenericEntity.Cast(GetGame().FindEntity("TestEntity"));
340  if (!testEntity) return;
341 
342  m_TestComponent = SCR_EditableEntityComponent.Cast(testEntity.FindComponent(SCR_EditableEntityComponent));
343  if (!m_TestComponent) return;
344 
345  m_LayerOrig = m_TestComponent.GetParentEntity();
346 
347  typename keysType = EEditableEntityAccessKey;
348  int keysCount = keysType.GetVariableCount();
349 
350  DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY, "", "TestEntity: Access Key", "Editable Entities", string.Format("0, %1, 0, 1", keysCount - 1));
351  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY_TOGGLE, "", "TestEntity: Access Key: Toggle", "Editable Entities");
352  DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_LAYER, "", "TestEntity: Layer", "Editable Entities", "0, 2, 0, 1");
353  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SELECT, "", "TestEntity: Toggle Selection", "Editable Entities");
354  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_FOCUS, "", "TestEntity: Toggle Focus", "Editable Entities");
355  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SHOW, "", "TestEntity: Show", "Editable Entities");
356 
357  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_LAYER, 0);
358  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SHOW, true);
359 
360 #endif
361  }
362  override protected void EOnEditorDeactivate()
363  {
364  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY);
365  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_ACCESS_KEY_TOGGLE);
366  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_LAYER);
367  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SELECT);
368  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_FOCUS);
369  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_TEST_ENTITY_SHOW);
370  }
371 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_CursorEditorUIComponent
Definition: SCR_CursorEditorUIComponent.c:3
SCR_DebugEditorComponentClass
Definition: SCR_DebugEditorComponent.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_DebugEditorComponent
Definition: SCR_DebugEditorComponent.c:13
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
m_HoverManager
SCR_BaseActionsEditorComponentClass m_HoverManager
MenuRootBase
Definition: MenuRootBase.c:6
EEditableEntityAccessKey
EEditableEntityAccessKey
Definition: EEditableEntityAccessKey.c:8
SCR_PingEditorComponent
Definition: SCR_PingEditorComponent.c:70
m_SelectedManager
protected SCR_BaseEditableEntityFilter m_SelectedManager
Definition: SCR_BaseActionsEditorComponent.c:151
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_EditorBaseEntity
Definition: SCR_EditorBaseEntity.c:14
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180