LevelAsset.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. StringTableEntry mGameModesNames;
  60. Vector<AssetBase*> mAssetDependencies;
  61. StringTableEntry mPreviewImageAssetId;
  62. AssetPtr<ImageAsset> mPreviewImageAsset;
  63. public:
  64. LevelAsset();
  65. virtual ~LevelAsset();
  66. /// Engine.
  67. static void initPersistFields();
  68. void copyTo(SimObject* object) override;
  69. /// Declare Console Object.
  70. DECLARE_CONOBJECT(LevelAsset);
  71. void loadDependencies();
  72. void unloadDependencies();
  73. void setLevelFile(const char* pImageFile);
  74. inline StringTableEntry getLevelFile(void) const { return mLevelFile; };
  75. void setPostFXPresetFile(const char* pPostFXPresetFile);
  76. inline StringTableEntry getPostFXPresetFile(void) const { return mPostFXPresetFile; };
  77. void setDecalsFile(const char* pDecalsFile);
  78. inline StringTableEntry getDecalsFile(void) const { return mDecalsFile; };
  79. void setForestFile(const char* pForestFile);
  80. inline StringTableEntry getForestFile(void) const { return mForestFile; };
  81. void setNavmeshFile(const char* pNavmeshFile);
  82. inline StringTableEntry getNavmeshFile(void) const { return mNavmeshFile; };
  83. StringTableEntry getPreviewImageAsset(void) const;
  84. inline StringTableEntry getLevelPath(void) const { return mLevelPath; };
  85. inline StringTableEntry getPostFXPresetPath(void) const { return mPostFXPresetPath; };
  86. inline StringTableEntry getDecalsPath(void) const { return mDecalsPath; };
  87. inline StringTableEntry getForestPath(void) const { return mForestPath; };
  88. inline StringTableEntry getNavmeshPath(void) const { return mNavmeshPath; };
  89. StringTableEntry getPreviewImagePath(void) const;
  90. void setEditorFile(const char* pEditorFile);
  91. inline StringTableEntry getEditorFile(void) const { return mEditorFile; };
  92. void setBakedSceneFile(const char* pBakedSceneFile);
  93. inline StringTableEntry getBakedSceneFile(void) const { return mBakedSceneFile; };
  94. U32 load() override { return Ok; };
  95. protected:
  96. static bool setLevelFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setLevelFile(data); return false; }
  97. static const char* getLevelFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getLevelFile(); }
  98. static bool setEditorFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setEditorFile(data); return false; }
  99. static const char* getEditorFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getEditorFile(); }
  100. static bool setBakedSceneFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setBakedSceneFile(data); return false; }
  101. static const char* getBakedSceneFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getBakedSceneFile(); }
  102. static bool setPostFXPresetFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setPostFXPresetFile(data); return false; }
  103. static const char* getPostFXPresetFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getPostFXPresetFile(); }
  104. static bool setDecalsFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setDecalsFile(data); return false; }
  105. static const char* getDecalsFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getDecalsFile(); }
  106. static bool setForestFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setForestFile(data); return false; }
  107. static const char* getForestFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getForestFile(); }
  108. static bool setNavmeshFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setNavmeshFile(data); return false; }
  109. static const char* getNavmeshFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getNavmeshFile(); }
  110. void initializeAsset(void) override;
  111. void onAssetRefresh(void) override;
  112. void loadAsset();
  113. typedef Signal<void()> LevelAssetChanged;
  114. LevelAssetChanged mChangeSignal;
  115. public:
  116. LevelAssetChanged& getChangedSignal() { return mChangeSignal; }
  117. };
  118. #ifdef TORQUE_TOOLS
  119. class GuiInspectorTypeLevelAssetPtr : public GuiInspectorTypeFileName
  120. {
  121. typedef GuiInspectorTypeFileName Parent;
  122. public:
  123. GuiBitmapButtonCtrl* mEditButton;
  124. DECLARE_CONOBJECT(GuiInspectorTypeLevelAssetPtr);
  125. static void consoleInit();
  126. GuiControl* constructEditControl() override;
  127. bool updateRects() override;
  128. };
  129. class GuiInspectorTypeLevelAssetId : public GuiInspectorTypeLevelAssetPtr
  130. {
  131. typedef GuiInspectorTypeLevelAssetPtr Parent;
  132. public:
  133. DECLARE_CONOBJECT(GuiInspectorTypeLevelAssetId);
  134. static void consoleInit();
  135. };
  136. #endif
  137. DefineConsoleType(TypeLevelAssetPtr, LevelAsset)
  138. DefineConsoleType(TypeLevelAssetId, String)
  139. #pragma region Singular Asset Macros
  140. //Singular assets
  141. /// <Summary>
  142. /// Declares an level asset
  143. /// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
  144. /// </Summary>
  145. #define DECLARE_LEVELASSET(className, name, changeFunc) public: \
  146. StringTableEntry m##name##AssetId;\
  147. AssetPtr<LevelAsset> m##name##Asset;\
  148. public: \
  149. const AssetPtr<LevelAsset> & get##name##Asset() const { return m##name##Asset; }\
  150. void set##name##Asset(const AssetPtr<LevelAsset> &_in) { m##name##Asset = _in;}\
  151. \
  152. bool _set##name(StringTableEntry _in)\
  153. {\
  154. if(m##name##AssetId != _in)\
  155. {\
  156. if (m##name##Asset.notNull())\
  157. {\
  158. m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
  159. }\
  160. if (_in == NULL || !String::compare(_in,StringTable->EmptyString()))\
  161. {\
  162. m##name##AssetId = StringTable->EmptyString();\
  163. m##name##Asset = NULL;\
  164. return true;\
  165. }\
  166. if (AssetDatabase.isDeclaredAsset(_in))\
  167. {\
  168. m##name##AssetId = _in;\
  169. m##name##Asset = _in;\
  170. return true;\
  171. }\
  172. }\
  173. \
  174. if(get##name() == StringTable->EmptyString())\
  175. return true;\
  176. \
  177. return false;\
  178. }\
  179. \
  180. const StringTableEntry get##name() const\
  181. {\
  182. return m##name##AssetId;\
  183. }\
  184. bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
  185. #define INITPERSISTFIELD_LEVELASSET(name, consoleClass, docs) \
  186. addProtectedField(assetText(name, Asset), TypeLevelAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
  187. #pragma endregion
  188. #endif // _ASSET_BASE_H_