BsGUIGameObjectField.h 10 KB

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