瀏覽代碼

Differentiate between scene-modified and individual ui-element file-modified in the Editor app.

Wei Tjong Yao 12 年之前
父節點
當前提交
7d2c5db872

+ 33 - 3
Bin/Data/Scripts/Editor/EditorActions.as

@@ -268,6 +268,11 @@ class EditAttributeAction : EditAction
             attributesFullDirty = true;
             attributesFullDirty = true;
             // Apply side effects
             // Apply side effects
             PostEditAttribute(target, attrIndex);
             PostEditAttribute(target, attrIndex);
+
+            if (targetType == ITEM_UI_ELEMENT)
+                SetUIElementModified(target);
+            else
+                SetSceneModified();
         }
         }
     }
     }
 
 
@@ -282,6 +287,11 @@ class EditAttributeAction : EditAction
             attributesFullDirty = true;
             attributesFullDirty = true;
             // Apply side effects
             // Apply side effects
             PostEditAttribute(target, attrIndex);
             PostEditAttribute(target, attrIndex);
+
+            if (targetType == ITEM_UI_ELEMENT)
+                SetUIElementModified(target);
+            else
+                SetSceneModified();
         }
         }
     }
     }
 }
 }
@@ -363,6 +373,11 @@ class ResetAttributesAction : EditAction
             for (uint i = 0; i < target.numAttributes; ++i)
             for (uint i = 0; i < target.numAttributes; ++i)
                 PostEditAttribute(target, i);
                 PostEditAttribute(target, i);
 
 
+            if (targetType == ITEM_UI_ELEMENT)
+                SetUIElementModified(target);
+            else
+                SetSceneModified();
+
             attributesFullDirty = true;
             attributesFullDirty = true;
         }
         }
     }
     }
@@ -390,6 +405,11 @@ class ResetAttributesAction : EditAction
             for (uint i = 0; i < target.numAttributes; ++i)
             for (uint i = 0; i < target.numAttributes; ++i)
                 PostEditAttribute(target, i);
                 PostEditAttribute(target, i);
 
 
+            if (targetType == ITEM_UI_ELEMENT)
+                SetUIElementModified(target);
+            else
+                SetSceneModified();
+
             attributesFullDirty = true;
             attributesFullDirty = true;
         }
         }
     }
     }
@@ -499,6 +519,7 @@ class CreateUIElementAction : EditAction
         {
         {
             parent.RemoveChild(element);
             parent.RemoveChild(element);
             hierarchyList.ClearSelection();
             hierarchyList.ClearSelection();
+            SetUIElementModified(parent);
         }
         }
     }
     }
 
 
@@ -515,6 +536,7 @@ class CreateUIElementAction : EditAction
                 UIElement@ element = parent.children[parent.numChildren - 1];
                 UIElement@ element = parent.children[parent.numChildren - 1];
                 UpdateHierarchyItem(element);
                 UpdateHierarchyItem(element);
                 FocusUIElement(element);
                 FocusUIElement(element);
+                SetUIElementModified(parent);
             }
             }
 
 
             suppressUIElementChanges = false;
             suppressUIElementChanges = false;
@@ -559,6 +581,7 @@ class DeleteUIElementAction : EditAction
                 UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
                 UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
                 UpdateHierarchyItem(listItemIndex, element, parentItem);
                 UpdateHierarchyItem(listItemIndex, element, parentItem);
                 FocusUIElement(element);
                 FocusUIElement(element);
+                SetUIElementModified(parent);
             }
             }
 
 
             suppressUIElementChanges = false;
             suppressUIElementChanges = false;
@@ -573,6 +596,7 @@ class DeleteUIElementAction : EditAction
         {
         {
             parent.RemoveChild(element);
             parent.RemoveChild(element);
             hierarchyList.ClearSelection();
             hierarchyList.ClearSelection();
+            SetUIElementModified(parent);
         }
         }
     }
     }
 }
 }
