BsGUIGameObjectField.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 GameObject can be dragged and dropped.
  10. * The field accepts a GameObject of a specific type and displays an optional label.
  11. */
  12. class BS_SCR_BED_EXPORT GUIGameObjectField : 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 game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIOptions& options, const String& style = StringUtil::BLANK);
  90. /**
  91. * @brief Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, UINT32 labelWidth,
  102. const String& style = StringUtil::BLANK);
  103. /**
  104. * @brief Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent,
  114. const String& style = StringUtil::BLANK);
  115. /**
  116. * @brief Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const HString& labelText, UINT32 labelWidth,
  127. const String& style = StringUtil::BLANK);
  128. /**
  129. * @brief Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const HString& labelText,
  139. const String& style = StringUtil::BLANK);
  140. /**
  141. * @brief Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const String& style = StringUtil::BLANK);
  150. GUIGameObjectField(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 game object currently referenced by the field, if any.
  154. */
  155. HGameObject getValue() const;
  156. /**
  157. * @brief Sets the game object referenced by the field.
  158. */
  159. void setValue(const HGameObject& value);
  160. /**
  161. * @copydoc GUIElement::setTint
  162. */
  163. virtual void setTint(const Color& color) override;
  164. /**
  165. * @copydoc GUIElement::_updateLayoutInternal
  166. */
  167. void _updateLayoutInternal(const GUILayoutData& data) override;
  168. /**
  169. * @copydoc GUIElement::_getOptimalSize
  170. */
  171. Vector2I _getOptimalSize() const override;
  172. /**
  173. * @brief Triggered whenever the referenced game object changes.
  174. */
  175. Event<void(const HGameObject&)> onValueChanged;
  176. private:
  177. virtual ~GUIGameObjectField();
  178. /**
  179. * @brief Sets the game object referenced by the field.
  180. *
  181. * @param value Game object to reference.
  182. * @param triggerEvent Determines should the ::onValueChanged event be triggered if the new object is different
  183. * from the previous one.
  184. */
  185. void setValue(const HGameObject& value, bool triggerEvent);
  186. /**
  187. * @copydoc GUIElement::styleUpdated
  188. */
  189. void styleUpdated() override;
  190. /**
  191. * @brief Triggered when a drag and drop operation finishes over this element.
  192. */
  193. void dataDropped(void* data);
  194. /**
  195. * @brief Triggered when the drop button that displays the game object label is clicked.
  196. */
  197. void onDropButtonClicked();
  198. /**
  199. * @brief Triggered when the clear button is clicked.
  200. */
  201. void onClearButtonClicked();
  202. private:
  203. static const UINT32 DEFAULT_LABEL_WIDTH;
  204. GUILayout* mLayout;
  205. GUILabel* mLabel;
  206. GUIDropButton* mDropButton;
  207. GUIButton* mClearButton;
  208. String mType;
  209. String mNamespace;
  210. UINT64 mInstanceId;
  211. };
  212. }