BsGUIGameObjectField.cpp 6.5 KB

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