BsGUIGameObjectField.cpp 7.4 KB

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