1 [
EntityEditorProps(
category:
"GameScripted/Editor", description:
"Core Editor manager", color:
"251 91 0 255", icon:
"WBData/EntityEditorProps/entityEditor.png")]
30 [
Attribute(
"true", UIWidgets.Auto,
"Are default modes created automatically?",
category:
"Editor Manager")]
31 private bool m_bIsAutoModes;
33 [
Attribute(
"false", UIWidgets.Auto,
"Is the editor launched by default?",
category:
"Editor Manager")]
34 private bool m_bIsAutoInit;
38 private bool m_bIsOpened;
39 private bool m_bIsInTransition;
45 private RplComponent m_RplComponent;
46 private int m_iPlayerID;
48 private ref array<SCR_EditorModeEntity> m_Modes =
new array<SCR_EditorModeEntity>;
49 protected ref map<EEditorModeAccess, EEditorMode> m_ModesByAccess =
new map<EEditorModeAccess, EEditorMode>();
54 private bool m_bIsModeChangeRequested;
55 private bool m_bIsLimited;
56 protected SCR_NotificationsComponent m_NotificationsComponent;
60 private int m_iEventComponent;
61 private int m_iEventAttempt;
62 private float m_iEventProgress;
63 private float m_iEventProgressMax;
64 private float m_fEventAsyncStart;
65 private ref array<SCR_BaseEditorComponent> m_aEventComponentsActivate;
66 private ref array<SCR_BaseEditorComponent> m_aEventComponentsDeactivate;
67 private ref array<EEditorEvent> m_aEvents;
69 private ref ScriptInvoker Event_OnInit =
new ScriptInvoker();
70 private ref ScriptInvoker Event_OnRequest =
new ScriptInvoker();
71 private ref ScriptInvoker Event_OnOpened =
new ScriptInvoker();
72 private ref ScriptInvoker Event_OnCanOpen =
new ScriptInvoker();
73 private ref ScriptInvoker Event_OnCanClose =
new ScriptInvoker();
74 private ref ScriptInvoker Event_OnPreActivate =
new ScriptInvoker();
75 private ref ScriptInvoker Event_OnActivate =
new ScriptInvoker();
76 private ref ScriptInvoker Event_OnPostActivate =
new ScriptInvoker();
77 private ref ScriptInvoker Event_OnDeactivate =
new ScriptInvoker();
78 private ref ScriptInvoker Event_OnClosed =
new ScriptInvoker();
79 private ref ScriptInvoker Event_OnDebug =
new ScriptInvoker();
80 private ref ScriptInvoker Event_OnOpenedServer =
new ScriptInvoker();
81 private ref ScriptInvoker Event_OnOpenedServerCallback =
new ScriptInvoker();
82 private ref ScriptInvoker Event_OnClosedServer =
new ScriptInvoker();
83 private ref ScriptInvoker Event_OnClosedServerCallback =
new ScriptInvoker();
84 private ref ScriptInvoker Event_OnModeAdd =
new ScriptInvoker();
85 private ref ScriptInvoker Event_OnModeRemove =
new ScriptInvoker();
86 private ref ScriptInvoker Event_OnModeChangeRequest =
new ScriptInvoker();
87 private ref ScriptInvoker Event_OnModeChange =
new ScriptInvoker();
88 private ref ScriptInvoker Event_OnLimitedChange =
new ScriptInvoker();
89 private ref ScriptInvoker Event_OnAsyncLoad =
new ScriptInvoker();
90 private ref ScriptInvoker Event_OnCanEndGameChanged =
new ScriptInvoker();
98 override bool IsOpened()
100 if (m_bIsInTransition)
121 void Open(
bool showErrorNotification =
true)
123 if (m_bIsOpened || !IsAuthority())
return;
126 if (showErrorNotification)
127 SCR_NotificationsComponent.SendToPlayer(GetPlayerID(),
ENotification.EDITOR_CANNOT_OPEN);
132 Rpc(ToggleServer,
true);
139 void Close(
bool showErrorNotification =
true)
141 if (!m_bIsOpened || !IsAuthority())
return;
144 if (showErrorNotification)
145 SCR_NotificationsComponent.SendToPlayer(GetPlayerID(),
ENotification.EDITOR_CANNOT_CLOSE);
151 Rpc(ToggleServer,
false);
153 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
154 protected void ToggleServer(
bool open)
156 if (m_bIsOpened == open || RplSession.Mode() == RplMode.Client)
return;
159 if (open && !CanOpen())
161 SCR_NotificationsComponent.SendToPlayer(GetPlayerID(),
ENotification.EDITOR_CANNOT_OPEN);
165 if (!open && !CanClose())
167 SCR_NotificationsComponent.SendToPlayer(GetPlayerID(),
ENotification.EDITOR_CANNOT_CLOSE);
172 Rpc(ToggleOwner, m_bIsOpened);
176 if (m_CurrentModeEntity)
177 m_CurrentModeEntity.ActivateModeServer();
179 Event_OnOpenedServer.Invoke();
183 if (m_CurrentModeEntity)
184 m_CurrentModeEntity.DeactivateModeServer();
186 Event_OnClosedServer.Invoke();
189 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
190 protected void ToggleOwner(
bool open)
198 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_IS_OPENED, m_bIsOpened);
200 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
201 protected void ToggleOwnerServerCallback(
bool open)
205 Event_OnOpenedServerCallback.Invoke();
209 statsApi.IncrementEditorCounter(GetPlayerID());
213 Event_OnClosedServerCallback.Invoke();
217 protected int GetEnumSum(
typename enumType)
219 int enumCount = enumType.GetVariableCount();
222 for (
int i = 0; i < enumCount; i++)
224 if (enumType.GetVariableType(i) ==
int && enumType.GetVariableValue(
null, i, val))
256 return m_CanOpen == m_CanOpenSum;
267 return m_CanOpen & accessType;
274 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
277 if (canOpen == CanOpen(accessType) || RplSession.Mode() == RplMode.Client)
return;
280 m_CanOpen = m_CanOpen | accessType;
282 m_CanOpen = m_CanOpen &~ accessType;
284 Rpc(SetCanOpenOwner, m_CanOpen);
287 if (!CanOpen() && IsOpened()) ToggleServer(
false);
289 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
293 Event_OnCanOpen.Invoke(m_CanOpen);
298 if (canOpen == CanOpen(accessType))
return;
299 Rpc(SetCanOpen, canOpen, accessType);
309 m_CanClose == m_CanCloseSum;
318 return m_CanClose & accessType;
325 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
328 if (canClose == CanClose(accessType) || RplSession.Mode() == RplMode.Client)
return;
331 m_CanClose = m_CanClose | accessType;
333 m_CanClose = m_CanClose &~ accessType;
335 Rpc(SetCanCloseOwner, m_CanClose);
337 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
340 m_CanClose = canClose;
341 Event_OnCanClose.Invoke(m_CanClose);
346 if (canClose == CanClose(accessType))
return;
347 Rpc(SetCanClose, canClose, accessType);
356 void SetAutoInit(
bool isAutoInit =
false)
358 m_bIsAutoInit = isAutoInit;
365 return m_bIsAutoInit;
372 void SetAutoModes(
bool isAutoModes =
false)
374 m_bIsAutoModes = isAutoModes;
384 protected bool IsAuthority()
386 return this == GetInstance() || RplSession.Mode() != RplMode.Client;
397 bool IsInTransition()
399 return m_bIsInTransition;
408 return m_bIsLimited || DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_FORCE_LIMITED);
415 static bool IsLimitedInstance()
418 return !editorManager || editorManager.IsLimited();
433 void SendNotification(
ENotification notificationID,
int selfID = 0,
int targetID = 0, vector
position = vector.Zero)
436 SCR_NotificationsComponent.SendLocal(notificationID,
position, selfID, targetID);
445 protected void UpdateLimited()
448 bool limitedPrev = m_bIsLimited;
452 if (mode && !mode.IsLimited())
454 m_bIsLimited =
false;
468 if (m_bIsLimited != limitedPrev)
469 Event_OnLimitedChange.Invoke(m_bIsLimited);
474 override ScriptInvoker GetOnInit()
478 override ScriptInvoker GetOnOpened()
480 return Event_OnOpened;
482 override ScriptInvoker GetOnPreActivate()
484 return Event_OnPreActivate;
486 override ScriptInvoker GetOnActivate()
488 return Event_OnActivate;
490 override ScriptInvoker GetOnPostActivate()
492 return Event_OnPostActivate;
494 override ScriptInvoker GetOnDeactivate()
496 return Event_OnDeactivate;
498 override ScriptInvoker GetOnClosed()
500 return Event_OnClosed;
502 override ScriptInvoker GetOnDebug()
504 return Event_OnDebug;
506 override ScriptInvoker GetOnOpenedServer()
508 return Event_OnOpenedServer;
510 override ScriptInvoker GetOnOpenedServerCallback()
512 return Event_OnOpenedServerCallback;
514 override ScriptInvoker GetOnClosedServer()
516 return Event_OnClosedServer;
518 override ScriptInvoker GetOnClosedServerCallback()
520 return Event_OnClosedServerCallback;
522 override ScriptInvoker GetOnActivateServer()
524 return Event_OnOpenedServer;
526 override ScriptInvoker GetOnDeactivateServer()
528 return Event_OnClosedServer;
530 override ScriptInvoker GetOnRequest()
532 return Event_OnRequest;
534 ScriptInvoker GetOnCanOpen()
536 return Event_OnCanOpen;
538 ScriptInvoker GetOnCanClose()
540 return Event_OnCanClose;
542 ScriptInvoker GetOnModeAdd()
544 return Event_OnModeAdd;
546 ScriptInvoker GetOnModeRemove()
548 return Event_OnModeRemove;
550 ScriptInvoker GetOnModeChangeRequest()
552 return Event_OnModeChangeRequest;
554 ScriptInvoker GetOnModeChange()
556 return Event_OnModeChange;
558 ScriptInvoker GetOnLimitedChange()
560 return Event_OnLimitedChange;
562 ScriptInvoker GetOnAsyncLoad()
564 return Event_OnAsyncLoad;
566 ScriptInvoker GetOnCanEndGameChanged()
568 return Event_OnCanEndGameChanged;
577 static bool ToggleInstance()
580 if (!instance)
return false;
588 static bool OpenInstance()
591 if (!instance)
return false;
599 static bool CloseInstance()
602 if (!instance)
return false;
611 static bool IsOpenedInstance(
bool includeLimited =
true)
615 && instance.IsOpened()
616 && (includeLimited || !instance.IsLimited());
622 static bool CanOpenInstance()
625 if (!instance)
return false;
626 return instance.CanOpen();
632 static bool CanCloseInstance()
635 if (!instance)
return false;
636 return instance.CanClose();
644 ArmaReforgerScripted game =
GetGame();
645 if (!game)
return null;
648 if (!manager)
return null;
650 return manager.GetEditorManager();
669 if (RplSession.Mode() == RplMode.Client)
672 RplComponent rplEditor = RplComponent.Cast(FindComponent(RplComponent));
680 if (FindModeEntity(mode))
682 Print(
string.Format(
"Cannot create %1 mode manager, it already exists!", Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
688 if (prefab.IsEmpty())
690 array<SCR_EditorModePrefab> modePrefabs = {};
691 core.GetBaseModePrefabs(modePrefabs, -1,
true);
694 if (mode == basePrefab.GetMode())
696 prefab = basePrefab.GetPrefab();
704 if (prefab.IsEmpty())
706 Print(
string.Format(
"No prefab found for editor mode '%1'!", Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
711 EntitySpawnParams spawnParams =
new EntitySpawnParams;
712 spawnParams.Parent =
this;
716 Print(
string.Format(
"Prefab %1 for editor mode %2 is not SCR_EditorModeEntity!", prefab.GetPath(), Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
720 if (!modeEntity.GetParent())
722 Print(
string.Format(
"Prefab %1 for editor mode %2 is missing Hierarchy component!", prefab.GetPath(), Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
726 RplComponent rplMode = RplComponent.Cast(modeEntity.FindComponent(RplComponent));
729 Print(
string.Format(
"Prefab %1 for editor mode %2 is missing RplComponent!", prefab.GetPath(), Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
734 modeEntity.InitServer(
this);
736 AddMode(modeEntity, isInit);
738 Rpc(CreateEditorModeOwner, mode, Replication.FindId(modeEntity), isInit);
745 || (autoSelect && !IsOpened())
750 SetCurrentMode(mode);
763 SetEditorModes(access, GetEditorModes() | modes, isInit);
772 SetEditorModes(access, GetEditorModes() & ~modes,
false);
782 m_ModesByAccess.Set(access, modes);
786 array<EEditorMode> flags = {};
787 for (
int i, count =
SCR_Enum.BitToIntArray(preActiveModes & ~activeModes, flags); i < count; i++)
789 RplComponent.DeleteRplEntity(FindModeEntity(flags[i]),
false);
791 RepairEditorModes(isInit);
796 void RepairEditorModes(
bool isInit)
798 array<EEditorMode> flags = {};
799 for (
int i, count =
SCR_Enum.BitToIntArray(GetEditorModes(), flags); i < count; i++)
801 if (!FindModeEntity(flags[i]))
802 CreateEditorMode(flags[i], isInit);
811 for(
int i, count = m_ModesByAccess.Count(); i < count; i++)
813 modes |= m_ModesByAccess.GetElement(i);
825 if (modeEntity && !modeEntity.IsDeleted())
826 return modeEntity.GetModeType();
833 void RestorePreviousMode()
835 SetCurrentMode(m_PrevMode);
842 bool SetCurrentMode(
bool isLimited)
846 if (modeEntity.IsLimited() == isLimited)
848 SetCurrentMode(modeEntity.GetModeType());
861 if (m_CurrentMode == mode && m_CurrentModeEntity)
864 m_bIsModeChangeRequested =
true;
865 Event_OnModeChangeRequest.Invoke(FindModeEntity(mode), m_CurrentModeEntity);
866 Rpc(SetCurrentModeServer, mode);
874 if (m_bIsModeChangeRequested && m_CurrentMode == m_ProcessedMode)
877 return m_CurrentMode;
885 return m_CurrentModeEntity;
895 if (modeEntity && modeEntity.GetModeType() == mode)
908 if (modeEntity && modeEntity.GetModeType() == mode)
return modeEntity;
917 int GetModeEntities(out notnull array<SCR_EditorModeEntity> modeEntities)
920 return modeEntities.Count();
927 int GetModes(out notnull array<EEditorMode> modes)
932 modes.Insert(editorMode.GetModeType());
934 return modes.Count();
945 modes = modes | editorMode.GetModeType();
953 bool IsModeChangeRequested()
955 return m_bIsModeChangeRequested;
962 if (
m_Modes.Find(modeEntity) >= 0)
return;
964 int order = modeEntity.GetOrder();
974 for (
int c =
m_Modes.Count() - 1; c >= 0; c--)
987 if (!isInit && Replication.IsServer())
989 int playerID = GetPlayerID();
992 if (!modeEntity.SendNotificationLocalOnly())
993 SCR_NotificationsComponent.SendToUnlimitedEditorPlayersAndPlayer(playerID, modeEntity.GetOnAddNotification(), playerID);
995 SCR_NotificationsComponent.SendLocal(modeEntity.GetOnAddNotification(), playerID);
1001 Event_OnModeAdd.Invoke(modeEntity);
1005 if (!
m_Modes.Contains(modeEntity))
1010 m_ProcessedMode = modeEntity.GetModeType();
1012 Rpc(RemoveModeServer, modeEntity.GetModeType());
1015 m_Modes.RemoveItem(modeEntity);
1018 Event_OnModeRemove.Invoke(modeEntity);
1022 int playerID = GetPlayerID();
1026 if (!modeEntity.SendNotificationLocalOnly())
1027 SCR_NotificationsComponent.SendToUnlimitedEditorPlayersAndPlayer(playerID, modeEntity.GetOnRemoveNotification(), playerID);
1029 SCR_NotificationsComponent.SendLocal(modeEntity.GetOnRemoveNotification(), playerID);
1034 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1040 if (mode == m_CurrentMode)
1044 if (!CanOpen() && IsOpened())
1045 ToggleServer(
false);
1054 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1055 protected void CreateEditorModeOwner(
EEditorMode mode,
int modeEntityId,
bool isInit)
1058 if (!modeEntity)
return;
1060 AddMode(modeEntity, isInit);
1061 modeEntity.InitOwner();
1063 m_ProcessedMode = mode;
1066 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1067 protected void SetCurrentModeServer(
EEditorMode mode)
1071 mode = GetDefaultMode();
1074 if ((m_CurrentMode == mode && m_CurrentModeEntity) || mode == -1)
1081 modeEntity = FindModeEntity(mode);
1084 Print(
string.Format(
"SCR_EditorModeEntity for mode '%1' not found!", Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
1089 if (m_CurrentModeEntity && m_bIsOpened)
1090 m_CurrentModeEntity.DeactivateModeServer();
1092 Rpc(SetCurrentModeOwner, mode);
1093 m_CurrentMode = mode;
1094 m_CurrentModeEntity = modeEntity;
1096 if (m_CurrentModeEntity && m_bIsOpened)
1097 m_CurrentModeEntity.ActivateModeServer();
1099 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1100 protected void SetCurrentModeOwner(
EEditorMode mode)
1106 if (!modeEntity && mode >= 0)
1108 Print(
string.Format(
"Editor mode '%1' not found!", Type().EnumToString(
EEditorMode, mode)), LogLevel.ERROR);
1111 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_MODE, Math.Log2(mode));
1113 m_ProcessedMode = mode;
1125 Print(
string.Format(
"Editor operation %1 was requested while %2 was still running! Editor closed to prevent conflicts!",
typename.EnumToString(
EEditorEventOperation,
type),
typename.EnumToString(
EEditorEventOperation, m_iEventOperation)), LogLevel.WARNING);
1132 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_ASYNC_LOAD_DEBUG))
1134 string currentMode =
typename.EnumToString(
EEditorMode, m_CurrentMode);
1135 if (!m_CurrentModeEntity)
1136 currentMode +=
" (null)";
1137 Print(
string.Format(
"StartEvents: %1 | current mode: %2 | processed mode: %3",
typename.EnumToString(
EEditorEventOperation,
type), currentMode,
typename.EnumToString(
EEditorMode, m_ProcessedMode)), LogLevel.DEBUG);
1140 m_iEventOperation =
type;
1141 m_iEventProgress = 0;
1147 GetAllComponents(m_aEventComponentsActivate);
1157 FindEditorComponents(m_aEventComponentsDeactivate);
1160 if (m_ProcessedMode == m_CurrentMode)
1194 GetAllComponents(m_aEventComponentsActivate);
1204 m_iEventProgressMax = 1;
1206 FindEditorComponents(m_aEventComponentsActivate);
1207 if (m_CurrentModeEntity) m_CurrentModeEntity.FindEditorComponents(m_aEventComponentsActivate);
1208 m_aEventComponentsDeactivate = {};
1209 m_bIsInTransition =
true;
1224 GetAllComponents(m_aEventComponentsActivate);
1234 m_iEventProgressMax = 1;
1236 FindEditorComponents(m_aEventComponentsDeactivate);
1237 if (m_CurrentModeEntity) m_CurrentModeEntity.FindEditorComponents(m_aEventComponentsDeactivate);
1238 m_aEventComponentsActivate = {};
1239 m_bIsInTransition =
true;
1253 m_iEventProgressMax = 2;
1255 FindModeEntity(m_ProcessedMode).FindEditorComponents(m_aEventComponentsActivate);
1256 m_aEventComponentsDeactivate = {};
1257 if (m_CurrentModeEntity) m_CurrentModeEntity.FindEditorComponents(m_aEventComponentsDeactivate);
1281 FindModeEntity(m_ProcessedMode).FindEditorComponents(m_aEventComponentsActivate);
1298 FindModeEntity(m_ProcessedMode).FindEditorComponents(m_aEventComponentsDeactivate);
1301 if (m_ProcessedMode == m_CurrentMode)
1335 protected void ProcessEvent()
1337 m_iEvent = m_aEvents[0];
1339 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_ASYNC_LOAD_DEBUG) && m_iEventComponent == 0 && m_iEventAttempt == 0)
1341 Print(
typename.EnumToString(
EEditorEvent, m_iEvent), LogLevel.NORMAL);
1350 component.OnInitBase();
1357 component.OnRequestBase(
true);
1359 Event_OnRequest.Invoke(
true);
1366 if (component) component.OnRequestBase(
false);
1368 Event_OnRequest.Invoke(
false);
1376 if (component) component.OnOpenedBase();
1383 array<SCR_BaseEditorComponent> allComponents;
1384 GetAllComponents(allComponents);
1388 if (component) component.OnOpenedBase();
1397 if (component) component.OnPreActivateBase();
1402 processedMode.PreActivateMode();
1404 Event_OnPreActivate.Invoke();
1412 if (component) component.OnDeactivateBase();
1414 if (m_ProcessedMode == m_CurrentMode && m_CurrentModeEntity)
1415 m_CurrentModeEntity.DeactivateMode();
1417 Event_OnDeactivate.Invoke();
1423 bool instantContinue;
1424 if (ProcessAsyncEvent(
false, instantContinue))
1427 else if (instantContinue)
1444 if (component) component.OnActivateBase();
1447 if (m_CurrentModeEntity)
1448 m_CurrentModeEntity.ActivateMode();
1450 Event_OnActivate.Invoke();
1456 bool instantContinue;
1457 if (ProcessAsyncEvent(
true, instantContinue))
1460 else if (instantContinue)
1477 if (component) component.OnPostDeactivateBase();
1486 if (component) component.OnPostActivateBase();
1489 if (m_CurrentModeEntity)
1490 m_CurrentModeEntity.PostActivateMode();
1492 Event_OnPostActivate.Invoke();
1500 if (component) component.OnClosedBase();
1509 if (component) component.OnDeleteBase();
1516 m_PrevMode = m_CurrentMode;
1517 m_CurrentMode = m_ProcessedMode;
1518 m_CurrentModeEntity = FindModeEntity(m_CurrentMode);
1525 m_bIsInTransition =
false;
1528 switch (m_iEventOperation)
1532 Event_OnAsyncLoad.Invoke(1);
1533 Event_OnOpened.Invoke();
1534 Rpc(ToggleOwnerServerCallback,
true);
1539 Event_OnAsyncLoad.Invoke(1);
1540 Event_OnClosed.Invoke();
1541 Rpc(ToggleOwnerServerCallback,
false);
1546 m_bIsModeChangeRequested =
false;
1547 if (IsOpened()) Event_OnAsyncLoad.Invoke(1);
1548 Event_OnModeChange.Invoke(m_CurrentModeEntity, FindModeEntity(m_PrevMode));
1555 m_aEventComponentsActivate =
null;
1556 m_aEventComponentsDeactivate =
null;
1558 m_ProcessedMode = 0;
1564 m_aEvents.RemoveOrdered(0);
1565 if (!m_aEvents.IsEmpty())
1568 protected bool ProcessAsyncEvent(
bool toActivate, out
bool instantContinue)
1571 array<SCR_BaseEditorComponent> components;
1573 components = m_aEventComponentsActivate;
1575 components = m_aEventComponentsDeactivate;
1578 if (m_iEventComponent >= components.Count())
1580 m_iEventComponent = 0;
1581 m_iEventAttempt = 0;
1586 GetGame().GetInputManager().ActivateContext(
"DebugContext");
1589 if (m_iEventAttempt == 0)
1590 m_fEventAsyncStart =
GetGame().GetWorld().GetWorldTime();
1598 isProcessed = component.OnActivateAsyncBase(m_iEventAttempt);
1600 isProcessed = component.OnDeactivateAsyncBase(m_iEventAttempt);
1603 instantContinue = IsDeleted() || !component.GetOwner() || component.GetOwner().IsDeleted();
1609 instantContinue =
true;
1610 m_iEventAttempt = 0;
1616 if (m_iEventAttempt == 0)
1617 instantContinue =
true;
1619 m_iEventComponent++;
1620 m_iEventAttempt = 0;
1621 m_iEventProgress += 1 / components.Count() / m_iEventProgressMax;
1622 Event_OnAsyncLoad.Invoke(m_iEventProgress);
1624 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_ASYNC_LOAD_DEBUG) && component)
1625 Print(
string.Format(
"%1 (%2), %3 ms", Math.Round(m_iEventProgress * 100), component.Type(),
GetGame().GetWorld().GetWorldTime() - m_fEventAsyncStart), LogLevel.VERBOSE);
1634 protected void GetAllComponents(out array<SCR_BaseEditorComponent> outComponents)
1636 FindEditorComponents(outComponents);
1640 mode.FindEditorComponents(outComponents);
1646 protected void Action_EditorToggle(
float value, EActionTrigger reason)
1651 protected void Action_GoToLatestNotification(
float value, EActionTrigger reason)
1653 if (!m_NotificationsComponent)
1654 m_NotificationsComponent = SCR_NotificationsComponent.GetInstance();
1656 if (IsOpened() && !IsLimited() && m_NotificationsComponent)
1658 vector goToPosition;
1659 if (m_NotificationsComponent.GetLastNotificationLocation(goToPosition))
1663 cursorManualCameraComponent.TeleportCamera(goToPosition);
1672 protected void ShowDebug()
1674 array<string> debugTexts =
new array<string>;
1676 string accessSuffix =
"";
1677 debugTexts.Insert(
string.Format(
"CanOpen: %1/%2", m_CanOpen, m_CanOpenSum));
1678 debugTexts.Insert(
string.Format(
"CanClose: %1/%2", m_CanClose, m_CanCloseSum));
1680 string currentModeName =
"N/A";
1681 if (m_CurrentModeEntity) currentModeName =
typename.EnumToString(
EEditorMode, m_CurrentModeEntity.GetModeType());
1682 debugTexts.Insert(
string.Format(
"Current Mode: %1", currentModeName));
1683 debugTexts.Insert(
string.Format(
"Available Modes: %1",
m_Modes.Count()));
1684 debugTexts.Insert(
string.Format(
"Limited: %1", m_bIsLimited));
1685 GetOnDebug().Invoke(debugTexts);
1687 DbgUI.Begin(
"SCR_EditorManagerEntity", 0, 0);
1688 foreach (
string text: debugTexts)
1694 protected void ProcessDebug()
1697 bool isOpened = DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_IS_OPENED);
1698 if (isOpened != IsOpened())
1707 SetCanCloseDebug(
true);
1711 bool canOpen = DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_OPEN);
1716 bool canClose = DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_CLOSE);
1719 SetCanCloseDebug(canClose);
1722 if (m_CurrentModeEntity)
1724 int debugMode = 1 << DiagMenu.GetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_MODE);
1725 if (m_CurrentMode != debugMode && FindModeEntity(debugMode))
1727 SetCurrentMode(debugMode);
1731 if (DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_SHOW_DEBUG)) ShowDebug();
1737 void InitServer(
int playerID)
1745 InitComponents(
true);
1746 Rpc(InitOwner, playerID);
1753 if (modeEntity) modeEntity.InitServer(
this);
1754 child = child.GetSibling();
1757 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
1758 protected void InitOwner(
int playerID)
1764 if (!core || !core.SetEditorManager(
this))
1769 if (!
m_RplComponent) Print(
"SCR_EditorManagerEntity is missing RplComponent component!", LogLevel.ERROR);
1772 InitComponents(
false);
1776 core.Event_OnEditorManagerInitOwner.Invoke(
this);
1778 SetEventMask(EntityEvent.FRAME);
1780 InputManager inputManager =
GetGame().GetInputManager();
1783 inputManager.AddActionListener(
"EditorToggle", EActionTrigger.PRESSED, Action_EditorToggle);
1784 inputManager.AddActionListener(
"EditorLastNotificationTeleport", EActionTrigger.DOWN, Action_GoToLatestNotification);
1788 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_IS_OPENED,
"",
"Is Opened",
"Editor");
1789 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_OPEN,
"",
"Can Open",
"Editor");
1790 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_CLOSE,
"",
"Can Close",
"Editor");
1791 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_SHOW_DEBUG,
"",
"Show Debug",
"Editor");
1792 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_FORCE_LIMITED,
"",
"Force Limited",
"Editor");
1793 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_ASYNC_LOAD_DEBUG,
"",
"Log Async Load",
"Editor");
1794 DiagMenu.RegisterRange(
SCR_DebugMenuID.DEBUGUI_EDITOR_NETWORK_DELAY,
"",
"Simulated Network Delay",
"Editor",
"0 1000 0 100");
1797 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_IS_OPENED, m_bIsOpened);
1798 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_OPEN, m_CanOpen);
1799 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_CAN_CLOSE, m_CanClose);
1802 int enumCount = enumType.GetVariableCount();
1803 DiagMenu.RegisterRange(
SCR_DebugMenuID.DEBUGUI_EDITOR_MODE,
"",
"Mode",
"Editor",
string.Format(
"0 %1 0 1", enumCount - 1));
1804 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_MODE, Math.Max(m_CurrentMode, 0));
1806 void PostInitServer()
1808 if (m_CurrentMode < 0)
1810 SetCurrentModeServer(-1);
1815 if (m_bIsAutoInit && !m_bIsLimited)
1819 m_bIsAutoInit =
false;
1824 override void EOnInit(IEntity owner)
1826 super.EOnInit(owner);
1831 world.RegisterEntityToBeUpdatedWhileGameIsPaused(
this);
1834 override void EOnFrame(IEntity owner,
float timeSlice)
1846 SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
1858 if (m_CurrentModeEntity)
1859 m_CurrentModeEntity.DeactivateModeServer();
1861 if (Replication.IsServer() && IsOpened())
1862 Event_OnClosedServer.Invoke();
1867 if (GetInstance() ==
this)
1882 world.UnregisterEntityToBeUpdatedWhileGameIsPaused(
this);
1893 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Individual editor manager",
"et")]
1894 private ResourceName m_Prefab;
1906 ResourceName GetPrefab()
1917 return m_ModeUIInfo;