@@ -597,7 +621,10 @@ class ReparentUIElementAction : EditAction
         UIElement@ parent = GetUIElementByID(oldParentID);
         UIElement@ parent = GetUIElementByID(oldParentID);
         UIElement@ element = GetUIElementByID(elementID);
         UIElement@ element = GetUIElementByID(elementID);
         if (parent !is null && element !is null)
         if (parent !is null && element !is null)
+        {
             element.SetParent(parent, oldChildIndex);
             element.SetParent(parent, oldChildIndex);
+            SetUIElementModified(parent);
+        }
     }
     }
 
 
     void Redo()
     void Redo()
@@ -605,7 +632,10 @@ class ReparentUIElementAction : EditAction
         UIElement@ parent = GetUIElementByID(newParentID);
         UIElement@ parent = GetUIElementByID(newParentID);
         UIElement@ element = GetUIElementByID(elementID);
         UIElement@ element = GetUIElementByID(elementID);
         if (parent !is null && element !is null)
         if (parent !is null && element !is null)
+        {
             element.parent = parent;
             element.parent = parent;
+            SetUIElementModified(parent);
+        }
     }
     }
 }
 }
 
 
@@ -640,7 +670,7 @@ class ApplyUIElementStyleAction : EditAction
         {
         {
             // Apply the style in the XML data
             // Apply the style in the XML data
             elementData.root.SetAttribute("style", style);
             elementData.root.SetAttribute("style", style);
-            
+
             // Have to update manually because the element ID var is not set yet when the E_ELEMENTADDED event is sent
             // Have to update manually because the element ID var is not set yet when the E_ELEMENTADDED event is sent
             suppressUIElementChanges = true;
             suppressUIElementChanges = true;
 
 
@@ -653,14 +683,14 @@ class ApplyUIElementStyleAction : EditAction
                 UIElement@ element = parent.children[index];
                 UIElement@ element = parent.children[index];
                 UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
                 UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
                 UpdateHierarchyItem(listItemIndex, element, parentItem);
                 UpdateHierarchyItem(listItemIndex, element, parentItem);
+                SetUIElementModified(element);
                 hierarchyUpdateSelections.Push(listItemIndex);
                 hierarchyUpdateSelections.Push(listItemIndex);
             }
             }
 
 
             suppressUIElementChanges = false;
             suppressUIElementChanges = false;
-            SetSceneModified();
         }
         }
     }
     }
-    
+
     void Undo()
     void Undo()
     {
     {
         ApplyStyle(elementOldStyle);
         ApplyStyle(elementOldStyle);

+ 1 - 0
Bin/Data/Scripts/Editor/EditorGizmo.as

@@ -461,6 +461,7 @@ void StoreGizmoEditActions()
         }
         }
         
         
         SaveEditActionGroup(group);
         SaveEditActionGroup(group);
+        SetSceneModified();
     }
     }
 
 
     needGizmoUndo = false;
     needGizmoUndo = false;

+ 1 - 0
Bin/Data/Scripts/Editor/EditorImport.as

@@ -49,6 +49,7 @@ void ImportModel(const String&in fileName)
         CreateNodeAction action;
         CreateNodeAction action;
         action.Define(newNode);
         action.Define(newNode);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetSceneModified();
 
 
         FocusNode(newNode);
         FocusNode(newNode);
     }
     }

+ 13 - 2
Bin/Data/Scripts/Editor/EditorNodeWindow.as

