| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
- // Please see LICENSE.md in repository root for license information
- // https://github.com/AtomicGameEngine/AtomicGameEngine
- #include "AtomicEditor.h"
- #include <TurboBadger/tb_editfield.h>
- #include <Atomic/Core/Context.h>
- #include <Atomic/IO/Log.h>
- #include <Atomic/IO/FileSystem.h>
- #include <Atomic/Resource/ResourceEvents.h>
- #include <Atomic/Scene/Component.h>
- #include <Atomic/UI/UI.h>
- #include "AEEditor.h"
- #include "AEEvents.h"
- #include "UIInspectorDataBinding.h"
- #include "UIInspectorFrame.h"
- #include "UI/Modal/UIModalOps.h"
- using namespace tb;
- namespace AtomicEditor
- {
- InspectorFrame::InspectorFrame(Context* context) :
- UIWidget(context, true)
- {
- SetGravity(WIDGET_GRAVITY_TOP_BOTTOM);
- InitializeSources();
- SubscribeToEvent(E_EDITORACTIVENODECHANGE, HANDLER(InspectorFrame, HandleEditorActiveNodeChange));
- }
- InspectorFrame::~InspectorFrame()
- {
- }
- void InspectorFrame::InitializeSources()
- {
- /*
- componentCreateSource.AddItem(new MenubarItem("Audio", &audioCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Geometry", &geometryCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Logic", &logicCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Navigation", &navigationCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Network", &networkCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Physics", &physicsCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Scene", &sceneCreateSource));
- componentCreateSource.AddItem(new MenubarItem("Subsystem", &subsystemCreateSource));
- audioCreateSource.AddItem(new MenubarItem("SoundListener", TBIDC("create component")));
- audioCreateSource.AddItem(new MenubarItem("SoundSource", TBIDC("create component")));
- audioCreateSource.AddItem(new MenubarItem("SoundSource3D", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("AnimatedModel", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("BillboardSet", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("CustomGeometry", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("ParticleEmitter", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("Skybox", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("StaticModel", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("StaticModelGroup", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("Terrain", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("Text3D", TBIDC("create component")));
- geometryCreateSource.AddItem(new MenubarItem("Water", TBIDC("create component")));
- logicCreateSource.AddItem(new MenubarItem("AnimationController", TBIDC("create component")));
- logicCreateSource.AddItem(new MenubarItem("Javascript Component", TBIDC("create component")));
- logicCreateSource.AddItem(new MenubarItem("SplinePath", TBIDC("create component")));
- navigationCreateSource.AddItem(new MenubarItem("Navigable", TBIDC("create component")));
- navigationCreateSource.AddItem(new MenubarItem("NavigationMesh", TBIDC("create component")));
- navigationCreateSource.AddItem(new MenubarItem("OffMeshConnection", TBIDC("create component")));
- networkCreateSource.AddItem(new MenubarItem("Network Priority", TBIDC("create component")));
- physicsCreateSource.AddItem(new MenubarItem("CollisionShape", TBIDC("create component")));
- physicsCreateSource.AddItem(new MenubarItem("Constraint", TBIDC("create component")));
- physicsCreateSource.AddItem(new MenubarItem("RigidBody", TBIDC("create component")));
- sceneCreateSource.AddItem(new MenubarItem("Camera", TBIDC("create component")));
- sceneCreateSource.AddItem(new MenubarItem("Light", TBIDC("create component")));
- sceneCreateSource.AddItem(new MenubarItem("Zone", TBIDC("create component")));
- subsystemCreateSource.AddItem(new MenubarItem("DebugRenderer", TBIDC("create component")));
- subsystemCreateSource.AddItem(new MenubarItem("Octree", TBIDC("create component")));
- subsystemCreateSource.AddItem(new MenubarItem("PhysicsWorld", TBIDC("create component")));
- */
- }
- bool InspectorFrame::OnEvent(const TBWidgetEvent &ev)
- {
- for (unsigned i = 0; i < dataBindings_.Size(); i++)
- dataBindings_[i]->OnEvent(ev);
- return false;
- }
- void InspectorFrame::InspectNode(Node* node)
- {
- if (node_ == node)
- return;
- node_ = node;
- TBLayout* inspectorContainer = GetInternalWidget()->GetWidgetByIDAndType<TBLayout>(TBIDC("inspectorcontainer"));
- assert(inspectorContainer);
- inspectorContainer->DeleteAllChildren();
- for (unsigned i = 0; i < dataBindings_.Size(); i++)
- delete dataBindings_[i];
- dataBindings_.Clear();
- if (!node_)
- {
- return;
- }
- else
- {
- TBFontDescription fd;
- fd.SetID(TBIDC("Vera"));
- fd.SetSize(11);
- LayoutParams nlp;
- nlp.SetWidth(304);
- TBLayout* nodeLayout = new TBLayout(AXIS_Y);
- nodeLayout->SetSpacing(4);
- nodeLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
- nodeLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
- nodeLayout->SetLayoutParams(nlp);
- TBContainer* nodeContainer = new TBContainer();
- nodeContainer->SetGravity(WIDGET_GRAVITY_ALL);
- nodeContainer->SetSkinBg("InspectorTopLayout");
- TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
- attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
- attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
- nodeContainer->AddChild(attrsVerticalLayout);
- TBTextField* nodeLabel = new TBTextField();
- nodeLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
- nodeLabel->SetText("Node");
- nodeLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
- attrsVerticalLayout->AddChild(nodeLabel);
- const Vector<AttributeInfo>* attrs = node->GetAttributes();
- for (unsigned i = 0; i < attrs->Size(); i++)
- {
- const AttributeInfo* attr = &attrs->At(i);
- InspectorDataBinding* binding = InspectorDataBinding::Create(node, attr);
- if (binding)
- {
- dataBindings_.Push(binding);
- TBLayout* attrLayout = new TBLayout();
- if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
- {
- attrLayout->SetAxis(AXIS_Y);
- attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
- attrLayout->SetSkinBg("InspectorVectorAttrLayout");
- }
- attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
- TBTextField* name = new TBTextField();
- name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
- name->SetSkinBg(TBIDC("InspectorTextAttrName"));
- String bname = attr->name_;
- if (bname == "Is Enabled")
- bname = "Enabled";
- name->SetText(bname.CString());
- name->SetFontDescription(fd);
- attrLayout->AddChild(name);
- TBWidget* bwidget = binding->GetWidget();
- attrLayout->AddChild(bwidget);
- attrsVerticalLayout->AddChild(attrLayout);
- }
- }
- nodeLayout->AddChild(nodeContainer);
- TBLayout* componentsLayout = new TBLayout();
- TBTextField* componentsLabel = new TBTextField();
- componentsLabel->SetText("Components");
- componentsLabel->SetSkinBg(TBIDC("InspectorTextLabel"));
- componentsLabel->SetTextAlign(TB_TEXT_ALIGN_LEFT);
- componentsLayout->AddChild(componentsLabel);
- TBButton* create = new TBButton();
- LayoutParams createLP;
- createLP.SetHeight(20);
- create->SetLayoutParams(createLP);
- create->SetFontDescription(fd);
- create->SetText("Create");
- create->SetID(TBIDC("create button"));
- componentsLayout->AddChild(create);
- nodeLayout->AddChild(componentsLayout);
- const Vector<SharedPtr<Component> > components = node->GetComponents();
- for (unsigned i = 0; i < components.Size(); i++)
- {
- Component* c = components[i];
- TBContainer* componentContainer = new TBContainer();
- componentContainer->SetSkinBg("InspectorTopLayout");
- componentContainer->SetGravity(WIDGET_GRAVITY_ALL);
- TBLayout* attrsVerticalLayout = new TBLayout(AXIS_Y);
- attrsVerticalLayout->SetGravity(WIDGET_GRAVITY_ALL);
- attrsVerticalLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
- attrsVerticalLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
- TBTextField* cnameField = new TBTextField();
- cnameField->SetText(c->GetTypeName().CString());
- cnameField->SetSkinBg(TBIDC("InspectorTextLabel"));
- cnameField->SetTextAlign(TB_TEXT_ALIGN_LEFT);
- cnameField->SetFontDescription(fd);
- attrsVerticalLayout->AddChild(cnameField);
- componentContainer->AddChild(attrsVerticalLayout);
- const Vector<AttributeInfo>* attrs = c->GetAttributes();
- if (attrs)
- for (unsigned i = 0; i < attrs->Size(); i++)
- {
- const AttributeInfo* attr = &attrs->At(i);
- InspectorDataBinding* binding = InspectorDataBinding::Create(c, attr);
- if (binding)
- {
- dataBindings_.Push(binding);
- TBLayout* attrLayout = new TBLayout();
- attrLayout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
- if (attr->type_ == VAR_VECTOR3 || attr->type_ == VAR_COLOR || attr->type_ == VAR_QUATERNION)
- {
- attrLayout->SetAxis(AXIS_Y);
- attrLayout->SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP);
- attrLayout->SetSkinBg("InspectorVectorAttrLayout");
- }
- TBTextField* name = new TBTextField();
- String bname = attr->name_;
- if (bname == "Is Enabled")
- bname = "Enabled";
- name->SetTextAlign(TB_TEXT_ALIGN_LEFT);
- name->SetText(bname.CString());
- name->SetFontDescription(fd);
- name->SetSkinBg(TBIDC("InspectorTextAttrName"));
- LayoutParams lp;
- lp.SetWidth(140);
- name->SetLayoutParams(lp);
- attrLayout->AddChild(name);
- TBWidget* bwidget = binding->GetWidget();
- attrLayout->AddChild(bwidget);
- attrsVerticalLayout->AddChild(attrLayout);
- }
- }
- nodeLayout->AddChild(componentContainer);
- }
- inspectorContainer->AddChild(nodeLayout);
- for (unsigned i = 0; i < dataBindings_.Size(); i++)
- dataBindings_[i]->SetWidgetValueFromObject();
- }
- }
- void InspectorFrame::HandleEditorActiveNodeChange(StringHash eventType, VariantMap& eventData)
- {
- Node* node = (Node*) (eventData[EditorActiveNodeChange::P_NODE].GetPtr());
- InspectNode(node);
- }
- }
|