CryEditDoc.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. #ifndef CRYINCLUDE_EDITOR_CRYEDITDOC_H
  9. #define CRYINCLUDE_EDITOR_CRYEDITDOC_H
  10. #pragma once
  11. #if !defined(Q_MOC_RUN)
  12. #include "DocMultiArchive.h"
  13. #include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
  14. #include <AzToolsFramework/Entity/SliceEditorEntityOwnershipServiceBus.h>
  15. #include <AzToolsFramework/Prefab/PrefabLoaderInterface.h>
  16. #include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
  17. #include <AzToolsFramework/UI/Prefab/PrefabIntegrationInterface.h>
  18. #include <AzCore/Component/Component.h>
  19. #include <AzQtComponents/Components/Widgets/Card.h>
  20. #include <TimeValue.h>
  21. #include <IEditor.h>
  22. #endif
  23. struct LightingSettings;
  24. struct IVariable;
  25. struct ICVar;
  26. // Filename of the temporary file used for the hold / fetch operation
  27. // conform to the "$tmp[0-9]_" naming convention
  28. #define HOLD_FETCH_FILE "$tmp_hold"
  29. class CCryEditDoc
  30. : public QObject
  31. , protected AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler
  32. {
  33. Q_OBJECT
  34. Q_PROPERTY(bool modified READ IsModified WRITE SetModifiedFlag);
  35. Q_PROPERTY(QString pathName READ GetLevelPathName WRITE SetPathName);
  36. Q_PROPERTY(QString title READ GetTitle WRITE SetTitle);
  37. public: // Create from serialization only
  38. enum DocumentEditingMode
  39. {
  40. LevelEdit,
  41. SliceEdit
  42. };
  43. Q_INVOKABLE CCryEditDoc();
  44. virtual ~CCryEditDoc();
  45. bool IsModified() const;
  46. void SetModifiedFlag(bool modified);
  47. // Currently it's not possible to disable one single flag and eModifiedModule is ignored
  48. // if bModified is false.
  49. virtual void SetModifiedModules(EModifiedModule eModifiedModule, bool boSet = true);
  50. int GetModifiedModule();
  51. // Return level path.
  52. // If a slice is being edited then the path to a placeholder level is returned.
  53. QString GetLevelPathName() const;
  54. // Set path of slice or level being edited.
  55. void SetPathName(const QString& pathName);
  56. // Return slice path, if slice is open, an empty string otherwise. Use GetEditMode() to determine if a slice is open.
  57. QString GetSlicePathName() const;
  58. // Return The current type of document being edited, a level or a slice
  59. // While editing a slice, a placeholder level is opened since the editor requires an open level to function.
  60. // While editing a slice, saving will only affect the slice and not the placeholder level.
  61. DocumentEditingMode GetEditMode() const;
  62. // Return slice path if editing slice, level path if editing level.
  63. SANDBOX_API QString GetActivePathName() const;
  64. QString GetTitle() const;
  65. void SetTitle(const QString& title);
  66. virtual bool OnNewDocument();
  67. void InitEmptyLevel(int resolution = 0, int unitSize = 0, bool bUseTerrain = false);
  68. void CreateDefaultLevelAssets(int resolution = 0, int unitSize = 0);
  69. bool DoSave(const QString& pathName, bool replace);
  70. SANDBOX_API bool Save();
  71. virtual bool DoFileSave();
  72. bool SaveModified();
  73. virtual bool BackupBeforeSave(bool bForce = false);
  74. void SaveAutoBackup(bool bForce = false);
  75. // ClassWizard generated virtual function overrides
  76. virtual bool OnOpenDocument(const QString& lpszPathName);
  77. bool IsLevelLoadFailed() const { return m_bLoadFailed; }
  78. //! Marks this document as having errors.
  79. void SetHasErrors() { m_hasErrors = true; }
  80. bool IsDocumentReady() const { return m_bDocumentReady; }
  81. void SetDocumentReady(bool bReady);
  82. bool IsLevelExported() const;
  83. void SetLevelExported(bool boExported = true);
  84. bool CanCloseFrame();
  85. enum class FetchPolicy
  86. {
  87. DELETE_FOLDER,
  88. DELETE_LY_FILE,
  89. PRESERVE
  90. };
  91. void Hold(const QString& holdName);
  92. void Hold(const QString& holdName, const QString& relativeHoldPath);
  93. void Fetch(const QString& relativeHoldPath, bool bShowMessages = true, bool bDelHoldFolder = false);
  94. void Fetch(const QString& holdName, const QString& relativeHoldPath, bool bShowMessages, FetchPolicy policy);
  95. const char* GetTemporaryLevelName() const;
  96. void DeleteTemporaryLevel();
  97. void SetWaterColor(const QColor& col) { m_waterColor = col; }
  98. QColor GetWaterColor() const { return m_waterColor; }
  99. XmlNodeRef& GetFogTemplate() { return m_fogTemplate; }
  100. XmlNodeRef& GetEnvironmentTemplate() { return m_environmentTemplate; }
  101. void OnEnvironmentPropertyChanged(IVariable* pVar);
  102. void RegisterListener(IDocListener* listener);
  103. void UnregisterListener(IDocListener* listener);
  104. static bool IsBackupOrTempLevelSubdirectory(const QString& folderName);
  105. virtual void OnFileSaveAs();
  106. protected:
  107. virtual void DeleteContents();
  108. struct TOpenDocContext
  109. {
  110. CTimeValue loading_start_time;
  111. QString absoluteLevelPath;
  112. QString absoluteSlicePath;
  113. };
  114. bool BeforeOpenDocument(const QString& lpszPathName, TOpenDocContext& context);
  115. bool DoOpenDocument(TOpenDocContext& context);
  116. virtual bool LoadXmlArchiveArray(TDocMultiArchive& arrXmlAr, const QString& absoluteLevelPath, const QString& levelPath);
  117. virtual void ReleaseXmlArchiveArray(TDocMultiArchive& arrXmlAr);
  118. virtual void Load(TDocMultiArchive& arrXmlAr, const QString& szFilename);
  119. virtual void StartStreamingLoad(){}
  120. void Save(CXmlArchive& xmlAr);
  121. void Load(CXmlArchive& xmlAr, const QString& szFilename);
  122. void Save(TDocMultiArchive& arrXmlAr);
  123. bool SaveLevel(const QString& filename);
  124. bool SaveSlice(const QString& filename);
  125. bool LoadLevel(TDocMultiArchive& arrXmlAr, const QString& absoluteCryFilePath);
  126. bool LoadEntitiesFromLevel(const QString& levelPakFile);
  127. bool LoadEntitiesFromSlice(const QString& sliceFile);
  128. void SerializeFogSettings(CXmlArchive& xmlAr);
  129. virtual void SerializeViewSettings(CXmlArchive& xmlAr);
  130. void LogLoadTime(int time) const;
  131. struct TSaveDocContext
  132. {
  133. bool bSaved;
  134. };
  135. bool BeforeSaveDocument(const QString& lpszPathName, TSaveDocContext& context);
  136. bool HasLayerNameConflicts() const;
  137. bool DoSaveDocument(const QString& lpszPathName, TSaveDocContext& context);
  138. bool AfterSaveDocument(const QString& lpszPathName, TSaveDocContext& context, bool bShowPrompt = true);
  139. virtual bool OnSaveDocument(const QString& lpszPathName);
  140. //! called immediately after saving the level.
  141. void AfterSave();
  142. void OnStartLevelResourceList();
  143. QString GetCryIndexPath(const char* levelFilePath) const;
  144. //////////////////////////////////////////////////////////////////////////
  145. // SliceEditorEntityOwnershipServiceNotificationBus::Handler
  146. void OnSliceInstantiated(const AZ::Data::AssetId& sliceAssetId, AZ::SliceComponent::SliceInstanceAddress& sliceAddress, const AzFramework::SliceInstantiationTicket& /*ticket*/) override;
  147. void OnSliceInstantiationFailed(const AZ::Data::AssetId& sliceAssetId, const AzFramework::SliceInstantiationTicket& /*ticket*/) override;
  148. //////////////////////////////////////////////////////////////////////////
  149. bool m_bLoadFailed = false;
  150. QColor m_waterColor = QColor(0, 0, 255);
  151. XmlNodeRef m_fogTemplate;
  152. XmlNodeRef m_environmentTemplate;
  153. std::list<IDocListener*> m_listeners;
  154. bool m_bDocumentReady = false;
  155. int m_modifiedModuleFlags;
  156. // On construction, it assumes loaded levels have already been exported. Can be a big fat lie, though.
  157. // The right way would require us to save to the level folder the export status of the level.
  158. bool m_boLevelExported = true;
  159. bool m_modified = false;
  160. QString m_pathName;
  161. QString m_slicePathName;
  162. QString m_title;
  163. const char* m_envProbeSliceRelativePath = "EngineAssets/Slices/DefaultLevelSetup.slice";
  164. const float m_envProbeHeight = 200.0f;
  165. bool m_hasErrors = false; ///< This is used to warn the user that they may lose work when they go to save.
  166. AzToolsFramework::Prefab::PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr;
  167. AzToolsFramework::PrefabEditorEntityOwnershipInterface* m_prefabEditorEntityOwnershipInterface = nullptr;
  168. AzToolsFramework::Prefab::PrefabLoaderInterface* m_prefabLoaderInterface = nullptr;
  169. AzToolsFramework::Prefab::PrefabIntegrationInterface* m_prefabIntegrationInterface = nullptr;
  170. };
  171. class CAutoDocNotReady
  172. {
  173. public:
  174. CAutoDocNotReady()
  175. {
  176. m_prevState = GetIEditor()->GetDocument()->IsDocumentReady();
  177. GetIEditor()->GetDocument()->SetDocumentReady(false);
  178. }
  179. ~CAutoDocNotReady()
  180. {
  181. GetIEditor()->GetDocument()->SetDocumentReady(m_prevState);
  182. }
  183. private:
  184. bool m_prevState;
  185. };
  186. namespace AzToolsFramework
  187. {
  188. //! A component to reflect scriptable commands for the Editor
  189. class CryEditDocFuncsHandler
  190. : public AZ::Component
  191. {
  192. public:
  193. AZ_COMPONENT(CryEditDocFuncsHandler, "{628CE458-72E7-4B7B-B8A2-62F95F55E738}")
  194. SANDBOX_API static void Reflect(AZ::ReflectContext* context);
  195. // AZ::Component ...
  196. void Activate() override {}
  197. void Deactivate() override {}
  198. };
  199. } // namespace AzToolsFramework
  200. #endif // CRYINCLUDE_EDITOR_CRYEDITDOC_H