CryEditDoc.h 7.1 KB

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