LevelAsset.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #pragma once
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2013 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #ifndef LEVEL_ASSET_H
  24. #define LEVEL_ASSET_H
  25. #ifndef _ASSET_BASE_H_
  26. #include "assets/assetBase.h"
  27. #endif
  28. #ifndef _ASSET_DEFINITION_H_
  29. #include "assets/assetDefinition.h"
  30. #endif
  31. #ifndef _STRINGUNIT_H_
  32. #include "string/stringUnit.h"
  33. #endif
  34. #ifndef _ASSET_FIELD_TYPES_H_
  35. #include "assets/assetFieldTypes.h"
  36. #endif
  37. #include "T3D/assets/ImageAsset.h"
  38. #ifndef _GUI_INSPECTOR_TYPES_H_
  39. #include "gui/editor/guiInspectorTypes.h"
  40. #endif
  41. #include <gui/controls/guiBitmapCtrl.h>
  42. //-----------------------------------------------------------------------------
  43. class LevelAsset : public AssetBase
  44. {
  45. typedef AssetBase Parent;
  46. StringTableEntry mLevelName;
  47. StringTableEntry mLevelFile;
  48. StringTableEntry mPostFXPresetFile;
  49. StringTableEntry mDecalsFile;
  50. StringTableEntry mForestFile;
  51. StringTableEntry mNavmeshFile;
  52. StringTableEntry mLevelPath;
  53. StringTableEntry mPostFXPresetPath;
  54. StringTableEntry mDecalsPath;
  55. StringTableEntry mForestPath;
  56. StringTableEntry mNavmeshPath;
  57. StringTableEntry mEditorFile;
  58. StringTableEntry mBakedSceneFile;
  59. bool mIsSubLevel;
  60. StringTableEntry mMainLevelAsset;
  61. StringTableEntry mGameModesNames;
  62. Vector<AssetBase*> mAssetDependencies;
  63. StringTableEntry mPreviewImageAssetId;
  64. AssetPtr<ImageAsset> mPreviewImageAsset;
  65. public:
  66. LevelAsset();
  67. virtual ~LevelAsset();
  68. /// Engine.
  69. static void initPersistFields();
  70. void copyTo(SimObject* object) override;
  71. /// Declare Console Object.
  72. DECLARE_CONOBJECT(LevelAsset);
  73. void loadDependencies();
  74. void unloadDependencies();
  75. void setLevelFile(const char* pImageFile);
  76. inline StringTableEntry getLevelFile(void) const { return mLevelFile; };
  77. void setPostFXPresetFile(const char* pPostFXPresetFile);
  78. inline StringTableEntry getPostFXPresetFile(void) const { return mPostFXPresetFile; };
  79. void setDecalsFile(const char* pDecalsFile);
  80. inline StringTableEntry getDecalsFile(void) const { return mDecalsFile; };
  81. void setForestFile(const char* pForestFile);
  82. inline StringTableEntry getForestFile(void) const { return mForestFile; };
  83. void setNavmeshFile(const char* pNavmeshFile);
  84. inline StringTableEntry getNavmeshFile(void) const { return mNavmeshFile; };
  85. StringTableEntry getPreviewImageAsset(void) const;
  86. inline StringTableEntry getLevelPath(void) const { return mLevelPath; };
  87. inline StringTableEntry getPostFXPresetPath(void) const { return mPostFXPresetPath; };
  88. inline StringTableEntry getDecalsPath(void) const { return mDecalsPath; };
  89. inline StringTableEntry getForestPath(void) const { return mForestPath; };
  90. inline StringTableEntry getNavmeshPath(void) const { return mNavmeshPath; };
  91. StringTableEntry getPreviewImagePath(void) const;
  92. void setEditorFile(const char* pEditorFile);
  93. inline StringTableEntry getEditorFile(void) const { return mEditorFile; };
  94. void setBakedSceneFile(const char* pBakedSceneFile);
  95. inline StringTableEntry getBakedSceneFile(void) const { return mBakedSceneFile; };
  96. U32 load() override { return Ok; };
  97. protected:
  98. static bool setLevelFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setLevelFile(data); return false; }
  99. static const char* getLevelFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getLevelFile(); }
  100. static bool setEditorFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setEditorFile(data); return false; }
  101. static const char* getEditorFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getEditorFile(); }
  102. static bool setBakedSceneFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setBakedSceneFile(data); return false; }
  103. static const char* getBakedSceneFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getBakedSceneFile(); }
  104. static bool setPostFXPresetFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setPostFXPresetFile(data); return false; }
  105. static const char* getPostFXPresetFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getPostFXPresetFile(); }
  106. static bool setDecalsFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setDecalsFile(data); return false; }
  107. static const char* getDecalsFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getDecalsFile(); }
  108. static bool setForestFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setForestFile(data); return false; }
  109. static const char* getForestFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getForestFile(); }
  110. static bool setNavmeshFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setNavmeshFile(data); return false; }
  111. static const char* getNavmeshFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getNavmeshFile(); }
  112. void initializeAsset(void) override;
  113. void onAssetRefresh(void) override;
  114. void loadAsset();
  115. typedef Signal<void()> LevelAssetChanged;
  116. LevelAssetChanged mChangeSignal;
  117. public:
  118. LevelAssetChanged& getChangedSignal() { return mChangeSignal; }
  119. };
  120. #ifdef TORQUE_TOOLS
  121. class GuiInspectorTypeLevelAssetPtr : public GuiInspectorTypeFileName
  122. {
  123. typedef GuiInspectorTypeFileName Parent;
  124. public:
  125. GuiBitmapButtonCtrl* mEditButton;
  126. DECLARE_CONOBJECT(GuiInspectorTypeLevelAssetPtr);
  127. static void consoleInit();
  128. GuiControl* constructEditControl() override;
  129. bool updateRects() override;
  130. };
  131. class GuiInspectorTypeLevelAssetId : public GuiInspectorTypeLevelAssetPtr
  132. {
  133. typedef GuiInspectorTypeLevelAssetPtr Parent;
  134. public:
  135. DECLARE_CONOBJECT(GuiInspectorTypeLevelAssetId);
  136. static void consoleInit();
  137. };
  138. #endif
  139. DefineConsoleType(TypeLevelAssetPtr, LevelAsset)
  140. DefineConsoleType(TypeLevelAssetId, String)
  141. #pragma region Singular Asset Macros
  142. //Singular assets
  143. /// <Summary>
  144. /// Declares an level asset
  145. /// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
  146. /// </Summary>
  147. #define DECLARE_LEVELASSET(className, name, changeFunc) public: \
  148. StringTableEntry m##name##AssetId;\
  149. AssetPtr<LevelAsset> m##name##Asset;\
  150. public: \
  151. const AssetPtr<LevelAsset> & get##name##Asset() const { return m##name##Asset; }\
  152. void set##name##Asset(const AssetPtr<LevelAsset> &_in) { m##name##Asset = _in;}\
  153. \
  154. bool _set##name(StringTableEntry _in)\
  155. {\
  156. if(m##name##AssetId != _in)\
  157. {\
  158. if (m##name##Asset.notNull())\
  159. {\
  160. m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
  161. }\
  162. if (_in == NULL || _in == StringTable->EmptyString())\
  163. {\
  164. m##name##AssetId = StringTable->EmptyString();\
  165. m##name##Asset = NULL;\
  166. return true;\
  167. }\
  168. if (AssetDatabase.isDeclaredAsset(_in))\
  169. {\
  170. m##name##AssetId = _in;\
  171. m##name##Asset = _in;\
  172. return true;\
  173. }\
  174. }\
  175. \
  176. if(get##name() == StringTable->EmptyString())\
  177. return true;\
  178. \
  179. return false;\
  180. }\
  181. \
  182. const StringTableEntry get##name() const\
  183. {\
  184. return m##name##AssetId;\
  185. }\
  186. bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
  187. #define INITPERSISTFIELD_LEVELASSET(name, consoleClass, docs) \
  188. addProtectedField(assetText(name, Asset), TypeLevelAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
  189. #pragma endregion
  190. #endif // _ASSET_BASE_H_