Browse Source

More work on component delete undo/redo, sort component sections alphabetically

Josh Engebretson 10 years ago
parent
commit
0fd99f90ee

+ 60 - 7
Script/AtomicEditor/ui/frames/inspector/SelectionInspector.ts

@@ -82,9 +82,6 @@ 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();
@@ -111,6 +108,8 @@ class SelectionInspector extends ScriptWidget {
         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(sceneEditor.scene, "SceneEditComponentAddedRemoved", (ev) => this.handleSceneEditComponentAddedRemovedEvent(ev));
+
         this.subscribeToEvent(this.createComponentButton, "SelectionCreateComponent", (data) => this.handleSelectionCreateComponent(data));
         this.subscribeToEvent(this.createComponentButton, "SelectionCreateComponent", (data) => this.handleSelectionCreateComponent(data));
 
 
     }
     }
@@ -222,19 +221,34 @@ class SelectionInspector extends ScriptWidget {
 
 
         this.mainLayout.removeChild(this.createComponentButton, false);
         this.mainLayout.removeChild(this.createComponentButton, false);
 
 
-        this.mainLayout.addChild(section);
+        // sort it in alphabetically
+
+        this.sections.push(section);
+
+        this.sections.sort(function(a, b) {
+            if (a.editType.typeName == "Node")
+                return -1;
+            if (b.editType.typeName == "Node")
+                return 1;
+            return a.editType.typeName.localeCompare(b.editType.typeName);
+        });
+
+        var idx = this.sections.indexOf(section);
+
+        if (idx == this.sections.length - 1)
+            this.mainLayout.addChild(section);
+        else {
+            this.mainLayout.addChildAfter(section, this.sections[idx - 1]);
+        }
 
 
         // move the create component button down
         // move the create component button down
         this.mainLayout.addChild(this.createComponentButton);
         this.mainLayout.addChild(this.createComponentButton);
 
 
-        this.sections.push(section);
-
     }
     }
 
 
     removeSection(section: SelectionSection) {
     removeSection(section: SelectionSection) {
 
 
         SelectionInspector.sectionStates[section.editType.typeName] = section.value ? true : false;
         SelectionInspector.sectionStates[section.editType.typeName] = section.value ? true : false;
-
         var index = this.sections.indexOf(section);
         var index = this.sections.indexOf(section);
         this.sections.splice(index, 1);
         this.sections.splice(index, 1);
         this.mainLayout.removeChild(section);
         this.mainLayout.removeChild(section);
@@ -300,6 +314,7 @@ class SelectionInspector extends ScriptWidget {
 
 
         var typeName = serial.typeName;
         var typeName = serial.typeName;
 
 
+
         if (SelectionInspector._editTypes[typeName]) {
         if (SelectionInspector._editTypes[typeName]) {
             return new SelectionInspector._editTypes[typeName](serial);
             return new SelectionInspector._editTypes[typeName](serial);
         }
         }
@@ -348,6 +363,40 @@ class SelectionInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    handleSceneEditComponentAddedRemovedEvent(ev: Editor.SceneEditComponentAddedRemovedEvent) {
+
+        if (!ev.removed) {
+
+            editType = this.addSerializable(ev.component);
+            editType.addNode(ev.node);
+
+        } else {
+
+            for (var i in this.sections) {
+
+                var section = this.sections[i];
+                var editType = section.editType;
+
+                var index = editType.objects.indexOf(ev.component);
+                if (index != -1) {
+
+                    editType.objects.splice(index, 1);
+                    index = editType.nodes.indexOf(ev.node);
+                    if (index != -1) {
+                        editType.nodes.splice(index, 1);
+                    }
+                    break;
+
+                }
+
+            }
+
+        }
+
+        this.refresh();
+
+    }
+
     onComponentDelete(editType: SerializableEditType) {
     onComponentDelete(editType: SerializableEditType) {
 
 
         var removed: Atomic.Component[] = [];
         var removed: Atomic.Component[] = [];
@@ -365,6 +414,7 @@ class SelectionInspector extends ScriptWidget {
 
 
             var node = c.node;
             var node = c.node;
             c.remove();
             c.remove();
+
             this.removeSerializable(removed[i]);
             this.removeSerializable(removed[i]);
 
 
             var index = editType.nodes.indexOf(node);
             var index = editType.nodes.indexOf(node);
@@ -376,6 +426,7 @@ class SelectionInspector extends ScriptWidget {
 
 
         if (removed.length) {
         if (removed.length) {
 
 
+            this.sceneEditor.scene.sendEvent("SceneEditEnd");
             this.refresh();
             this.refresh();
 
 
         }
         }
@@ -540,6 +591,8 @@ class SelectionInspector extends ScriptWidget {
     nodes: Atomic.Node[] = [];
     nodes: Atomic.Node[] = [];
     sections: SelectionSection[] = [];
     sections: SelectionSection[] = [];
 
 
+    createComponentButton: CreateComponentButton;
+    nodeSection: NodeSection;
 
 
     stateChangesInProgress: boolean = false;
     stateChangesInProgress: boolean = false;
     stateChanges: Atomic.Serializable[] = [];
     stateChanges: Atomic.Serializable[] = [];

+ 8 - 0
Script/TypeScript/AtomicWork.d.ts

@@ -289,6 +289,14 @@ declare module Editor {
 
 
   }
   }
 
 
+  export interface SceneEditComponentAddedRemovedEvent {
+
+      scene: Atomic.Scene;
+      node: Atomic.Node;
+      component: Atomic.Component;
+      removed:boolean;
+  }
+
   export interface SceneEditStateChangeEvent {
   export interface SceneEditStateChangeEvent {
 
 
     serializable:Atomic.Serializable;
     serializable:Atomic.Serializable;

+ 34 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneEditOp.cpp

@@ -120,8 +120,12 @@ bool SelectionEditOp::Commit()
         {
         {
             EditComponent* ecomponent = enode->components_[j];
             EditComponent* ecomponent = enode->components_[j];
 
 
+            if (ecomponent->nodeBegin_ != ecomponent->nodeEnd_)
+                return true;
+
             if (!CompareStates(ecomponent->stateBegin_, ecomponent->stateEnd_))
             if (!CompareStates(ecomponent->stateBegin_, ecomponent->stateEnd_))
                 return true;
                 return true;
+
         }
         }
 
 
     }
     }
@@ -231,8 +235,24 @@ bool SelectionEditOp::Undo()
             if (component->GetNode() != ecomponent->nodeBegin_)
             if (component->GetNode() != ecomponent->nodeBegin_)
             {
             {
                 component->Remove();
                 component->Remove();
+
+                VariantMap caData;
+                caData[SceneEditComponentAddedRemoved::P_SCENE] = scene_;
+                caData[SceneEditComponentAddedRemoved::P_COMPONENT] = component;
+
                 if (ecomponent->nodeBegin_.NotNull())
                 if (ecomponent->nodeBegin_.NotNull())
+                {
                     ecomponent->nodeBegin_->AddComponent(component, 0, REPLICATED);
                     ecomponent->nodeBegin_->AddComponent(component, 0, REPLICATED);
+                    caData[SceneEditComponentAddedRemoved::P_NODE] = ecomponent->nodeBegin_;
+                    caData[SceneEditComponentAddedRemoved::P_REMOVED] = false;
+                }
+                else
+                {
+                    caData[SceneEditComponentAddedRemoved::P_NODE] = ecomponent->nodeEnd_;
+                    caData[SceneEditComponentAddedRemoved::P_REMOVED] = true;
+                }
+
+                scene_->SendEvent(E_SCENEEDITCOMPONENTADDEDREMOVED, caData);
             }
             }
 
 
         }
         }
@@ -323,10 +343,24 @@ bool SelectionEditOp::Redo()
             if (component->GetNode() != ecomponent->nodeEnd_)
             if (component->GetNode() != ecomponent->nodeEnd_)
             {
             {
                 component->Remove();
                 component->Remove();
+
+                VariantMap caData;
+                caData[SceneEditComponentAddedRemoved::P_SCENE] = scene_;
+                caData[SceneEditComponentAddedRemoved::P_COMPONENT] = component;
+
                 if (ecomponent->nodeEnd_.NotNull())
                 if (ecomponent->nodeEnd_.NotNull())
                 {
                 {
                     ecomponent->nodeEnd_->AddComponent(component, 0, REPLICATED);
                     ecomponent->nodeEnd_->AddComponent(component, 0, REPLICATED);
+                    caData[SceneEditComponentAddedRemoved::P_NODE] = ecomponent->nodeEnd_;
+                    caData[SceneEditComponentAddedRemoved::P_REMOVED] = false;
                 }
                 }
+                else
+                {
+                    caData[SceneEditComponentAddedRemoved::P_NODE] = ecomponent->nodeBegin_;
+                    caData[SceneEditComponentAddedRemoved::P_REMOVED] = true;
+                }
+
+                scene_->SendEvent(E_SCENEEDITCOMPONENTADDEDREMOVED, caData);
 
 
             }
             }
 
 

+ 11 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneEditor3DEvents.h

@@ -81,6 +81,17 @@ EVENT(E_SCENEEDITNODEREMOVED, SceneEditNodeRemoved)
 }
 }
 
 
 
 
+/// A child node has been added to a parent node.
+EVENT(E_SCENEEDITCOMPONENTADDEDREMOVED, SceneEditComponentAddedRemoved)
+{
+    PARAM(P_SCENE, Scene);                  // Scene pointer
+    PARAM(P_NODE, Node);                    // Node pointer
+    PARAM(P_COMPONENT, Component);          // Component pointer
+    PARAM(P_REMOVED, Removed);          // bool
+
+}
+
+
 EVENT(E_SCENEEDITADDREMOVENODES, SceneEditAddRemoveNodes)
 EVENT(E_SCENEEDITADDREMOVENODES, SceneEditAddRemoveNodes)
 {
 {
     PARAM(P_END, End);       // bool
     PARAM(P_END, End);       // bool