@@ -378,7 +378,8 @@ void PostEditAttribute(Array<Serializable@>@ serializables, uint index, const Ar
 
 
     // If a UI-element changing its 'Is Modal' attribute, clear the hierarchy list selection
     // If a UI-element changing its 'Is Modal' attribute, clear the hierarchy list selection
     bool testModalElement = false;
     bool testModalElement = false;
-    if (GetType(serializables[0]) == ITEM_UI_ELEMENT && serializables[0].attributeInfos[index].name == "Is Modal")
+    int itemType = GetType(serializables[0]);
+    if (itemType == ITEM_UI_ELEMENT && serializables[0].attributeInfos[index].name == "Is Modal")
     {
     {
         hierarchyList.ClearSelection();
         hierarchyList.ClearSelection();
         testModalElement = true;
         testModalElement = true;
@@ -392,7 +393,13 @@ void PostEditAttribute(Array<Serializable@>@ serializables, uint index, const Ar
         // After losing the modal flag, the modal element should be reparented to its original parent automatically
         // After losing the modal flag, the modal element should be reparented to its original parent automatically
         if (testModalElement)
         if (testModalElement)
             cast<UIElement>(serializables[i]).vars[NO_AUTO_REMOVE] = true;
             cast<UIElement>(serializables[i]).vars[NO_AUTO_REMOVE] = true;
+
+        if (itemType == ITEM_UI_ELEMENT)
+            SetUIElementModified(serializables[i]);
     }
     }
+
+    if (itemType != ITEM_UI_ELEMENT)
+        SetSceneModified();
 }
 }
 
 
 void PostEditAttribute(Serializable@ serializable, uint index)
 void PostEditAttribute(Serializable@ serializable, uint index)
@@ -504,14 +511,18 @@ void HandleResetToDefault(StringHash eventType, VariantMap& eventData)
 
 
         target.ResetToDefault();
         target.ResetToDefault();
         if (action.targetType == ITEM_UI_ELEMENT)
         if (action.targetType == ITEM_UI_ELEMENT)
+        {
             action.SetInternalVars(target);
             action.SetInternalVars(target);
+            SetUIElementModified(target);
+        }
         target.ApplyAttributes();
         target.ApplyAttributes();
         for (uint j = 0; j < target.numAttributes; ++j)
         for (uint j = 0; j < target.numAttributes; ++j)
             PostEditAttribute(target, j);
             PostEditAttribute(target, j);
     }
     }
 
 
     SaveEditActionGroup(group);
     SaveEditActionGroup(group);
-    SetSceneModified();
+    if (GetType(serializables[0]) != ITEM_UI_ELEMENT)
+        SetSceneModified();
     attributesFullDirty = true;
     attributesFullDirty = true;
 }
 }
 
 

+ 9 - 0
Bin/Data/Scripts/Editor/EditorScene.as

@@ -203,6 +203,7 @@ void CreateNode(CreateMode mode)
     CreateNodeAction action;
     CreateNodeAction action;
     action.Define(newNode);
     action.Define(newNode);
     SaveEditAction(action);
     SaveEditAction(action);
+    SetSceneModified();
 
 
     FocusNode(newNode);
     FocusNode(newNode);
 }
 }
@@ -276,6 +277,7 @@ void LoadNode(const String&in fileName)
         CreateNodeAction action;
         CreateNodeAction action;
         action.Define(newNode);
         action.Define(newNode);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetSceneModified();
 
 
         FocusNode(newNode);
         FocusNode(newNode);
         instantiateFileName = fileName;
         instantiateFileName = fileName;
@@ -476,6 +478,7 @@ bool ScenePaste()
     }
     }
 
 
     SaveEditActionGroup(group);
     SaveEditActionGroup(group);
+    SetSceneModified();
     return true;
     return true;
 }
 }
 
 
@@ -511,6 +514,7 @@ bool SceneUnparent()
         hierarchyList.AddSelection(GetListIndex(changedNodes[i]));
         hierarchyList.AddSelection(GetListIndex(changedNodes[i]));
 
 
     SaveEditActionGroup(group);
     SaveEditActionGroup(group);
+    SetSceneModified();
 
 
     return true;
     return true;
 }
 }
@@ -556,6 +560,7 @@ bool SceneToggleEnable()
     }
     }
 
 
     SaveEditActionGroup(group);
     SaveEditActionGroup(group);
