BsGUIResourceField.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsGUIElementContainer.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief GUI object that displays a field in which a Resource can be dragged and dropped.
  10. * The field accepts a Resource of a specific type and displays an optional label.
  11. */
  12. class BS_SCR_BED_EXPORT GUIResourceField : public GUIElementContainer
  13. {
  14. struct PrivatelyConstruct {};
  15. public:
  16. /**
  17. * Returns type name of the GUI element used for finding GUI element styles.
  18. */
  19. static const String& getGUITypeName();
  20. /**
  21. * @brief Creates a new resource GUI editor field with a label.
  22. *
  23. * @param typeNamespace Namespace of the type this field accepts.
  24. * @param type Type name of the type this field accepts. Must derive from Resource.
  25. * @param labelContent Content to display in the editor field label.
  26. * @param labelWidth Width of the label in pixels.
  27. * @param options Options that allow you to control how is the element positioned and sized.
  28. * This will override any similar options set by style.
  29. * @param style Optional style to use for the element. Style will be retrieved
  30. * from GUISkin of the GUIWidget the element is used on. If not specified
  31. * default style is used.
  32. */
  33. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& options,
  34. const String& style = StringUtil::BLANK);
  35. /**
  36. * @brief Creates a new resource GUI editor field with a label.
  37. *
  38. * @param typeNamespace Namespace of the type this field accepts.
  39. * @param type Type name of the type this field accepts. Must derive from Resource.
  40. * @param labelContent Content to display in the editor field label.
  41. * @param options Options that allow you to control how is the element positioned and sized.
  42. * This will override any similar options set by style.
  43. * @param style Optional style to use for the element. Style will be retrieved
  44. * from GUISkin of the GUIWidget the element is used on. If not specified
  45. * default style is used.
  46. */
  47. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, const GUIOptions& options,
  48. const String& style = StringUtil::BLANK);
  49. /**
  50. * @brief Creates a new resource GUI editor field with a label.
  51. *
  52. * @param typeNamespace Namespace of the type this field accepts.
  53. * @param type Type name of the type this field accepts. Must derive from Resource.
  54. * @param labelText Text to display in the editor field label.
  55. * @param labelWidth Width of the label in pixels.
  56. * @param options Options that allow you to control how is the element positioned and sized.
  57. * This will override any similar options set by style.
  58. * @param style Optional style to use for the element. Style will be retrieved
  59. * from GUISkin of the GUIWidget the element is used on. If not specified
  60. * default style is used.
  61. */
  62. static GUIResourceField* create(const String& typeNamespace, const String& type, const HString& labelText, UINT32 labelWidth, const GUIOptions& options,
  63. const String& style = StringUtil::BLANK);
  64. /**
  65. * @brief Creates a new resource GUI editor field with a label.
  66. *
  67. * @param typeNamespace Namespace of the type this field accepts.
  68. * @param type Type name of the type this field accepts. Must derive from Resource.
  69. * @param labelText Text to display in the editor field label.
  70. * @param options Options that allow you to control how is the element positioned and sized.
  71. * This will override any similar options set by style.
  72. * @param style Optional style to use for the element. Style will be retrieved
  73. * from GUISkin of the GUIWidget the element is used on. If not specified
  74. * default style is used.
  75. */
  76. static GUIResourceField* create(const String& typeNamespace, const String& type, const HString& labelText, const GUIOptions& options,
  77. const String& style = StringUtil::BLANK);
  78. /**
  79. * @brief Creates a new resource GUI editor field without a label.
  80. *
  81. * @param typeNamespace Namespace of the type this field accepts.
  82. * @param type Type name of the type this field accepts. Must derive from Resource.
  83. * @param options Options that allow you to control how is the element positioned and sized.
  84. * This will override any similar options set by style.
  85. * @param style Optional style to use for the element. Style will be retrieved
  86. * from GUISkin of the GUIWidget the element is used on. If not specified
  87. * default style is used.
  88. */
  89. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIOptions& options, const String& style = StringUtil::BLANK);
  90. /**
  91. * @brief Creates a new resource GUI editor field with a label.
  92. *
  93. * @param typeNamespace Namespace of the type this field accepts.
  94. * @param type Type name of the type this field accepts. Must derive from Resource.
  95. * @param labelContent Content to display in the editor field label.
  96. * @param labelWidth Width of the label in pixels.
  97. * @param style Optional style to use for the element. Style will be retrieved
  98. * from GUISkin of the GUIWidget the element is used on. If not specified
  99. * default style is used.
  100. */
  101. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, UINT32 labelWidth,
  102. const String& style = StringUtil::BLANK);
  103. /**
  104. * @brief Creates a new resource GUI editor field with a label.
  105. *
  106. * @param typeNamespace Namespace of the type this field accepts.
  107. * @param type Type name of the type this field accepts. Must derive from Resource.
  108. * @param labelContent Content to display in the editor field label.
  109. * @param style Optional style to use for the element. Style will be retrieved
  110. * from GUISkin of the GUIWidget the element is used on. If not specified
  111. * default style is used.
  112. */
  113. static GUIResourceField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent,
  114. const String& style = StringUtil::BLANK);
  115. /**
  116. * @brief Creates a new resource GUI editor field with a label.
  117. *
  118. * @param typeNamespace Namespace of the type this field accepts.
  119. * @param type Type name of the type this field accepts. Must derive from Resource.
  120. * @param labelText Text to display in the editor field label.
  121. * @param labelWidth Width of the label in pixels.
  122. * @param style Optional style to use for the element. Style will be retrieved
  123. * from GUISkin of the GUIWidget the element is used on. If not specified
  124. * default style is used.
  125. */
  126. static GUIResourceField* create(const String& typeNamespace, const String& type, const HString& labelText, UINT32 labelWidth,
  127. const String& style = StringUtil::BLANK);
  128. /**
  129. * @brief Creates a new resource GUI editor field with a label.
  130. *
  131. * @param typeNamespace Namespace of the type this field accepts.
  132. * @param type Type name of the type this field accepts. Must derive from Resource.
  133. * @param labelText Text to display in the editor field label.
  134. * @param style Optional style to use for the element. Style will be retrieved
  135. * from GUISkin of the GUIWidget the element is used on. If not specified
  136. * default style is used.
  137. */
  138. static GUIResourceField* create(const String& typeNamespace, const String& type, const HString& labelText,
  139. const String& style = StringUtil::BLANK);
  140. /**
  141. * @brief Creates a new resource GUI editor field without a label.
  142. *
  143. * @param typeNamespace Namespace of the type this field accepts.
  144. * @param type Type name of the type this field accepts. Must derive from Resource.
  145. * @param style Optional style to use for the element. Style will be retrieved
  146. * from GUISkin of the GUIWidget the element is used on. If not specified
  147. * default style is used.
  148. */
  149. static GUIResourceField* create(const String& typeNamespace, const String& type, const String& style = StringUtil::BLANK);
  150. GUIResourceField(const PrivatelyConstruct& dummy, const String& typeNamespace, const String& type, const GUIContent& labelContent,
  151. UINT32 labelWidth, const String& style, const GUIDimensions& dimensions, bool withLabel);
  152. /**
  153. * @brief Returns the resource referenced by the field, if any.
  154. */
  155. HResource getValue() const;
  156. /**
  157. * @brief Sets the resource referenced by the field.
  158. */
  159. void setValue(const HResource& value);
  160. /**
  161. * @brief Returns a weak reference to the texture referenced by the field, if any.
  162. */
  163. WeakResourceHandle<Resource> getValueWeak() const;
  164. /**
  165. * @brief Sets a weak reference to the texture referenced by the field.
  166. */
  167. void setValueWeak(const WeakResourceHandle<Resource>& value);
  168. /**
  169. * @brief Returns the resource referenced by the field. Returns
  170. * empty string with no resource is referenced.
  171. */
  172. String getUUID() const { return mUUID; }
  173. /**
  174. * @copydoc GUIElement::setTint
  175. */
  176. virtual void setTint(const Color& color) override;
  177. /**
  178. * @copydoc GUIElement::_updateLayoutInternal
  179. */
  180. void _updateLayoutInternal(const GUILayoutData& data) override;
  181. /**
  182. * @copydoc GUIElement::_getOptimalSize
  183. */
  184. Vector2I _getOptimalSize() const override;
  185. /**
  186. * @brief Triggered whenever the referenced resource changes. Provides
  187. * a weak handle of the resource, or empty handle if no resource is referenced.
  188. */
  189. Event<void(const WeakResourceHandle<Resource>&)> onValueChanged;
  190. private:
  191. virtual ~GUIResourceField();
  192. /**
  193. * @brief Sets the resource referenced by the field by finding
  194. * the resource with the provided UUID.
  195. *
  196. * @param uuid Unique resource identifier of the resource to show, or empty string if no resource.
  197. * @param triggerEvent Determines should the ::onValueChanged event be triggered if the new UUID is different
  198. * from the previous one.
  199. */
  200. void setUUID(const String& uuid, bool triggerEvent = true);
  201. /**
  202. * @copydoc GUIElement::styleUpdated
  203. */
  204. void styleUpdated() override;
  205. /**
  206. * @brief Triggered when a drag and drop operation finishes over this element.
  207. */
  208. void dataDropped(void* data);
  209. /**
  210. * @brief Triggered when the drop button that displays the game object label is clicked.
  211. */
  212. void onDropButtonClicked();
  213. /**
  214. * @brief Triggered when the clear button is clicked.
  215. */
  216. void onClearButtonClicked();
  217. private:
  218. static const UINT32 DEFAULT_LABEL_WIDTH;
  219. GUILayout* mLayout;
  220. GUILabel* mLabel;
  221. GUIDropButton* mDropButton;
  222. GUIButton* mClearButton;
  223. String mNamespace;
  224. String mType;
  225. String mUUID;
  226. };
  227. }