UIInspectorFrame.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. AEWidget(context)
  22. {
  23. UI* tbui = GetSubsystem<UI>();
  24. tbui->LoadResourceFile(delegate_, "AtomicEditor/editor/ui/inspectorframe.tb.txt");
  25. delegate_->SetID(TBIDC("projectframe_delegate"));
  26. delegate_->SetGravity(WIDGET_GRAVITY_TOP_BOTTOM);
  27. inspectorContainer_ = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("inspectorcontainer"));
  28. assert(inspectorContainer_);
  29. InitializeSources();
  30. SubscribeToEvent(E_EDITORACTIVENODECHANGE, HANDLER(InspectorFrame, HandleEditorActiveNodeChange));
  31. }
  32. InspectorFrame::~InspectorFrame()
  33. {
  34. }
  35. void InspectorFrame::InitializeSources()
  36. {
  37. componentCreateSource.AddItem(new MenubarItem("Audio", &audioCreateSource));
  38. componentCreateSource.AddItem(new MenubarItem("Geometry", &geometryCreateSource));
  39. componentCreateSource.AddItem(new MenubarItem("Logic", &logicCreateSource));
  40. componentCreateSource.AddItem(new MenubarItem("Navigation", &navigationCreateSource));
  41. componentCreateSource.AddItem(new MenubarItem("Network", &networkCreateSource));
  42. componentCreateSource.AddItem(new MenubarItem("Physics", &physicsCreateSource));
  43. componentCreateSource.AddItem(new MenubarItem("Scene", &sceneCreateSource));
  44. componentCreateSource.AddItem(new MenubarItem("Subsystem", &subsystemCreateSource));
  45. audioCreateSource.AddItem(new MenubarItem("SoundListener", TBIDC("create component")));
  46. audioCreateSource.AddItem(new MenubarItem("SoundSource", TBIDC("create component")));
  47. audioCreateSource.AddItem(new MenubarItem("SoundSource3D", TBIDC("create component")));
  48. geometryCreateSource.AddItem(new MenubarItem("AnimatedModel", TBIDC("create component")));
  49. geometryCreateSource.AddItem(new MenubarItem("BillboardSet", TBIDC("create component")));
  50. geometryCreateSource.AddItem(new MenubarItem("CustomGeometry", TBIDC("create component")));
  51. geometryCreateSource.AddItem(new MenubarItem("ParticleEmitter", TBIDC("create component")));
  52. geometryCreateSource.AddItem(new MenubarItem("Skybox", TBIDC("create component")));
  53. geometryCreateSource.AddItem(new MenubarItem("StaticModel", TBIDC("create component")));
  54. geometryCreateSource.AddItem(new MenubarItem("StaticModelGroup", TBIDC("create component")));
  55. geometryCreateSource.AddItem(new MenubarItem("Terrain", TBIDC("create component")));
  56. geometryCreateSource.AddItem(new MenubarItem("Text3D", TBIDC("create component")));
  57. geometryCreateSource.AddItem(new MenubarItem("Water", TBIDC("create component")));
  58. logicCreateSource.AddItem(new MenubarItem("AnimationController", TBIDC("create component")));
  59. logicCreateSource.AddItem(new MenubarItem("Javascript Component", TBIDC("create component")));
  60. logicCreateSource.AddItem(new MenubarItem("SplinePath", TBIDC("create component")));
  61. navigationCreateSource.AddItem(new MenubarItem("Navigable", TBIDC("create component")));
  62. navigationCreateSource.AddItem(new MenubarItem("NavigationMesh", TBIDC("create component")));
  63. navigationCreateSource.AddItem(new MenubarItem("OffMeshConnection", TBIDC("create component")));
  64. networkCreateSource.AddItem(new MenubarItem("Network Priority", TBIDC("create component")));
  65. physicsCreateSource.AddItem(new MenubarItem("CollisionShape", TBIDC("create component")));
  66. physicsCreateSource.AddItem(new MenubarItem("Constraint", TBIDC("create component")));
  67. physicsCreateSource.AddItem(new MenubarItem("RigidBody", TBIDC("create component")));
  68. sceneCreateSource.AddItem(new MenubarItem("Camera", TBIDC("create component")));
  69. sceneCreateSource.AddItem(new MenubarItem("Light", TBIDC("create component")));
  70. sceneCreateSource.AddItem(new MenubarItem("Zone", TBIDC("create component")));
  71. subsystemCreateSource.AddItem(new MenubarItem("DebugRenderer", TBIDC("create component")));
  72. subsystemCreateSource.AddItem(new MenubarItem("Octree", TBIDC("create component")));
  73. subsystemCreateSource.AddItem(new MenubarItem("PhysicsWorld", TBIDC("create component")));
  74. }
  75. bool InspectorFrame::OnEvent(const TBWidgetEvent &ev)
  76. {
  77. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  78. dataBindings_[i]->OnEvent(ev);
  79. if (ev.type == EVENT_TYPE_CLICK)
  80. {
  81. if (ev.target->GetID() == TBIDC("create popup"))
  82. {
  83. if (ev.ref_id == TBIDC("create component"))
  84. {
  85. Editor* editor = GetSubsystem<Editor>();
  86. editor->PostModalInfo("Early Access - Not Implemented", "Component creation not implemented in this early access build");
  87. }
  88. }
  89. if (ev.target->GetID() == TBIDC("create button"))
  90. {
  91. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("create popup")))
  92. {
  93. menu->Show(&componentCreateSource, TBPopupAlignment(TB_ALIGN_LEFT));
  94. }
  95. return true;
  96. }
  97. }
  98. return false;
  99. }
  100. void InspectorFrame::InspectNode(Node* node)
  101. {
  102. if (node_ == node)
  103. return;
  104. node_ = node;
  105. inspectorContainer_->DeleteAllChildren();
  106. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  107. delete dataBindings_[i];
  108. dataBindings_.Clear();
  109. if (!node_)
  110. {
  111. return;
  112. }
  113. else
  114. {
  115. TBFontDescription fd;
  116. fd.SetID(TBIDC("Vera"));
  117. fd.SetSize(11);
  118. LayoutParams nlp;
  119. nlp.SetWidth(304);
  120. TBLayout* nodeLayout = new TBLayout(AXIS_Y);
  121. nodeLayout->SetSpacing(4);
  122. nodeLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  123. nodeLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  124. nodeLayout->SetLayoutParams(nlp);
  125. TBContainer* nodeContainer = new TBContainer();
  126. nodeContainer->SetGravity(WIDGET_GRAVITY_ALL);
  127. nodeContainer->SetSkinBg("InspectorTopLayout");
  128. TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
  129. attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
  130. attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  131. nodeContainer->AddChild(attrsVerticalLayout);
  132. TBTextField* nodeLabel = new TBTextField();
  133. nodeLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  134. nodeLabel->SetText("Node");
  135. nodeLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
  136. attrsVerticalLayout->AddChild(nodeLabel);
  137. const Vector<AttributeInfo>* attrs = node->GetAttributes();
  138. for (unsigned i = 0; i < attrs->Size(); i++)
  139. {
  140. const AttributeInfo* attr = &attrs->At(i);
  141. InspectorDataBinding* binding = InspectorDataBinding::Create(node, attr);
  142. if (binding)
  143. {
  144. dataBindings_.Push(binding);
  145. TBLayout* attrLayout = new TBLayout();
  146. if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
  147. {
  148. attrLayout->SetAxis(AXIS_Y);
  149. attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  150. attrLayout->SetSkinBg("InspectorVectorAttrLayout");
  151. }
  152. attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  153. TBTextField* name = new TBTextField();
  154. name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  155. name->SetSkinBg(TBIDC("InspectorTextAttrName"));
  156. String bname = attr->name_;
  157. if (bname == "Is Enabled")
  158. bname = "Enabled";
  159. name->SetText(bname.CString());
  160. name->SetFontDescription(fd);
  161. attrLayout->AddChild(name);
  162. TBWidget* bwidget = binding->GetWidget();
  163. attrLayout->AddChild(bwidget);
  164. attrsVerticalLayout->AddChild(attrLayout);
  165. }
  166. }
  167. nodeLayout->AddChild(nodeContainer);
  168. TBLayout* componentsLayout = new TBLayout();
  169. TBTextField* componentsLabel = new TBTextField();
  170. componentsLabel->SetText("Components");
  171. componentsLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
  172. componentsLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  173. componentsLayout->AddChild(componentsLabel);
  174. TBButton* create = new TBButton();
  175. LayoutParams createLP;
  176. createLP.SetHeight(20);
  177. create->SetLayoutParams(createLP);
  178. create->SetFontDescription(fd);
  179. create->SetText("Create");
  180. create->SetID(TBIDC("create button"));
  181. componentsLayout->AddChild(create);
  182. nodeLayout->AddChild(componentsLayout);
  183. const Vector<SharedPtr<Component> > components = node->GetComponents();
  184. for (unsigned i = 0; i < components.Size(); i++)
  185. {
  186. Component* c = components[i];
  187. TBContainer* componentContainer = new TBContainer();
  188. componentContainer->SetSkinBg("InspectorTopLayout");
  189. componentContainer->SetGravity(WIDGET_GRAVITY_ALL);
  190. TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
  191. attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
  192. attrsVerticalLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  193. attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  194. TBTextField* cnameField = new TBTextField();
  195. cnameField->SetText(c->GetTypeName().CString());
  196. cnameField->SetSkinBg(TBIDC("InspectorTextLabel"));
  197. cnameField->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  198. cnameField->SetFontDescription(fd);
  199. attrsVerticalLayout->AddChild(cnameField);
  200. componentContainer->AddChild(attrsVerticalLayout);
  201. const Vector<AttributeInfo>* attrs = c->GetAttributes();
  202. if (attrs)
  203. for (unsigned i = 0; i < attrs->Size(); i++)
  204. {
  205. const AttributeInfo* attr = &attrs->At(i);
  206. InspectorDataBinding* binding = InspectorDataBinding::Create(c, attr);
  207. if (binding)
  208. {
  209. dataBindings_.Push(binding);
  210. TBLayout* attrLayout = new TBLayout();
  211. attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  212. if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
  213. {
  214. attrLayout->SetAxis(AXIS_Y);
  215. attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
  216. attrLayout->SetSkinBg("InspectorVectorAttrLayout");
  217. }
  218. TBTextField* name = new TBTextField();
  219. String bname = attr->name_;
  220. if (bname == "Is Enabled")
  221. bname = "Enabled";
  222. name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  223. name->SetText(bname.CString());
  224. name->SetFontDescription(fd);
  225. name->SetSkinBg(TBIDC("InspectorTextAttrName"));
  226. LayoutParams lp;
  227. lp.SetWidth(140);
  228. name->SetLayoutParams(lp);
  229. attrLayout->AddChild(name);
  230. TBWidget* bwidget = binding->GetWidget();
  231. attrLayout->AddChild(bwidget);
  232. attrsVerticalLayout->AddChild(attrLayout);
  233. }
  234. }
  235. nodeLayout->AddChild(componentContainer);
  236. }
  237. inspectorContainer_->AddChild(nodeLayout);
  238. for (unsigned i = 0; i < dataBindings_.Size(); i++)
  239. dataBindings_[i]->SetWidgetValueFromObject();
  240. }
  241. }
  242. void InspectorFrame::HandleEditorActiveNodeChange(StringHash eventType, VariantMap& eventData)
  243. {
  244. Node* node = (Node*) (eventData[EditorActiveNodeChange::P_NODE].GetPtr());
  245. InspectNode(node);
  246. }
  247. }