+    SetSceneModified();
 
 
     return true;
     return true;
 }
 }
@@ -571,6 +576,7 @@ bool SceneChangeParent(Node@ sourceNode, Node@ targetNode, bool createUndoAction
     }
     }
 
 
     sourceNode.parent = targetNode;
     sourceNode.parent = targetNode;
+    SetSceneModified();
 
 
     // Return true if success
     // Return true if success
     if (sourceNode.parent is targetNode)
     if (sourceNode.parent is targetNode)
@@ -595,6 +601,7 @@ bool SceneResetPosition()
         EditNodeTransformAction action;
         EditNodeTransformAction action;
         action.Define(editNode, oldTransform);
         action.Define(editNode, oldTransform);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetSceneModified();
 
 
         UpdateNodeAttributes();
         UpdateNodeAttributes();
         return true;
         return true;
@@ -616,6 +623,7 @@ bool SceneResetRotation()
         EditNodeTransformAction action;
         EditNodeTransformAction action;
         action.Define(editNode, oldTransform);
         action.Define(editNode, oldTransform);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetSceneModified();
 
 
         UpdateNodeAttributes();
         UpdateNodeAttributes();
         return true;
         return true;
@@ -637,6 +645,7 @@ bool SceneResetScale()
         EditNodeTransformAction action;
         EditNodeTransformAction action;
         action.Define(editNode, oldTransform);
         action.Define(editNode, oldTransform);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetSceneModified();
 
 
         UpdateNodeAttributes();
         UpdateNodeAttributes();
         return true;
         return true;

+ 4 - 3
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -420,7 +420,9 @@ uint GetComponentListIndex(Component@ component)
 
 
 String GetUIElementTitle(UIElement@ element)
 String GetUIElementTitle(UIElement@ element)
 {
 {
-    return (element.name.empty ? element.typeName : element.name) + " [" + GetUIElementID(element).ToString() + "]";
+    // Only top level UI-element has this variable
+    String modifiedStr = element.GetVar(MODIFIED_VAR).GetBool() ? "*" : "";
+    return (element.name.empty ? element.typeName : element.name) + modifiedStr + " [" + GetUIElementID(element).ToString() + "]";
 }
 }
 
 
 String GetNodeTitle(Node@ node)
 String GetNodeTitle(Node@ node)
@@ -823,6 +825,7 @@ void CreateBuiltinObject(const String& name)
     CreateNodeAction action;
     CreateNodeAction action;
     action.Define(newNode);
     action.Define(newNode);
     SaveEditAction(action);
     SaveEditAction(action);
+    SetSceneModified();
 
 
     FocusNode(newNode);
     FocusNode(newNode);
 }
 }
@@ -1115,8 +1118,6 @@ void SaveEditActionGroup(EditActionGroup@ group)
         undoStack.Erase(0);
         undoStack.Erase(0);
         --undoStackPos;
         --undoStackPos;
     }
     }
-
-    SetSceneModified();
 }
 }
 
 
 void BeginSelectionModify()
 void BeginSelectionModify()

+ 19 - 8
Bin/Data/Scripts/Editor/EditorUIElement.as

@@ -73,6 +73,7 @@ bool NewUIElement(const String&in typeName)
         CreateUIElementAction action;
         CreateUIElementAction action;
         action.Define(element);
         action.Define(element);
         SaveEditAction(action);
         SaveEditAction(action);
+        SetUIElementModified(element);
 
 
         FocusUIElement(element);
         FocusUIElement(element);
     }
     }
@@ -212,10 +213,7 @@ bool SaveUIElement(const String&in fileName)
         if (success)
         if (success)
         {
         {
             element.vars[FILENAME_VAR] = fileName;
             element.vars[FILENAME_VAR] = fileName;
-            element.vars[MODIFIED_VAR] = false;
-
-            sceneModified = false;
-            UpdateWindowTitle();
+            SetUIElementModified(element, false);
         }
         }
     }
     }
 
 
