BsGUIGameObjectField.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 EditorScript
  9. * @{
  10. */
  11. /**
  12. * GUI object that displays a field in which a GameObject can be dragged and dropped. The field accepts a GameObject of
  13. * a specific type and displays an optional label.
  14. */
  15. class BS_SCR_BED_EXPORT GUIGameObjectField : 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 game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, const GUIOptions& options,
  47. const String& style = StringUtil::BLANK);
  48. /**
  49. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* 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 game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const HString& labelText, const GUIOptions& options,
  74. const String& style = StringUtil::BLANK);
  75. /**
  76. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIOptions& options, const String& style = StringUtil::BLANK);
  86. /**
  87. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent, UINT32 labelWidth,
  97. const String& style = StringUtil::BLANK);
  98. /**
  99. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const GUIContent& labelContent,
  108. const String& style = StringUtil::BLANK);
  109. /**
  110. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const HString& labelText, UINT32 labelWidth,
  120. const String& style = StringUtil::BLANK);
  121. /**
  122. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const HString& labelText,
  131. const String& style = StringUtil::BLANK);
  132. /**
  133. * Creates a new game object 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 GameObject.
  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 GUIGameObjectField* create(const String& typeNamespace, const String& type, const String& style = StringUtil::BLANK);
  141. GUIGameObjectField(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 game object currently referenced by the field, if any. */
  144. HGameObject getValue() const;
  145. /** Sets the game object referenced by the field. */
  146. void setValue(const HGameObject& value);
  147. /** Triggered whenever the referenced game object changes. */
  148. Event<void(const HGameObject&)> onValueChanged;
  149. /** @name Internal
  150. * @{
  151. */
  152. /** @copydoc GUIElement::setTint */
  153. void setTint(const Color& color) override;
  154. /** @copydoc GUIElement::_updateLayoutInternal */
  155. void _updateLayoutInternal(const GUILayoutData& data) override;
  156. /** @copydoc GUIElement::_getOptimalSize */
  157. Vector2I _getOptimalSize() const override;
  158. /** @} */
  159. private:
  160. virtual ~GUIGameObjectField();
  161. /**
  162. * Sets the game object referenced by the field.
  163. *
  164. * @param[in] value Game object to reference.
  165. * @param[in] triggerEvent Determines should the onValueChanged() event be triggered if the new object is
  166. * different from the previous one.
  167. */
  168. void setValue(const HGameObject& value, bool triggerEvent);
  169. /** @copydoc GUIElement::styleUpdated */
  170. void styleUpdated() override;
  171. /** Triggered when a drag and drop operation finishes over this element. */
  172. void dataDropped(void* data);
  173. /** Triggered when the drop button that displays the game object label is clicked. */
  174. void onDropButtonClicked();
  175. /** Triggered when the clear button is clicked. */
  176. void onClearButtonClicked();
  177. private:
  178. static const UINT32 DEFAULT_LABEL_WIDTH;
  179. GUILayout* mLayout;
  180. GUILabel* mLabel;
  181. GUIDropButton* mDropButton;
  182. GUIButton* mClearButton;
  183. String mType;
  184. String mNamespace;
  185. UINT64 mInstanceId;
  186. };
  187. /** @} */
  188. }