Browse Source

Prefab node edit widget

Josh Engebretson 10 years ago
parent
commit
0a3b0cb00a

+ 2 - 14
Script/AtomicEditor/ui/frames/inspector/CreateComponentButton.ts

@@ -99,12 +99,10 @@ for (var sub in sources) {
 
 
 class CreateComponentButton extends Atomic.UIButton {
 class CreateComponentButton extends Atomic.UIButton {
 
 
-    constructor(node: Atomic.Node) {
+    constructor() {
 
 
         super();
         super();
 
 
-        this.node = node;
-
         this.fd.id = "Vera";
         this.fd.id = "Vera";
         this.fd.size = 11;
         this.fd.size = 11;
 
 
@@ -129,16 +127,7 @@ class CreateComponentButton extends Atomic.UIButton {
 
 
         if (ev.target && ev.target.id == "create component popup") {
         if (ev.target && ev.target.id == "create component popup") {
 
 
-            var c = this.node.createComponent(ev.refid);
-
-            if (c) {
-
-              var ci = new ComponentInspector();
-              ci.inspect(c);
-
-              this.parent.addChildRelative(ci, Atomic.UI_WIDGET_Z_REL_BEFORE, this);
-
-            }
+            this.sendEvent("SelectionCreateComponent", { componentTypeName : ev.refid});
 
 
             return true;
             return true;
 
 
@@ -146,7 +135,6 @@ class CreateComponentButton extends Atomic.UIButton {
 
 
     }
     }
 
 
-    node: Atomic.Node;
     fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
     fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
 
 
 }
 }

+ 113 - 3
Script/AtomicEditor/ui/frames/inspector/SelectionInspector.ts

@@ -1,15 +1,22 @@
 
 
+import CreateComponentButton = require("./CreateComponentButton");
 import ScriptWidget = require("ui/ScriptWidget");
 import ScriptWidget = require("ui/ScriptWidget");
 import EditorEvents = require("editor/EditorEvents");
 import EditorEvents = require("editor/EditorEvents");
 import SerializableEditType = require("./SerializableEditType");
 import SerializableEditType = require("./SerializableEditType");
 import SelectionSection = require("./SelectionSection");
 import SelectionSection = require("./SelectionSection");
+import SelectionPrefabWidget = require("./SelectionPrefabWidget");
 
 
 class NodeSection extends SelectionSection {
 class NodeSection extends SelectionSection {
 
 
+    prefabWidget: SelectionPrefabWidget;
+
     constructor(editType: SerializableEditType) {
     constructor(editType: SerializableEditType) {
 
 
         super(editType);
         super(editType);
 
 
+        this.prefabWidget = new SelectionPrefabWidget();
+        this.attrLayout.addChild(this.prefabWidget);
+
     }
     }
 
 
 }
 }
@@ -28,6 +35,9 @@ class ComponentSection extends SelectionSection {
 
 
 class SelectionInspector extends ScriptWidget {
 class SelectionInspector extends ScriptWidget {
 
 
+    createComponentButton: CreateComponentButton;
+    nodeSection: NodeSection;
+
     constructor(sceneEditor: Editor.SceneEditor3D) {
     constructor(sceneEditor: Editor.SceneEditor3D) {
 
 
         super();
         super();
@@ -47,10 +57,15 @@ class SelectionInspector extends ScriptWidget {
 
 
         this.addChild(mainLayout);
         this.addChild(mainLayout);
 
 
+        this.createComponentButton = new CreateComponentButton();
+        mainLayout.addChild(this.createComponentButton);
+
         this.subscribeToEvent(sceneEditor.scene, "SceneEditStateChangesBegin", (data) => this.handleSceneEditStateChangesBeginEvent());
         this.subscribeToEvent(sceneEditor.scene, "SceneEditStateChangesBegin", (data) => this.handleSceneEditStateChangesBeginEvent());
         this.subscribeToEvent("SceneEditStateChange", (data) => this.handleSceneEditStateChangeEvent(data));
         this.subscribeToEvent("SceneEditStateChange", (data) => this.handleSceneEditStateChangeEvent(data));
         this.subscribeToEvent(sceneEditor.scene, "SceneEditStateChangesEnd", (data) => this.handleSceneEditStateChangesEndEvent());
         this.subscribeToEvent(sceneEditor.scene, "SceneEditStateChangesEnd", (data) => this.handleSceneEditStateChangesEndEvent());
 
 
+        this.subscribeToEvent(this.createComponentButton, "SelectionCreateComponent", (data) => this.handleSelectionCreateComponent(data));
+
     }
     }
 
 
     pruneSections() {
     pruneSections() {
@@ -128,6 +143,10 @@ class SelectionInspector extends ScriptWidget {
 
 
         }
         }
 
 
+        if (this.nodeSection) {
+            this.nodeSection.prefabWidget.updateSelection(this.nodes);
+        }
+
         Atomic.ui.blockChangedEvents = false;
         Atomic.ui.blockChangedEvents = false;
 
 
     }
     }
@@ -138,7 +157,13 @@ class SelectionInspector extends ScriptWidget {
 
 
         if (editType.typeName == "Node") {
         if (editType.typeName == "Node") {
 
 
-            section = new NodeSection(editType);
+            this.nodeSection = new NodeSection(editType);
+            section = this.nodeSection;
+
+            this.subscribeToEvent(this.nodeSection.prefabWidget, "SelectionPrefabSave", (data) => this.handleSelectionPrefabSave());
+            this.subscribeToEvent(this.nodeSection.prefabWidget, "SelectionPrefabUndo", (data) => this.handleSelectionPrefabUndo());
+            this.subscribeToEvent(this.nodeSection.prefabWidget, "SelectionPrefabBreak", (data) => this.handleSelectionPrefabBreak());
+
 
 
         } else {
         } else {
 
 
@@ -146,7 +171,14 @@ class SelectionInspector extends ScriptWidget {
 
 
         }
         }
 
 
+
+        this.mainLayout.removeChild(this.createComponentButton, false);
+
         this.mainLayout.addChild(section);
         this.mainLayout.addChild(section);
+
+        // move the create component button down
+        this.mainLayout.addChild(this.createComponentButton);
+
         this.sections.push(section);
         this.sections.push(section);
 
 
     }
     }
@@ -266,11 +298,33 @@ class SelectionInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    handleSelectionCreateComponent(ev) {
+
+        for (var i in this.nodes) {
+
+            var node = this.nodes[i];
+
+            var c = node.createComponent(ev.componentTypeName);
+
+            if (!c) {
+                console.log("ERROR: unable to create component ", ev.componentTypeName);
+                return;
+            }
+
+            var editType = this.addSerializable(c);
+            editType.addNode(node);
+
+        }
+
+        this.refresh();
+
+    }
+
 
 
     handleSceneEditStateChangeEvent(ev: Editor.SceneEditStateChangeEvent) {
     handleSceneEditStateChangeEvent(ev: Editor.SceneEditStateChangeEvent) {
 
 
         if (!this.stateChangesInProgress)
         if (!this.stateChangesInProgress)
-          return;
+            return;
 
 
         if (this.stateChanges.indexOf(ev.serializable) == -1) {
         if (this.stateChanges.indexOf(ev.serializable) == -1) {
             this.stateChanges.push(ev.serializable);
             this.stateChanges.push(ev.serializable);
@@ -278,6 +332,62 @@ class SelectionInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    getPrefabComponent(node: Atomic.Node): Atomic.PrefabComponent {
+
+        if (node.getComponent("PrefabComponent"))
+            return <Atomic.PrefabComponent>node.getComponent("PrefabComponent");
+
+        if (node.parent)
+            return this.getPrefabComponent(node.parent);
+
+        return null;
+
+    }
+
+    handleSelectionPrefabSave() {
+
+        if (this.nodes.length != 1)
+            return;
+
+        var c = this.getPrefabComponent(this.nodes[0]);
+        if (!c)
+            return;
+
+        c.savePrefab();
+
+    }
+
+    handleSelectionPrefabBreak() {
+
+        if (this.nodes.length != 1)
+            return;
+
+        var c = this.getPrefabComponent(this.nodes[0]);
+        if (!c)
+            return;
+
+        c.breakPrefab();
+        this.refresh();
+
+    }
+
+    handleSelectionPrefabUndo() {
+
+        if (this.nodes.length != 1)
+            return;
+
+        var c = this.getPrefabComponent(this.nodes[0]);
+        if (!c)
+            return;
+
+        c.undoPrefab();
+
+        var node = this.nodes[0];
+        this.removeNode(node);
+        this.addNode(node);
+
+    }
+
     handleSceneEditStateChangesEndEvent() {
     handleSceneEditStateChangesEndEvent() {
 
 
         Atomic.ui.blockChangedEvents = true;
         Atomic.ui.blockChangedEvents = true;
@@ -319,7 +429,7 @@ class SelectionInspector extends ScriptWidget {
     sections: SelectionSection[] = [];
     sections: SelectionSection[] = [];
 
 
 
 
-    stateChangesInProgress:boolean =  false;
+    stateChangesInProgress: boolean = false;
     stateChanges: Atomic.Serializable[] = [];
     stateChanges: Atomic.Serializable[] = [];
 
 
     // ------------------------------------
     // ------------------------------------

+ 135 - 0
Script/AtomicEditor/ui/frames/inspector/SelectionPrefabWidget.ts

@@ -0,0 +1,135 @@
+
+
+class SelectionPrefabWidget extends Atomic.UILayout {
+
+    widgetLayout: Atomic.UILayout;
+    noticeLayout: Atomic.UILayout;
+
+    constructor() {
+
+        super();
+
+        var fd = new Atomic.UIFontDescription();
+        fd.id = "Vera";
+        fd.size = 11;
+
+        var widgetLayout = this.widgetLayout = new Atomic.UILayout();
+        var noticeLayout = this.noticeLayout = new Atomic.UILayout();
+
+        this.axis = Atomic.UI_AXIS_Y;
+        widgetLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
+        noticeLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
+
+        var name = new Atomic.UITextField();
+        name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        name.skinBg = "InspectorTextAttrName";
+        name.text = "Prefab"
+        name.fontDescription = fd;
+
+        var saveButton = new Atomic.UIButton();
+        saveButton.text = "Save";
+        saveButton.fontDescription = fd;
+
+        saveButton.onClick = () => {
+
+            this.sendEvent("SelectionPrefabSave");
+            return true;
+        }
+
+        var undoButton = new Atomic.UIButton();
+        undoButton.text = "Undo";
+        undoButton.fontDescription = fd;
+
+        undoButton.onClick = () => {
+
+            this.sendEvent("SelectionPrefabUndo");
+            return true;
+
+        }
+
+        var breakButton = new Atomic.UIButton();
+        breakButton.text = "Break";
+        breakButton.fontDescription = fd;
+
+        breakButton.onClick = () => {
+
+            this.sendEvent("SelectionPrefabBreak");
+            return true;
+        }
+
+        var noticeName = new Atomic.UITextField();
+        noticeName.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        noticeName.skinBg = "InspectorTextAttrName";
+        noticeName.text = "Prefab"
+        noticeName.fontDescription = fd;
+
+        var noticeText = new Atomic.UITextField();
+        noticeText.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        noticeText.skinBg = "InspectorTextAttrName";
+        noticeText.text = "Multiple Selection"
+        noticeText.fontDescription = fd;
+
+        noticeLayout.addChild(noticeName);
+        noticeLayout.addChild(noticeText);
+
+        widgetLayout.addChild(name);
+        widgetLayout.addChild(saveButton);
+        widgetLayout.addChild(undoButton);
+        widgetLayout.addChild(breakButton);
+
+        this.addChild(this.widgetLayout);
+        this.addChild(this.noticeLayout);
+
+        this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
+
+    }
+
+    detectPrefab(node: Atomic.Node): boolean {
+
+        if (node.getComponent("PrefabComponent"))
+            return true;
+
+        if (node.parent)
+            return this.detectPrefab(node.parent);
+
+        return false;
+
+    }
+
+
+    updateSelection(nodes: Atomic.Node[]) {
+
+        var hasPrefab = false;
+
+        for (var i in nodes) {
+
+            var node = nodes[i];
+            if (this.detectPrefab(node)) {
+                hasPrefab = true;
+                break;
+            }
+
+        }
+
+        if (!hasPrefab) {
+            this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
+            return;
+        }
+
+        this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
+
+        if (nodes.length > 1) {
+            this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
+            this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
+            return;
+        }
+
+        this.noticeLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
+        this.widgetLayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
+
+    }
+
+
+}
+
+export = SelectionPrefabWidget;