UIInspectorFrame.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_editfield.h>
  6. #include <Atomic/Core/Context.h>
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/Resource/ResourceEvents.h>
  10. #include <Atomic/Scene/Component.h>
  11. #include <Atomic/UI/UI.h>
  12. #include "AEEditor.h"
  13. #include "AEEvents.h"
  14. #include "UIInspectorDataBinding.h"
  15. #include "UIInspectorFrame.h"
  16. #include "UI/Modal/UIModalOps.h"
  17. using namespace tb;
  18. namespace AtomicEditor
  19. {
  20. InspectorFrame::InspectorFrame(Context* context) :
  21. UIWidget(context, true)
  22. {
  23. SetGravity(WIDGET_GRAVITY_TOP_BOTTOM);
  24. InitializeSources();
  25. SubscribeToEvent(E_EDITORACTIVENODECHANGE, HANDLER(InspectorFrame, HandleEditorActiveNodeChange));
  26. }
  27. InspectorFrame::~InspectorFrame()
  28. {
  29. }
  30. void InspectorFrame::InitializeSources()
  31. {
  32. /*
  33. componentCreateSource.AddItem(new MenubarItem("Audio", &audioCreateSource));
  34. componentCreateSource.AddItem(new MenubarItem("Geometry", &geometryCreateSource));
  35. componentCreateSource.AddItem(new MenubarItem("Logic", &logicCreateSource));
  36. componentCreateSource.AddItem(new MenubarItem("Navigation", &navigationCreateSource));
  37. componentCreateSource.AddItem(new MenubarItem("Network", &networkCreateSource));
  38. componentCreateSource.AddItem(new MenubarItem("Physics", &physicsCreateSource));
  39. componentCreateSource.AddItem(new MenubarItem("Scene", &sceneCreateSource));
  40. componentCreateSource.AddItem(new MenubarItem("Subsystem", &subsystemCreateSource));
  41. audioCreateSource.AddItem(new MenubarItem("SoundListener", TBIDC("create component")));
  42. audioCreateSource.AddItem(new MenubarItem("SoundSource", TBIDC("create component")));
  43. audioCreateSource.AddItem(new MenubarItem("SoundSource3D", TBIDC("create component")));
  44. geometryCreateSource.AddItem(new MenubarItem("AnimatedModel", TBIDC("create component")));
  45. geometryCreateSource.AddItem(new MenubarItem("BillboardSet", TBIDC("create component")));
  46. geometryCreateSource.AddItem(new MenubarItem("CustomGeometry", TBIDC("create component")));
  47. geometryCreateSource.AddItem(new MenubarItem("ParticleEmitter", TBIDC("create component")));
  48. geometryCreateSource.AddItem(new MenubarItem("Skybox", TBIDC("create component")));
  49. geometryCreateSource.AddItem(new MenubarItem("StaticModel", TBIDC("create component")));
  50. geometryCreateSource.AddItem(new MenubarItem("StaticModelGroup", TBIDC("create component")));
  51. geometryCreateSource.AddItem(new MenubarItem("Terrain", TBIDC("create component")));
  52. geometryCreateSource.AddItem(new MenubarItem("Text3D", TBIDC("create component")));
  53. geometryCreateSource.AddItem(new MenubarItem("Water", TBIDC("create component")));
  54. logicCreateSource.AddItem(new MenubarItem("AnimationController", TBIDC("create component")));
  55. logicCreateSource.AddItem(new MenubarItem("Javascript Component", TBIDC("create component")));
  56. logicCreateSource.AddItem(new MenubarItem("SplinePath", TBIDC("create component")));
  57. navigationCreateSource.AddItem(new MenubarItem("Navigable", TBIDC("create component")));
  58. navigationCreateSource.AddItem(new MenubarItem("NavigationMesh", TBIDC("create component")));
  59. navigationCreateSource.AddItem(new MenubarItem("OffMeshConnection", TBIDC("create component")));
  60. networkCreateSource.AddItem(new MenubarItem("Network Priority", TBIDC("create component")));
  61. physicsCreateSource.AddItem(new MenubarItem("CollisionShape", TBIDC("create component")));
  62. physicsCreateSource.AddItem(new MenubarItem("Constraint", TBIDC("create component")));
  63. physicsCreateSource.AddItem(new MenubarItem("RigidBody", TBIDC("create component")));
  64. sceneCreateSource.AddItem(new MenubarItem("Camera", TBIDC("create component")));
  65. sceneCreateSource.AddItem(new MenubarItem("Light", TBIDC("create component")));
  66. sceneCreateSource.AddItem(new MenubarItem("Zone", TBIDC("create component")));
  67. subsystemCreateSource.AddItem(new MenubarItem("DebugRenderer", TBIDC("create component")));
  68. subsystemCreateSource.AddItem(new MenubarItem("Octree", TBIDC("create component")));
  69. subsystemCreateSource.AddItem(new MenubarItem("PhysicsWorld", TBIDC("create component")));
  70. */
  71. }
  72. bool InspectorFrame::OnEvent(const TBWidgetEvent &ev)
  73. {
  74. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  75. dataBindings_[i]->OnEvent(ev);
  76. return false;
  77. }
  78. void InspectorFrame::InspectNode(Node* node)
  79. {
  80. if (node_ == node)
  81. return;
  82. node_ = node;
  83. TBLayout* inspectorContainer = GetInternalWidget()->GetWidgetByIDAndType<TBLayout>(TBIDC("inspectorcontainer"));
  84. assert(inspectorContainer);
  85. inspectorContainer->DeleteAllChildren();
  86. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  87. delete dataBindings_[i];
  88. dataBindings_.Clear();
  89. if (!node_)
  90. {
  91. return;
  92. }
  93. else
  94. {
  95. TBFontDescription fd;
  96. fd.SetID(TBIDC("Vera"));
  97. fd.SetSize(11);
  98. LayoutParams nlp;
  99. nlp.SetWidth(304);
  100. TBLayout* nodeLayout = new TBLayout(AXIS_Y);
  101. nodeLayout->SetSpacing(4);
  102. nodeLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  103. nodeLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  104. nodeLayout->SetLayoutParams(nlp);
  105. TBContainer* nodeContainer = new TBContainer();
  106. nodeContainer->SetGravity(WIDGET_GRAVITY_ALL);
  107. nodeContainer->SetSkinBg("InspectorTopLayout");
  108. TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
  109. attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
  110. attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  111. nodeContainer->AddChild(attrsVerticalLayout);
  112. TBTextField* nodeLabel = new TBTextField();
  113. nodeLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  114. nodeLabel->SetText("Node");
  115. nodeLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
  116. attrsVerticalLayout->AddChild(nodeLabel);
  117. const Vector<AttributeInfo>* attrs = node->GetAttributes();
  118. for (unsigned i = 0; i < attrs->Size(); i++)
  119. {
  120. const AttributeInfo* attr = &attrs->At(i);
  121. InspectorDataBinding* binding = InspectorDataBinding::Create(node, attr);
  122. if (binding)
  123. {
  124. dataBindings_.Push(binding);
  125. TBLayout* attrLayout = new TBLayout();
  126. if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
  127. {
  128. attrLayout->SetAxis(AXIS_Y);
  129. attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  130. attrLayout->SetSkinBg("InspectorVectorAttrLayout");
  131. }
  132. attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  133. TBTextField* name = new TBTextField();
  134. name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  135. name->SetSkinBg(TBIDC("InspectorTextAttrName"));
  136. String bname = attr->name_;
  137. if (bname == "Is Enabled")
  138. bname = "Enabled";
  139. name->SetText(bname.CString());
  140. name->SetFontDescription(fd);
  141. attrLayout->AddChild(name);
  142. TBWidget* bwidget = binding->GetWidget();
  143. attrLayout->AddChild(bwidget);
  144. attrsVerticalLayout->AddChild(attrLayout);
  145. }
  146. }
  147. nodeLayout->AddChild(nodeContainer);
  148. TBLayout* componentsLayout = new TBLayout();
  149. TBTextField* componentsLabel = new TBTextField();
  150. componentsLabel->SetText("Components");
  151. componentsLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
  152. componentsLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  153. componentsLayout->AddChild(componentsLabel);
  154. TBButton* create = new TBButton();
  155. LayoutParams createLP;
  156. createLP.SetHeight(20);
  157. create->SetLayoutParams(createLP);
  158. create->SetFontDescription(fd);
  159. create->SetText("Create");
  160. create->SetID(TBIDC("create button"));
  161. componentsLayout->AddChild(create);
  162. nodeLayout->AddChild(componentsLayout);
  163. const Vector<SharedPtr<Component> > components = node->GetComponents();
  164. for (unsigned i = 0; i < components.Size(); i++)
  165. {
  166. Component* c = components[i];
  167. TBContainer* componentContainer = new TBContainer();
  168. componentContainer->SetSkinBg("InspectorTopLayout");
  169. componentContainer->SetGravity(WIDGET_GRAVITY_ALL);
  170. TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
  171. attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
  172. attrsVerticalLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  173. attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  174. TBTextField* cnameField = new TBTextField();
  175. cnameField->SetText(c->GetTypeName().CString());
  176. cnameField->SetSkinBg(TBIDC("InspectorTextLabel"));
  177. cnameField->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  178. cnameField->SetFontDescription(fd);
  179. attrsVerticalLayout->AddChild(cnameField);
  180. componentContainer->AddChild(attrsVerticalLayout);
  181. const Vector<AttributeInfo>* attrs = c->GetAttributes();
  182. if (attrs)
  183. for (unsigned i = 0; i < attrs->Size(); i++)
  184. {
  185. const AttributeInfo* attr = &attrs->At(i);
  186. InspectorDataBinding* binding = InspectorDataBinding::Create(c, attr);
  187. if (binding)
  188. {
  189. dataBindings_.Push(binding);
  190. TBLayout* attrLayout = new TBLayout();
  191. attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  192. if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
  193. {
  194. attrLayout->SetAxis(AXIS_Y);
  195. attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  196. attrLayout->SetSkinBg("InspectorVectorAttrLayout");
  197. }
  198. TBTextField* name = new TBTextField();
  199. String bname = attr->name_;
  200. if (bname == "Is Enabled")
  201. bname = "Enabled";
  202. name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  203. name->SetText(bname.CString());
  204. name->SetFontDescription(fd);
  205. name->SetSkinBg(TBIDC("InspectorTextAttrName"));
  206. LayoutParams lp;
  207. lp.SetWidth(140);
  208. name->SetLayoutParams(lp);
  209. attrLayout->AddChild(name);
  210. TBWidget* bwidget = binding->GetWidget();
  211. attrLayout->AddChild(bwidget);
  212. attrsVerticalLayout->AddChild(attrLayout);
  213. }
  214. }
  215. nodeLayout->AddChild(componentContainer);
  216. }
  217. inspectorContainer->AddChild(nodeLayout);
  218. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  219. dataBindings_[i]->SetWidgetValueFromObject();
  220. }
  221. }
  222. void InspectorFrame::HandleEditorActiveNodeChange(StringHash eventType, VariantMap& eventData)
  223. {
  224. Node* node = (Node*) (eventData[EditorActiveNodeChange::P_NODE].GetPtr());
  225. InspectNode(node);
  226. }
  227. }