BsGUIGameObjectField.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 "CmGameObjectManager.h"
  13. using namespace CamelotFramework;
  14. using namespace BansheeEngine;
  15. using namespace std::placeholders;
  16. namespace BansheeEditor
  17. {
  18. const UINT32 GUIGameObjectField::DEFAULT_LABEL_WIDTH = 100;
  19. const String GUIGameObjectField::DROP_BUTTON_STYLE = "DropButton";
  20. const String GUIGameObjectField::CLEAR_BUTTON_STYLE = "ObjectClearButton";
  21. GUIGameObjectField::GUIGameObjectField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, CM::UINT32 labelWidth,
  22. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle, const GUILayoutOptions& layoutOptions, bool withLabel)
  23. :GUIElementContainer(layoutOptions), mLabel(nullptr), mClearButton(nullptr), mDropButton(nullptr), mInstanceId(0)
  24. {
  25. mLayout = &addLayoutXInternal(this);
  26. if(withLabel)
  27. {
  28. mLabel = GUILabel::create(labelContent, GUIOptions(GUIOption::fixedWidth(labelWidth)), labelStyle);
  29. mLayout->addElement(mLabel);
  30. }
  31. const String* curDropButtonStyle = &dropButtonStyle;
  32. const String* curClearButtonStyle = &clearButtonStyle;
  33. if(*curDropButtonStyle == StringUtil::BLANK)
  34. curDropButtonStyle = &DROP_BUTTON_STYLE;
  35. if(*curClearButtonStyle == StringUtil::BLANK)
  36. curClearButtonStyle = &CLEAR_BUTTON_STYLE;
  37. mDropButton = GUIDropButton::create((UINT32)DragAndDropType::SceneObject, GUIOptions(GUIOption::flexibleWidth()), *curDropButtonStyle);
  38. mClearButton = GUIButton::create(HString(L""), *curClearButtonStyle);
  39. mLayout->addElement(mDropButton);
  40. mLayout->addElement(mClearButton);
  41. mDropButton->onDataDropped.connect(std::bind(&GUIGameObjectField::dataDropped, this, _1));
  42. }
  43. GUIGameObjectField::~GUIGameObjectField()
  44. {
  45. }
  46. GUIGameObjectField* GUIGameObjectField::create(const BS::GUIContent& labelContent, CM::UINT32 labelWidth, const BS::GUIOptions& layoutOptions,
  47. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  48. {
  49. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  50. GUILayoutOptions::create(layoutOptions), true);
  51. }
  52. GUIGameObjectField* GUIGameObjectField::create(const BS::GUIContent& labelContent, const BS::GUIOptions& layoutOptions,
  53. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  54. {
  55. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  56. GUILayoutOptions::create(layoutOptions), true);
  57. }
  58. GUIGameObjectField* GUIGameObjectField::create(const CM::HString& labelText, CM::UINT32 labelWidth, const BS::GUIOptions& layoutOptions,
  59. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  60. {
  61. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(labelText), labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  62. GUILayoutOptions::create(layoutOptions), true);
  63. }
  64. GUIGameObjectField* GUIGameObjectField::create(const CM::HString& labelText, const BS::GUIOptions& layoutOptions,
  65. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  66. {
  67. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  68. GUILayoutOptions::create(layoutOptions), true);
  69. }
  70. GUIGameObjectField* GUIGameObjectField::create(const BS::GUIOptions& layoutOptions, const CM::String& dropButtonStyle,
  71. const CM::String& clearButtonStyle)
  72. {
  73. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(), 0, nullptr, dropButtonStyle, clearButtonStyle,
  74. GUILayoutOptions::create(layoutOptions), false);
  75. }
  76. GUIGameObjectField* GUIGameObjectField::create(const BS::GUIContent& labelContent, CM::UINT32 labelWidth,
  77. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  78. {
  79. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  80. GUILayoutOptions::create(), true);
  81. }
  82. GUIGameObjectField* GUIGameObjectField::create(const BS::GUIContent& labelContent,
  83. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  84. {
  85. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  86. GUILayoutOptions::create(), true);
  87. }
  88. GUIGameObjectField* GUIGameObjectField::create(const CM::HString& labelText, CM::UINT32 labelWidth,
  89. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  90. {
  91. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(labelText), labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  92. GUILayoutOptions::create(), true);
  93. }
  94. GUIGameObjectField* GUIGameObjectField::create(const CM::HString& labelText,
  95. const CM::String& labelStyle, const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  96. {
  97. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  98. GUILayoutOptions::create(), true);
  99. }
  100. GUIGameObjectField* GUIGameObjectField::create(const CM::String& dropButtonStyle, const CM::String& clearButtonStyle)
  101. {
  102. return cm_new<GUIGameObjectField>(PrivatelyConstruct(), BS::GUIContent(), 0, nullptr, dropButtonStyle, clearButtonStyle,
  103. GUILayoutOptions::create(), false);
  104. }
  105. CM::HGameObject GUIGameObjectField::getValue() const
  106. {
  107. HGameObject obj;
  108. if(mInstanceId != 0)
  109. GameObjectManager::instance().tryGetObject(mInstanceId, obj);
  110. return obj;
  111. }
  112. void GUIGameObjectField::setValue(const CM::HGameObject& value)
  113. {
  114. if(value)
  115. {
  116. mInstanceId = value->getInstanceId();
  117. mDropButton->setContent(GUIContent(HString(toWString(value->getName()))));
  118. }
  119. else
  120. {
  121. mInstanceId = 0;
  122. mDropButton->setContent(GUIContent(HString(L"None")));
  123. }
  124. }
  125. void GUIGameObjectField::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  126. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  127. {
  128. mLayout->_updateLayoutInternal(x, y, width, height, clipRect, widgetDepth, areaDepth);
  129. }
  130. Vector2I GUIGameObjectField::_getOptimalSize() const
  131. {
  132. return mLayout->_getOptimalSize();
  133. }
  134. void GUIGameObjectField::dataDropped(void* data)
  135. {
  136. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(data);
  137. // TODO
  138. }
  139. const String& GUIGameObjectField::getGUITypeName()
  140. {
  141. static String typeName = "GUIGameObjectField";
  142. return typeName;
  143. }
  144. }