Browse Source

Save node and component expanded states

Josh Engebretson 10 years ago
parent
commit
17329b5da4

+ 22 - 19
Script/AtomicEditor/ui/frames/inspector/InspectorFrame.ts

@@ -19,7 +19,7 @@ import PrefabInspector = require("./PrefabInspector");
 
 
 class InspectorFrame extends ScriptWidget {
 class InspectorFrame extends ScriptWidget {
 
 
-    inspectingNode: Atomic.Node;
+    nodeInspector: NodeInspector;
 
 
     constructor() {
     constructor() {
 
 
@@ -41,10 +41,9 @@ class InspectorFrame extends ScriptWidget {
 
 
     handleProjectUnloaded(data) {
     handleProjectUnloaded(data) {
 
 
-        this.inspectingNode = null;
+        this.closeNodeInspector();
         var container = this.getWidget("inspectorcontainer");
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
         container.deleteAllChildren();
-
     }
     }
 
 
 
 
@@ -69,14 +68,7 @@ class InspectorFrame extends ScriptWidget {
 
 
         if (!node) {
         if (!node) {
 
 
-            if (this.inspectingNode) {
-
-                this.inspectingNode = null;
-                var container = this.getWidget("inspectorcontainer");
-                container.deleteAllChildren();
-
-            }
-
+            this.closeNodeInspector();
             return;
             return;
         }
         }
 
 
@@ -84,10 +76,22 @@ class InspectorFrame extends ScriptWidget {
 
 
     }
     }
 
 
+    closeNodeInspector() {
+
+      if (this.nodeInspector) {
+          this.nodeInspector.saveState();
+          var container = this.getWidget("inspectorcontainer");
+          container.deleteAllChildren();
+          this.nodeInspector = null;
+      }
+
+    }
+
 
 
     inspectAsset(asset: ToolCore.Asset) {
     inspectAsset(asset: ToolCore.Asset) {
 
 
-        this.inspectingNode = null;
+        this.sendEvent(EditorEvents.ActiveNodeChange, {node:null});
+
         var container = this.getWidget("inspectorcontainer");
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
         container.deleteAllChildren();
 
 
@@ -129,7 +133,7 @@ class InspectorFrame extends ScriptWidget {
 
 
             var prefabInspector = new PrefabInspector();
             var prefabInspector = new PrefabInspector();
             container.addChild(prefabInspector);
             container.addChild(prefabInspector);
-            
+
             prefabInspector.inspect(asset);
             prefabInspector.inspect(asset);
         }
         }
 
 
@@ -137,13 +141,10 @@ class InspectorFrame extends ScriptWidget {
 
 
     handleNodeRemoved(ev: Atomic.NodeRemovedEvent) {
     handleNodeRemoved(ev: Atomic.NodeRemovedEvent) {
 
 
-        if (this.inspectingNode != ev.node)
+        if (this.nodeInspector && this.nodeInspector.node != ev.node)
             return;
             return;
 
 
-        this.inspectingNode = null;
-
-        var container = this.getWidget("inspectorcontainer");
-        container.deleteAllChildren();
+        this.closeNodeInspector();
 
 
     }
     }
 
 
@@ -152,6 +153,8 @@ class InspectorFrame extends ScriptWidget {
 
 
         if (!node) return;
         if (!node) return;
 
 
+        this.closeNodeInspector();
+
         var container = this.getWidget("inspectorcontainer");
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
         container.deleteAllChildren();
 
 
@@ -160,7 +163,7 @@ class InspectorFrame extends ScriptWidget {
 
 
         inspector.inspect(node);
         inspector.inspect(node);
 
 
-        this.inspectingNode = node;
+        this.nodeInspector = inspector;
 
 
     }
     }
 
 

+ 117 - 9
Script/AtomicEditor/ui/frames/inspector/NodeInspector.ts

@@ -10,6 +10,19 @@ import ComponentInspector = require("./ComponentInspector");
 import DataBinding = require("./DataBinding");
 import DataBinding = require("./DataBinding");
 import CreateComponentButton = require("./CreateComponentButton");
 import CreateComponentButton = require("./CreateComponentButton");
 
 
+interface ComponentState {
+
+    expanded: boolean;
+
+}
+
+interface NodeState {
+
+    expanded: boolean;
+    componentStates: { [id: number]: ComponentState };
+
+}
+
 class NodeInspector extends ScriptWidget {
 class NodeInspector extends ScriptWidget {
 
 
     constructor() {
     constructor() {
@@ -94,7 +107,7 @@ class NodeInspector extends ScriptWidget {
     getPrefabComponent(node: Atomic.Node): Atomic.PrefabComponent {
     getPrefabComponent(node: Atomic.Node): Atomic.PrefabComponent {
 
 
         if (node.getComponent("PrefabComponent"))
         if (node.getComponent("PrefabComponent"))
-            return <Atomic.PrefabComponent> node.getComponent("PrefabComponent");
+            return <Atomic.PrefabComponent>node.getComponent("PrefabComponent");
 
 
         if (node.parent)
         if (node.parent)
             return this.getPrefabComponent(node.parent);
             return this.getPrefabComponent(node.parent);
@@ -115,14 +128,13 @@ class NodeInspector extends ScriptWidget {
 
 
     }
     }
 
 
-
     inspect(node: Atomic.Node) {
     inspect(node: Atomic.Node) {
 
 
         this.bindings = new Array();
         this.bindings = new Array();
 
 
         this.node = node;
         this.node = node;
 
 
-        node.scene.sendEvent("SceneEditSerializable", { serializable: node, operation: 0});
+        node.scene.sendEvent("SceneEditSerializable", { serializable: node, operation: 0 });
         this.subscribeToEvent(node, "SceneEditSerializableUndoRedo", (data) => this.handleSceneEditSerializableUndoRedoEvent(data));
         this.subscribeToEvent(node, "SceneEditSerializableUndoRedo", (data) => this.handleSceneEditSerializableUndoRedoEvent(data));
 
 
         this.isPrefab = this.detectPrefab(node);
         this.isPrefab = this.detectPrefab(node);
@@ -145,6 +157,7 @@ class NodeInspector extends ScriptWidget {
         // node attr layout
         // node attr layout
 
 
         var nodeSection = new Atomic.UISection();
         var nodeSection = new Atomic.UISection();
+        nodeSection.id = "node_section";
         nodeSection.text = "Node";
         nodeSection.text = "Node";
         nodeSection.value = 1;
         nodeSection.value = 1;
         nodeLayout.addChild(nodeSection);
         nodeLayout.addChild(nodeSection);
@@ -160,7 +173,7 @@ class NodeInspector extends ScriptWidget {
 
 
         for (var i in attrs) {
         for (var i in attrs) {
 
 
-            var attr = <Atomic.AttributeInfo> attrs[i];
+            var attr = <Atomic.AttributeInfo>attrs[i];
 
 
             if (attr.mode & Atomic.AM_NOEDIT)
             if (attr.mode & Atomic.AM_NOEDIT)
                 continue;
                 continue;
@@ -299,6 +312,7 @@ class NodeInspector extends ScriptWidget {
             //  continue;
             //  continue;
 
 
             var ci = new ComponentInspector();
             var ci = new ComponentInspector();
+            ci.id = "component_section_" + component.id;
 
 
             ci.inspect(component);
             ci.inspect(component);
 
 
@@ -317,15 +331,107 @@ class NodeInspector extends ScriptWidget {
             this.bindings[i].objectLocked = false;
             this.bindings[i].objectLocked = false;
         }
         }
 
 
+        this.loadState();
+
     }
     }
 
 
     handleSceneEditSerializableUndoRedoEvent(ev) {
     handleSceneEditSerializableUndoRedoEvent(ev) {
 
 
-      for (var i in this.bindings) {
-          this.bindings[i].objectLocked = true;
-          this.bindings[i].setWidgetValueFromObject();
-          this.bindings[i].objectLocked = false;
-      }
+        for (var i in this.bindings) {
+            this.bindings[i].objectLocked = true;
+            this.bindings[i].setWidgetValueFromObject();
+            this.bindings[i].objectLocked = false;
+        }
+
+    }
+
+    saveState() {
+
+        var node = this.node;
+
+        if (!node.scene)
+            return;
+
+        var nodeStates = NodeInspector.nodeStates[node.scene.id];
+
+        if (!nodeStates)
+            return;
+
+        var state = nodeStates[node.id];
+
+        if (!state) {
+
+            state = nodeStates[node.id] = { expanded: true, componentStates: {} };
+
+        }
+
+        var section: Atomic.UISection = <Atomic.UISection>this.nodeLayout.getWidget("node_section");
+
+        state.expanded = section.value ? true : false;
+
+        var components = node.getComponents();
+
+        for (var i in components) {
+
+            var component = components[i];
+            var cstate = state.componentStates[component.id];
+
+            if (!cstate) {
+                cstate = state.componentStates[component.id] = { expanded: false };
+            }
+
+            section = <Atomic.UISection>this.nodeLayout.getWidget("component_section_" + component.id);
+
+            if (section)
+                cstate.expanded = section.value ? true : false;
+
+        }
+
+    }
+
+    loadState() {
+
+        var node = this.node;
+
+        // lookup in node states via scene id
+        var nodeStates = NodeInspector.nodeStates[node.scene.id];
+
+        if (!nodeStates) {
+            nodeStates = NodeInspector.nodeStates[node.scene.id] = {};
+        }
+
+        // lookup by node id
+        var state = nodeStates[node.id];
+
+        if (!state) {
+
+            // we don't have a state, so save default state
+            this.saveState();
+
+        } else {
+
+            var section: Atomic.UISection = <Atomic.UISection>this.nodeLayout.getWidget("node_section");
+
+            section.value = state.expanded ? 1 : 0;
+
+            var components = node.getComponents();
+
+            for (var i in components) {
+
+                var component = components[i];
+
+                var cstate = state.componentStates[component.id];
+                section = <Atomic.UISection>this.nodeLayout.getWidget("component_section_" + component.id);
+
+                if (cstate && section) {
+
+                    section.value = cstate.expanded ? 1 : 0;
+
+                }
+
+            }
+
+        }
 
 
     }
     }
 
 
@@ -337,6 +443,8 @@ class NodeInspector extends ScriptWidget {
     gizmoMoved = false;
     gizmoMoved = false;
     updateDelta = 0;
     updateDelta = 0;
 
 
+    static nodeStates: { [sceneID: number]: { [nodeId: number]: NodeState } } = {};
+
 }
 }
 
 
 export = NodeInspector;
 export = NodeInspector;