Browse Source

Merge pull request #421 from AtomicGameEngine/JME-ATOMIC-231

Save expanded state for Node/Component Inspector
LaraEngebretson 10 years ago
parent
commit
d18fae760d

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

@@ -19,7 +19,7 @@ import PrefabInspector = require("./PrefabInspector");
 
 class InspectorFrame extends ScriptWidget {
 
-    inspectingNode: Atomic.Node;
+    nodeInspector: NodeInspector;
 
     constructor() {
 
@@ -41,10 +41,9 @@ class InspectorFrame extends ScriptWidget {
 
     handleProjectUnloaded(data) {
 
-        this.inspectingNode = null;
+        this.closeNodeInspector();
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
-
     }
 
 
@@ -69,14 +68,7 @@ class InspectorFrame extends ScriptWidget {
 
         if (!node) {
 
-            if (this.inspectingNode) {
-
-                this.inspectingNode = null;
-                var container = this.getWidget("inspectorcontainer");
-                container.deleteAllChildren();
-
-            }
-
+            this.closeNodeInspector();
             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) {
 
-        this.inspectingNode = null;
+        this.sendEvent(EditorEvents.ActiveNodeChange, {node:null});
+
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
 
@@ -129,7 +133,7 @@ class InspectorFrame extends ScriptWidget {
 
             var prefabInspector = new PrefabInspector();
             container.addChild(prefabInspector);
-            
+
             prefabInspector.inspect(asset);
         }
 
@@ -137,13 +141,10 @@ class InspectorFrame extends ScriptWidget {
 
     handleNodeRemoved(ev: Atomic.NodeRemovedEvent) {
 
-        if (this.inspectingNode != ev.node)
+        if (this.nodeInspector && this.nodeInspector.node != ev.node)
             return;
 
-        this.inspectingNode = null;
-
-        var container = this.getWidget("inspectorcontainer");
-        container.deleteAllChildren();
+        this.closeNodeInspector();
 
     }
 
@@ -152,6 +153,8 @@ class InspectorFrame extends ScriptWidget {
 
         if (!node) return;
 
+        this.closeNodeInspector();
+
         var container = this.getWidget("inspectorcontainer");
         container.deleteAllChildren();
 
@@ -160,7 +163,7 @@ class InspectorFrame extends ScriptWidget {
 
         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 CreateComponentButton = require("./CreateComponentButton");
 
+interface ComponentState {
+
+    expanded: boolean;
+
+}
+
+interface NodeState {
+
+    expanded: boolean;
+    componentStates: { [id: number]: ComponentState };
+
+}
+
 class NodeInspector extends ScriptWidget {
 
     constructor() {
@@ -94,7 +107,7 @@ class NodeInspector extends ScriptWidget {
     getPrefabComponent(node: Atomic.Node): Atomic.PrefabComponent {
 
         if (node.getComponent("PrefabComponent"))
-            return <Atomic.PrefabComponent> node.getComponent("PrefabComponent");
+            return <Atomic.PrefabComponent>node.getComponent("PrefabComponent");
 
         if (node.parent)
             return this.getPrefabComponent(node.parent);
@@ -115,14 +128,13 @@ class NodeInspector extends ScriptWidget {
 
     }
 
-
     inspect(node: Atomic.Node) {
 
         this.bindings = new Array();
 
         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.isPrefab = this.detectPrefab(node);
@@ -145,6 +157,7 @@ class NodeInspector extends ScriptWidget {
         // node attr layout
 
         var nodeSection = new Atomic.UISection();
+        nodeSection.id = "node_section";
         nodeSection.text = "Node";
         nodeSection.value = 1;
         nodeLayout.addChild(nodeSection);
@@ -160,7 +173,7 @@ class NodeInspector extends ScriptWidget {
 
         for (var i in attrs) {
 
-            var attr = <Atomic.AttributeInfo> attrs[i];
+            var attr = <Atomic.AttributeInfo>attrs[i];
 
             if (attr.mode & Atomic.AM_NOEDIT)
                 continue;
@@ -299,6 +312,7 @@ class NodeInspector extends ScriptWidget {
             //  continue;
 
             var ci = new ComponentInspector();
+            ci.id = "component_section_" + component.id;
 
             ci.inspect(component);
 
@@ -317,15 +331,107 @@ class NodeInspector extends ScriptWidget {
             this.bindings[i].objectLocked = false;
         }
 
+        this.loadState();
+
     }
 
     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;
     updateDelta = 0;
 
+    static nodeStates: { [sceneID: number]: { [nodeId: number]: NodeState } } = {};
+
 }
 
 export = NodeInspector;

+ 7 - 7
Source/Atomic/UI/UISelectList.cpp

@@ -147,9 +147,7 @@ void UISelectList::ScrollToSelectedItem()
 
 void UISelectList::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
 {
-    TBSelectList* select = (TBSelectList*) widget_;
-
-    if (!select)
+    if (!widget_)
         return;
 
     // if we have a drag and drop item, auto scroll if top/bottom
@@ -158,6 +156,7 @@ void UISelectList::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
 
     if (dragDrop->GetDraggingObject())
     {
+        TBSelectList* select = (TBSelectList*) widget_;
         Input* input = GetSubsystem<Input>();
         IntVector2 pos = input->GetMousePosition();
         select->ConvertFromRoot(pos.x_, pos.y_);
@@ -177,14 +176,15 @@ void UISelectList::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
             int speed = 0;
 
             if (value <= 16)
-                speed = 2;
+                speed = -2;
             if (value < 8)
-                speed = 4;
+                speed = -4;
 
-            if (pos.y_ <= 12)
+            if (pos.y_ > 16)
                 speed = -speed;
 
-            select->GetScrollContainer()->ScrollBy(0, speed);
+            if (speed)
+                select->GetScrollContainer()->ScrollBy(0, speed);
 
         }