@@ -265,6 +263,7 @@ void LoadChildUIElement(const String&in fileName)
         ResetSortChildren(element);
         ResetSortChildren(element);
         RegisterUIElementVar(xmlFile.root);
         RegisterUIElementVar(xmlFile.root);
         UpdateHierarchyItem(element);
         UpdateHierarchyItem(element);
+        SetUIElementModified(element);
 
 
         // Create an undo action for the load
         // Create an undo action for the load
         CreateUIElementAction action;
         CreateUIElementAction action;
@@ -380,6 +379,16 @@ UIElement@ GetTopLevelUIElement(UIElement@ element)
     return element;
     return element;
 }
 }
 
 
+void SetUIElementModified(UIElement@ element, bool flag = true)
+{
+    element = GetTopLevelUIElement(element);
+    if (element.GetVar(MODIFIED_VAR).GetBool() != flag)
+    {
+        element.vars[MODIFIED_VAR] = flag;
+        UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
+    }
+}
+
 XPathQuery availableStylesXPathQuery("/elements/element[@auto='false']/@type");
 XPathQuery availableStylesXPathQuery("/elements/element[@auto='false']/@type");
 
 
 void GetAvailableStyles()
 void GetAvailableStyles()
@@ -463,6 +472,7 @@ bool UIElementPaste()
             UIElement@ element = editUIElement.children[editUIElement.numChildren - 1];
             UIElement@ element = editUIElement.children[editUIElement.numChildren - 1];
             ResetDuplicateID(element);
             ResetDuplicateID(element);
             UpdateHierarchyItem(element);
             UpdateHierarchyItem(element);
+            SetUIElementModified(editUIElement);
 
 
             // Create an undo action
             // Create an undo action
             CreateUIElementAction action;
             CreateUIElementAction action;
@@ -484,7 +494,7 @@ bool UIElementDelete()
 
 
     BeginSelectionModify();
     BeginSelectionModify();
 
 
-    // Clear the selection now to prevent repopulation of selectedNodes and selectedComponents combo
+    // Clear the selection now to prevent deleted elements from being reselected
     hierarchyList.ClearSelection();
     hierarchyList.ClearSelection();
 
 
     // Group for storing undo actions
     // Group for storing undo actions
@@ -503,10 +513,10 @@ bool UIElementDelete()
         action.Define(element);
         action.Define(element);
         group.actions.Push(action);
         group.actions.Push(action);
 
 
+        SetUIElementModified(element);
         element.Remove();
         element.Remove();
-        SetSceneModified();
 
 
-        // If deleting only one node, select the next item in the same index
+        // If deleting only one element, select the next item in the same index
         if (selectedUIElements.length == 1)
         if (selectedUIElements.length == 1)
             hierarchyList.selection = index;
             hierarchyList.selection = index;
     }
     }
@@ -557,10 +567,10 @@ bool UIElementResetToDefault()
         element.ApplyAttributes();
         element.ApplyAttributes();
         for (uint j = 0; j < element.numAttributes; ++j)
         for (uint j = 0; j < element.numAttributes; ++j)
             PostEditAttribute(element, j);
             PostEditAttribute(element, j);
+        SetUIElementModified(element);
     }
     }
 
 
     SaveEditActionGroup(group);
     SaveEditActionGroup(group);
-    SetSceneModified();
     attributesFullDirty = true;
     attributesFullDirty = true;
 
 
     return true;
     return true;
@@ -573,5 +583,6 @@ bool UIElementChangeParent(UIElement@ sourceElement, UIElement@ targetElement)
     SaveEditAction(action);
     SaveEditAction(action);
 
 
     sourceElement.parent = targetElement;
     sourceElement.parent = targetElement;
+    SetUIElementModified(targetElement);
     return sourceElement.parent is targetElement;
     return sourceElement.parent is targetElement;
 }
 }