Browse Source

Cleanups and selection improvements

Josh Engebretson 10 years ago
parent
commit
1dc15dc751

+ 24 - 4
Script/AtomicEditor/ui/HierarchyFrame.ts

@@ -1,8 +1,6 @@
 
 class HierarchyFrame extends Atomic.UIWidget {
 
-    hierList: Atomic.UIListView;
-
     constructor(parent: Atomic.UIWidget) {
 
         super();
@@ -22,13 +20,21 @@ class HierarchyFrame extends Atomic.UIWidget {
 
         hierarchycontainer.addChild(hierList);
 
-        //this.subscribeToEvent("NodeAdded", (data) => this.handleNodeAdded(data));
-
         this.subscribeToEvent("EditorUpdateHierarchy", (data) => this.handleUpdateHierarchy(data));
 
         this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
+
         this.subscribeToEvent("EditorActiveSceneChanged", (data) => this.handleActiveSceneChanged(data));
 
+        this.subscribeToEvent("EditorActiveNodeChange", (data) => {
+
+            if (data.node)
+              this.hierList.selectItemByID(data.node.id.toString());
+
+        });
+
+
+
     }
 
     recursiveAddNode(parentID: number, node: Atomic.Node) {
@@ -79,8 +85,21 @@ class HierarchyFrame extends Atomic.UIWidget {
 
     handleActiveSceneChanged(data) {
 
+        if (this.scene)
+          this.unsubscribeFromEvents(this.scene);
+
         this.scene = <Atomic.Scene> data.scene;
 
+        if (this.scene) {
+
+          this.subscribeToEvent("NodeRemoved", (data) => {
+
+              this.hierList.deleteItemByID(data.node.id.toString());
+
+          });
+
+        }
+
         this.refresh();
 
     }
@@ -108,6 +127,7 @@ class HierarchyFrame extends Atomic.UIWidget {
     }
 
     scene: Atomic.Scene = null;
+    hierList: Atomic.UIListView;
 
 }
 

+ 23 - 7
Script/AtomicEditor/ui/inspector/ComponentInspector.ts

@@ -18,11 +18,11 @@ class ComponentInspector extends Atomic.UISection {
 
         for (var i = 0; i < this.bindings.length; i++) {
 
-          if (this.bindings[i].handleWidgetEvent(ev)) {
+            if (this.bindings[i].handleWidgetEvent(ev)) {
 
-            handled = true;
+                handled = true;
 
-          }
+            }
 
         }
 
@@ -34,6 +34,7 @@ class ComponentInspector extends Atomic.UISection {
 
     inspect(component: Atomic.Component) {
 
+        this.component = component;
         this.text = component.getTypeName();
         // don't example by default
         this.value = 0;
@@ -100,16 +101,31 @@ class ComponentInspector extends Atomic.UISection {
 
         }
 
-        for (var i in this.bindings)
-        {
+        var deleteButton = new Atomic.UIButton();
+        deleteButton.text = "Delete Component";
+        deleteButton.fontDescription = fd;
+
+        deleteButton.onClick = () => {
+
+            var node = this.component.node;
+            this.component.remove();
+            this.sendEvent("EditorActiveNodeChange", { node: node });
+
+            return true;
+
+        }
+
+        attrsVerticalLayout.addChild(deleteButton);
+
+        for (var i in this.bindings) {
             this.bindings[i].setWidgetValueFromObject();
             this.bindings[i].objectLocked = false;
         }
 
-
     }
 
-    bindings:Array<DataBinding> = new Array();
+    component: Atomic.Component;
+    bindings: Array<DataBinding> = new Array();
 
 
 }

+ 5 - 6
Script/AtomicEditor/ui/inspector/NodeInspector.ts

@@ -92,7 +92,7 @@ class NodeInspector extends ScriptWidget {
 
 
     inspect(node: Atomic.Node) {
-      
+
         this.bindings = new Array();
 
         this.node = node;
@@ -193,7 +193,7 @@ class NodeInspector extends ScriptWidget {
           saveButton.text = "Save";
           saveButton.fontDescription = fd;
 
-          saveButton.onClick = function() {
+          saveButton.onClick = () => {
 
             var prefabComponent = this.getPrefabComponent(this.node);
 
@@ -207,13 +207,13 @@ class NodeInspector extends ScriptWidget {
 
             }
 
-          }.bind(this);
+          }
 
           var undoButton = new Atomic.UIButton();
           undoButton.text = "Undo";
           undoButton.fontDescription = fd;
 
-          undoButton.onClick = function() {
+          undoButton.onClick = () => {
 
             var prefabComponent = this.getPrefabComponent(this.node);
 
@@ -227,8 +227,7 @@ class NodeInspector extends ScriptWidget {
 
             }
 
-          }.bind(this);
-
+          }
 
           prefabLayout.addChild(name);
           prefabLayout.addChild(saveButton);

+ 2 - 0
Script/TypeScript/Atomic.d.ts

@@ -6974,6 +6974,7 @@ declare module Atomic {
       constructor(createWidget?: boolean);
 
       setSqueezable(value: boolean): void;
+      onClick: () => void;
 
    }
 
@@ -7111,6 +7112,7 @@ declare module Atomic {
 
       addRootItem(text: string, icon: string, id: string): number;
       addChildItem(parentItemID: number, text: string, icon: string, id: string): number;
+      deleteItemByID(id: string): void;
       setExpanded(itemID: number, value: boolean): void;
       deleteAllItems(): void;
       selectItemByID(id: string): void;

+ 6 - 0
Source/Atomic/Scene/PrefabComponent.cpp

@@ -101,6 +101,12 @@ void PrefabComponent::SetPrefabGUID(const String& guid)
 void PrefabComponent::OnNodeSet(Node* node)
 {
     Component::OnNodeSet(node);
+
+    if (!node && prefabNode_.NotNull())
+    {
+        prefabNode_->Remove();
+        prefabNode_ = NULL;
+    }
 }
 
 }

+ 14 - 0
Source/Atomic/UI/UIListView.cpp

@@ -213,6 +213,20 @@ unsigned UIListView::AddRootItem(const String& text, const String& icon, const S
     return itemLookupId_ - 1;
 }
 
+void UIListView::DeleteItemByID(const String& id)
+{
+    TBID tbid(id.CString());
+
+    for (int i = 0; i <  source_->GetNumItems(); i++)
+    {
+        if (source_->GetItemID(i) == tbid)
+        {
+            source_->DeleteItem(i);
+            return;
+        }
+    }
+}
+
 unsigned UIListView::AddChildItem(unsigned parentItemID, const String& text, const String& icon, const String& id)
 {
     if (!itemLookup_.Contains(parentItemID))

+ 3 - 0
Source/Atomic/UI/UIListView.h

@@ -22,8 +22,11 @@ public:
     virtual ~UIListView();
 
     unsigned AddRootItem(const String& text, const String& icon, const String& id);
+
     unsigned AddChildItem(unsigned parentItemID, const String& text, const String& icon, const String& id);
 
+    void DeleteItemByID(const String& id);
+
     void SetExpanded(unsigned itemID, bool value);
 
     void DeleteAllItems();

+ 7 - 0
Source/AtomicJS/Packages/Atomic/UI.json

@@ -11,5 +11,12 @@
 								"UIContainer", "UISection", "UIInlineSelect", "UITextureWidget",
 								"UIScrollContainer", "UISeparator"],
 	"overloads" : {
+	},
+	"typescript_decl" : {
+
+		"UIButton" : [
+			"onClick: () => void;"
+		]
 	}
+
 }