IEditorImpl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : IEditor interface implementation.
  9. #pragma once
  10. #include "IEditor.h"
  11. #include "MainWindow.h"
  12. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  13. #include <memory> // for shared_ptr
  14. #include <QMap>
  15. #include <QApplication>
  16. #include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
  17. #include <AzCore/std/string/string.h>
  18. #include "Commands/CommandManager.h"
  19. #include "Include/IErrorReport.h"
  20. #include "ErrorReport.h"
  21. class QMenu;
  22. #define GET_PLUGIN_ID_FROM_MENU_ID(ID) (((ID) & 0x000000FF))
  23. #define GET_UI_ELEMENT_ID_FROM_MENU_ID(ID) ((((ID) & 0x0000FF00) >> 8))
  24. class CUndoManager;
  25. class CGameEngine;
  26. class CErrorsDlg;
  27. class CTrackViewSequenceManager;
  28. class CEditorFileMonitor;
  29. class AzAssetWindow;
  30. class AzAssetBrowserRequestHandler;
  31. class AssetEditorRequestsHandler;
  32. struct IEditorFileMonitor;
  33. class CVegetationMap;
  34. namespace Editor
  35. {
  36. class EditorQtApplication;
  37. }
  38. namespace AssetDatabase
  39. {
  40. class AssetDatabaseLocationListener;
  41. }
  42. class CEditorImpl
  43. : public IEditor
  44. {
  45. Q_DECLARE_TR_FUNCTIONS(CEditorImpl)
  46. public:
  47. CEditorImpl();
  48. virtual ~CEditorImpl();
  49. void Initialize();
  50. void OnBeginShutdownSequence();
  51. void OnEarlyExitShutdownSequence();
  52. void Uninitialize();
  53. void SetGameEngine(CGameEngine* ge);
  54. void DeleteThis() override { delete this; };
  55. CEditorCommandManager* GetCommandManager() override { return m_pCommandManager; };
  56. ICommandManager* GetICommandManager() override { return m_pCommandManager; }
  57. void ExecuteCommand(const char* sCommand, ...) override;
  58. void ExecuteCommand(const QString& command) override;
  59. void SetDocument(CCryEditDoc* pDoc) override;
  60. CCryEditDoc* GetDocument() const override;
  61. bool IsLevelLoaded() const override;
  62. void SetModifiedFlag(bool modified = true) override;
  63. void SetModifiedModule(EModifiedModule eModifiedModule, bool boSet = true) override;
  64. bool IsLevelExported() const override;
  65. bool SetLevelExported(bool boExported = true) override;
  66. void InitFinished();
  67. bool IsModified() override;
  68. bool IsInitialized() const override{ return m_bInitialized; }
  69. bool SaveDocument() override;
  70. ISystem* GetSystem() override;
  71. void WriteToConsole(const char* string) override { CLogFile::WriteLine(string); };
  72. void WriteToConsole(const QString& string) override { CLogFile::WriteLine(string); };
  73. // Change the message in the status bar
  74. void SetStatusText(const QString& pszString) override;
  75. IMainStatusBar* GetMainStatusBar() override;
  76. bool ShowConsole([[maybe_unused]] bool show) override
  77. {
  78. //if (AfxGetMainWnd())return ((CMainFrame *) (AfxGetMainWnd()))->ShowConsole(show);
  79. return false;
  80. }
  81. void SetConsoleVar(const char* var, float value) override;
  82. float GetConsoleVar(const char* var) override;
  83. //! Query main window of the editor
  84. QMainWindow* GetEditorMainWindow() const override
  85. {
  86. return MainWindow::instance();
  87. };
  88. QString GetPrimaryCDFolder() override;
  89. QString GetLevelName() override;
  90. QString GetLevelFolder() override;
  91. QString GetLevelDataFolder() override;
  92. QString GetSearchPath(EEditorPathName path) override;
  93. QString GetResolvedUserFolder() override;
  94. bool ExecuteConsoleApp(const QString& CommandLine, QString& OutputText, bool bNoTimeOut = false, bool bShowWindow = false) override;
  95. bool IsInGameMode() override;
  96. void SetInGameMode(bool inGame) override;
  97. bool IsInSimulationMode() override;
  98. bool IsInTestMode() override;
  99. bool IsInPreviewMode() override;
  100. bool IsInConsolewMode() override;
  101. bool IsInLevelLoadTestMode() override;
  102. //! Enables/Disable updates of editor.
  103. void EnableUpdate(bool enable) override { m_bUpdates = enable; };
  104. CGameEngine* GetGameEngine() override { return m_pGameEngine; };
  105. CDisplaySettings* GetDisplaySettings() override { return m_pDisplaySettings; };
  106. // This will return a null pointer if CrySystem is not loaded before
  107. // Global Sandbox Settings are loaded from the registry before CrySystem
  108. // At that stage GetSettingsManager will return null and xml node in
  109. // memory will not be populated with Sandbox Settings.
  110. // After m_IEditor is created and CrySystem loaded, it is possible
  111. // to feed memory node with all necessary data needed for export
  112. // (gSettings.Load() and CXTPDockingPaneManager/CXTPDockingPaneLayout Sandbox layout management)
  113. CSettingsManager* GetSettingsManager() override;
  114. CMusicManager* GetMusicManager() override { return m_pMusicManager; };
  115. IEditorFileMonitor* GetFileMonitor() override;
  116. float GetTerrainElevation(float x, float y) override;
  117. Editor::EditorQtApplication* GetEditorQtApplication() override { return m_QtApplication; }
  118. const QColor& GetColorByName(const QString& name) override;
  119. //////////////////////////////////////////////////////////////////////////
  120. IMovieSystem* GetMovieSystem() override
  121. {
  122. if (m_pSystem)
  123. {
  124. return m_pSystem->GetIMovieSystem();
  125. }
  126. return nullptr;
  127. };
  128. CPluginManager* GetPluginManager() override { return m_pPluginManager; }
  129. CViewManager* GetViewManager() override;
  130. CViewport* GetActiveView() override;
  131. void SetActiveView(CViewport* viewport) override;
  132. CLevelIndependentFileMan* GetLevelIndependentFileMan() override { return m_pLevelIndependentFileMan; }
  133. void UpdateViews(int flags, const AABB* updateRegion) override;
  134. void ResetViews() override;
  135. void ReloadTrackView() override;
  136. bool AddToolbarItem(uint8 iId, IUIEvent* pIHandler);
  137. void SetDataModified() override;
  138. void SetAxisConstraints(AxisConstrains axis) override;
  139. AxisConstrains GetAxisConstrains() override;
  140. void SetTerrainAxisIgnoreObjects(bool bIgnore) override;
  141. bool IsTerrainAxisIgnoreObjects() override;
  142. XmlNodeRef FindTemplate(const QString& templateName) override;
  143. void AddTemplate(const QString& templateName, XmlNodeRef& tmpl) override;
  144. const QtViewPane* OpenView(QString sViewClassName, bool reuseOpened = true) override;
  145. /**
  146. * Returns the top level widget which is showing the view pane with the specified name.
  147. * To access the child widget which actually implements the view pane use this instead:
  148. * QtViewPaneManager::FindViewPane<MyDialog>(name);
  149. */
  150. QWidget* FindView(QString viewClassName) override;
  151. bool SetViewFocus(const char* sViewClassName) override;
  152. // close ALL panels related to classId, used when unloading plugins.
  153. bool SelectColor(QColor &color, QWidget *parent = 0) override;
  154. void Update();
  155. SFileVersion GetFileVersion() override { return m_fileVersion; };
  156. SFileVersion GetProductVersion() override { return m_productVersion; };
  157. //! Get shader enumerator.
  158. CUndoManager* GetUndoManager() override { return m_pUndoManager; };
  159. void BeginUndo() override;
  160. void RestoreUndo(bool undo) override;
  161. void AcceptUndo(const QString& name) override;
  162. void CancelUndo() override;
  163. void SuperBeginUndo() override;
  164. void SuperAcceptUndo(const QString& name) override;
  165. void SuperCancelUndo() override;
  166. void SuspendUndo() override;
  167. void ResumeUndo() override;
  168. void Undo() override;
  169. void Redo() override;
  170. bool IsUndoRecording() override;
  171. bool IsUndoSuspended() override;
  172. void RecordUndo(IUndoObject* obj) override;
  173. bool FlushUndo(bool isShowMessage = false) override;
  174. bool ClearLastUndoSteps(int steps) override;
  175. bool ClearRedoStack() override;
  176. //! Retrieve current animation context.
  177. CAnimationContext* GetAnimation() override;
  178. CTrackViewSequenceManager* GetSequenceManager() override;
  179. ITrackViewSequenceManager* GetSequenceManagerInterface() override;
  180. CToolBoxManager* GetToolBoxManager() override { return m_pToolBoxManager; };
  181. IErrorReport* GetErrorReport() override { return m_pErrorReport; }
  182. IErrorReport* GetLastLoadedLevelErrorReport() override { return m_pLasLoadedLevelErrorReport; }
  183. void StartLevelErrorReportRecording() override;
  184. void CommitLevelErrorReport() override {SAFE_DELETE(m_pLasLoadedLevelErrorReport); m_pLasLoadedLevelErrorReport = new CErrorReport(*m_pErrorReport); }
  185. IFileUtil* GetFileUtil() override { return m_pFileUtil; }
  186. void Notify(EEditorNotifyEvent event) override;
  187. void NotifyExcept(EEditorNotifyEvent event, IEditorNotifyListener* listener) override;
  188. void RegisterNotifyListener(IEditorNotifyListener* listener) override;
  189. void UnregisterNotifyListener(IEditorNotifyListener* listener) override;
  190. void ReduceMemory() override;
  191. ESystemConfigPlatform GetEditorConfigPlatform() const override;
  192. void ReloadTemplates() override;
  193. void ShowStatusText(bool bEnable) override;
  194. SSystemGlobalEnvironment* GetEnv() override;
  195. SEditorSettings* GetEditorSettings() override;
  196. void UnloadPlugins() override;
  197. void LoadPlugins() override;
  198. protected:
  199. AZStd::string LoadProjectIdFromProjectData();
  200. void DetectVersion();
  201. void RegisterTools();
  202. void SetPrimaryCDFolder();
  203. //! List of all notify listeners.
  204. std::list<IEditorNotifyListener*> m_listeners;
  205. ISystem* m_pSystem;
  206. IFileUtil* m_pFileUtil;
  207. CEditorCommandManager* m_pCommandManager;
  208. CPluginManager* m_pPluginManager;
  209. CViewManager* m_pViewManager;
  210. CUndoManager* m_pUndoManager;
  211. AxisConstrains m_selectedAxis;
  212. bool m_bUpdates;
  213. bool m_bTerrainAxisIgnoreObjects;
  214. SFileVersion m_fileVersion;
  215. SFileVersion m_productVersion;
  216. CXmlTemplateRegistry m_templateRegistry;
  217. CDisplaySettings* m_pDisplaySettings;
  218. QString m_primaryCDFolder;
  219. QString m_userFolder;
  220. bool m_bSelectionLocked;
  221. CGameEngine* m_pGameEngine;
  222. CAnimationContext* m_pAnimationContext;
  223. CTrackViewSequenceManager* m_pSequenceManager;
  224. CToolBoxManager* m_pToolBoxManager;
  225. CMusicManager* m_pMusicManager;
  226. CErrorReport* m_pErrorReport;
  227. //! Contains the error reports for the last loaded level.
  228. CErrorReport* m_pLasLoadedLevelErrorReport;
  229. CSelectionTreeManager* m_pSelectionTreeManager;
  230. //! CConsole Synchronization
  231. CConsoleSynchronization* m_pConsoleSync;
  232. //! Editor Settings Manager
  233. CSettingsManager* m_pSettingsManager;
  234. CLevelIndependentFileMan* m_pLevelIndependentFileMan;
  235. std::unique_ptr<CEditorFileMonitor> m_pEditorFileMonitor;
  236. QString m_selectFileBuffer;
  237. QString m_levelNameBuffer;
  238. bool m_bShowStatusText;
  239. bool m_bInitialized;
  240. bool m_bExiting;
  241. static void CmdPy(IConsoleCmdArgs* pArgs);
  242. Editor::EditorQtApplication* const m_QtApplication = nullptr;
  243. // This has to be absolute for the namespace since there is also a class called AssetDatabase that causes issues in unity builds
  244. ::AssetDatabase::AssetDatabaseLocationListener* m_pAssetDatabaseLocationListener;
  245. AzAssetBrowserRequestHandler* m_pAssetBrowserRequestHandler;
  246. AssetEditorRequestsHandler* m_assetEditorRequestsHandler;
  247. AZStd::mutex m_pluginMutex; // protect any pointers that come from plugins, such as the source control cached pointer.
  248. static const char* m_crashLogFileName;
  249. };