Browse Source

Component deletion

Josh Engebretson 10 years ago
parent
commit
b740a33ecf
1 changed files with 50 additions and 2 deletions
  1. 50 2
      Script/AtomicEditor/ui/frames/inspector/SelectionInspector.ts

+ 50 - 2
Script/AtomicEditor/ui/frames/inspector/SelectionInspector.ts

@@ -23,10 +23,23 @@ class NodeSection extends SelectionSection {
 
 
 class ComponentSection extends SelectionSection {
 class ComponentSection extends SelectionSection {
 
 
-    constructor(editType: SerializableEditType) {
+    constructor(editType: SerializableEditType, inspector: SelectionInspector) {
 
 
         super(editType);
         super(editType);
 
 
+        var deleteButton = new Atomic.UIButton();
+        deleteButton.text = "Delete Component";
+        deleteButton.fontDescription = SelectionSection.fontDesc;
+
+        deleteButton.onClick = () => {
+
+            inspector.onComponentDelete(editType);
+            return true;
+
+        }
+
+        this.attrLayout.addChild(deleteButton);;
+
     }
     }
 
 
 }
 }
@@ -167,7 +180,7 @@ class SelectionInspector extends ScriptWidget {
 
 
         } else {
         } else {
 
 
-            section = new ComponentSection(editType);
+            section = new ComponentSection(editType, this);
 
 
         }
         }
 
 
@@ -298,6 +311,41 @@ class SelectionInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    onComponentDelete(editType: SerializableEditType) {
+
+        var removed: Atomic.Component[] = [];
+
+        for (var i in editType.objects) {
+
+            var c = <Atomic.Component>editType.objects[i];
+            removed.push(c);
+
+        }
+
+        for (var i in removed) {
+
+            var c = removed[i];
+
+            var node = c.node;
+            c.remove();
+            this.removeSerializable(removed[i]);
+
+            var index = editType.nodes.indexOf(node);
+            if (index != -1) {
+                editType.nodes.splice(index, 1);
+            }
+
+        }
+
+        if (removed.length) {
+
+            this.refresh();
+
+        }
+
+    }
+
+
     handleSelectionCreateComponent(ev) {
     handleSelectionCreateComponent(ev) {
 
 
         for (var i in this.nodes) {
         for (var i in this.nodes) {