BsGUIResourceField.h 11 KB

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