BsGUIGameObjectField.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include "BsGUIGameObjectField.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIDropButton.h"
  6. #include "BsGUIButton.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsGUIWidget.h"
  9. #include "BsGUIMouseEvent.h"
  10. #include "BsGUISceneTreeView.h"
  11. #include "BsGUIWidget.h"
  12. #include "BsGameObjectManager.h"
  13. using namespace std::placeholders;
  14. namespace BansheeEngine
  15. {
  16. const UINT32 GUIGameObjectField::DEFAULT_LABEL_WIDTH = 100;
  17. GUIGameObjectField::GUIGameObjectField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  18. const String& style, const GUILayoutOptions& layoutOptions, bool withLabel)
  19. :GUIElementContainer(layoutOptions, style), mLabel(nullptr), mClearButton(nullptr), mDropButton(nullptr), mInstanceId(0)
  20. {
  21. mLayout = &addLayoutXInternal(this);
  22. if(withLabel)
  23. {
  24. mLabel = GUILabel::create(labelContent, GUIOptions(GUIOption::fixedWidth(labelWidth)), getSubStyleName(getLabelStyleType()));
  25. mLayout->addElement(mLabel);
  26. }
  27. mDropButton = GUIDropButton::create((UINT32)DragAndDropType::SceneObject, GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getDropButtonStyleType()));
  28. mClearButton = GUIButton::create(HString(L""), getSubStyleName(getClearButtonStyleType()));
  29. mLayout->addElement(mDropButton);
  30. mLayout->addElement(mClearButton);
  31. mDropButton->onDataDropped.connect(std::bind(&GUIGameObjectField::dataDropped, this, _1));
  32. }
  33. GUIGameObjectField::~GUIGameObjectField()
  34. {
  35. }
  36. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& layoutOptions,
  37. const String& style)
  38. {
  39. const String* curStyle = &style;
  40. if (*curStyle == StringUtil::BLANK)
  41. curStyle = &getGUITypeName();
  42. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  43. GUILayoutOptions::create(layoutOptions), true);
  44. }
  45. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, const GUIOptions& layoutOptions,
  46. const String& style)
  47. {
  48. const String* curStyle = &style;
  49. if (*curStyle == StringUtil::BLANK)
  50. curStyle = &getGUITypeName();
  51. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  52. GUILayoutOptions::create(layoutOptions), true);
  53. }
  54. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, UINT32 labelWidth, const GUIOptions& layoutOptions,
  55. const String& style)
  56. {
  57. const String* curStyle = &style;
  58. if (*curStyle == StringUtil::BLANK)
  59. curStyle = &getGUITypeName();
  60. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  61. GUILayoutOptions::create(layoutOptions), true);
  62. }
  63. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, const GUIOptions& layoutOptions,
  64. const String& style)
  65. {
  66. const String* curStyle = &style;
  67. if (*curStyle == StringUtil::BLANK)
  68. curStyle = &getGUITypeName();
  69. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  70. GUILayoutOptions::create(layoutOptions), true);
  71. }
  72. GUIGameObjectField* GUIGameObjectField::create(const GUIOptions& layoutOptions, const String& style)
  73. {
  74. const String* curStyle = &style;
  75. if (*curStyle == StringUtil::BLANK)
  76. curStyle = &getGUITypeName();
  77. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  78. GUILayoutOptions::create(layoutOptions), false);
  79. }
  80. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, UINT32 labelWidth,
  81. const String& style)
  82. {
  83. const String* curStyle = &style;
  84. if (*curStyle == StringUtil::BLANK)
  85. curStyle = &getGUITypeName();
  86. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, *curStyle,
  87. GUILayoutOptions::create(), true);
  88. }
  89. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent,
  90. const String& style)
  91. {
  92. const String* curStyle = &style;
  93. if (*curStyle == StringUtil::BLANK)
  94. curStyle = &getGUITypeName();
  95. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, *curStyle,
  96. GUILayoutOptions::create(), true);
  97. }
  98. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, UINT32 labelWidth,
  99. const String& style)
  100. {
  101. const String* curStyle = &style;
  102. if (*curStyle == StringUtil::BLANK)
  103. curStyle = &getGUITypeName();
  104. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, *curStyle,
  105. GUILayoutOptions::create(), true);
  106. }
  107. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText,
  108. const String& style)
  109. {
  110. const String* curStyle = &style;
  111. if (*curStyle == StringUtil::BLANK)
  112. curStyle = &getGUITypeName();
  113. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, *curStyle,
  114. GUILayoutOptions::create(), true);
  115. }
  116. GUIGameObjectField* GUIGameObjectField::create(const String& style)
  117. {
  118. const String* curStyle = &style;
  119. if (*curStyle == StringUtil::BLANK)
  120. curStyle = &getGUITypeName();
  121. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(), 0, *curStyle,
  122. GUILayoutOptions::create(), false);
  123. }
  124. HGameObject GUIGameObjectField::getValue() const
  125. {
  126. HGameObject obj;
  127. if(mInstanceId != 0)
  128. GameObjectManager::instance().tryGetObject(mInstanceId, obj);
  129. return obj;
  130. }
  131. void GUIGameObjectField::setValue(const HGameObject& value)
  132. {
  133. if(value)
  134. {
  135. mInstanceId = value->getInstanceId();
  136. mDropButton->setContent(GUIContent(HString(toWString(value->getName()))));
  137. }
  138. else
  139. {
  140. mInstanceId = 0;
  141. mDropButton->setContent(GUIContent(HString(L"None")));
  142. }
  143. }
  144. void GUIGameObjectField::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  145. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  146. {
  147. mLayout->_updateLayoutInternal(x, y, width, height, clipRect, widgetDepth, areaDepth);
  148. }
  149. Vector2I GUIGameObjectField::_getOptimalSize() const
  150. {
  151. return mLayout->_getOptimalSize();
  152. }
  153. void GUIGameObjectField::dataDropped(void* data)
  154. {
  155. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(data);
  156. // TODO
  157. }
  158. void GUIGameObjectField::styleUpdated()
  159. {
  160. if (mLabel != nullptr)
  161. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  162. mDropButton->setStyle(getSubStyleName(getDropButtonStyleType()));
  163. mClearButton->setStyle(getSubStyleName(getClearButtonStyleType()));
  164. }
  165. const String& GUIGameObjectField::getGUITypeName()
  166. {
  167. static String typeName = "GUIGameObjectField";
  168. return typeName;
  169. }
  170. const String& GUIGameObjectField::getLabelStyleType()
  171. {
  172. static String STYLE_TYPE = "EditorFieldLabel";
  173. return STYLE_TYPE;
  174. }
  175. const String& GUIGameObjectField::getDropButtonStyleType()
  176. {
  177. static String typeName = "DropButton";
  178. return typeName;
  179. }
  180. const String& GUIGameObjectField::getClearButtonStyleType()
  181. {
  182. static String typeName = "ObjectClearButton";
  183. return typeName;
  184. }
  185. }