Sfoglia il codice sorgente

Notice when the scene has been modified.

Lasse Öörni 15 anni fa
parent
commit
24a76f7d99

+ 6 - 1
Bin/CoreData/Scripts/EditorComponentWindow.as

@@ -176,7 +176,7 @@ void updateComponentAttributes()
 
 void editComponentAttribute(StringHash eventType, VariantMap& eventData)
 {
-    if (selectedComponent is null)
+    if ((selectedComponent is null) || (selectedEntity is null))
         return;
         
     // Changing elements programmatically may cause events to be sent. Stop possible infinite loop in that case.
@@ -192,8 +192,13 @@ void editComponentAttribute(StringHash eventType, VariantMap& eventData)
         if (index == uint(attrEdit.userData["Index"].getInt()))
         {
             writeAttributeEditor(attrEdit.userData["Type"].getInt(), categoryElem, index, attrEdit.userData["Attribute"].getString());
+
+            uint id = selectedEntity.getID();
+            beginModify(id);
             selectedComponent.loadXML(rootElem);
             selectedComponent.postLoad();
+            endModify(id);
+
             updateComponentAttributes();
             return;
         }

+ 19 - 3
Bin/CoreData/Scripts/EditorScene.as

@@ -6,7 +6,7 @@
 Scene@ editorScene;
 string sceneFileName;
 string sceneResourcePath;
-bool sceneUnsaved = false;
+bool sceneModified = false;
 
 Component@ selectedComponent;
 Entity@ selectedEntity;
@@ -62,7 +62,7 @@ void loadScene(string fileName)
         editorScene.loadXML(file);
         
     sceneFileName = fileName;
-    sceneUnsaved = false;
+    sceneModified = false;
     updateWindowTitle();
     updateSceneWindow(false);
     resetCamera();
@@ -81,10 +81,26 @@ void saveScene(string fileName)
         editorScene.saveXML(file);
 
     sceneFileName = fileName;
-    sceneUnsaved = false;
+    sceneModified = false;
     updateWindowTitle();
 }
 
+void beginModify(uint entityID)
+{
+    // Undo/Redo can be implemented here
+}
+
+void endModify(uint entityID)
+{
+    // Undo/Redo can be implemented here
+
+    if (!sceneModified)
+    {
+        sceneModified = true;
+        updateWindowTitle();
+    }
+}
+
 string getEntityTitle(Entity@ entity)
 {
     string name = entity.getName();

+ 8 - 0
Bin/CoreData/Scripts/EditorSceneWindow.as

@@ -325,7 +325,11 @@ void handleEntityListKey(StringHash eventType, VariantMap& eventData)
             if (selectedComponent is component)
                 @selectedComponent = null;
 
+            uint id = entity.getID();
+            beginModify(id);
             entity.removeComponent(component);
+            endModify(id);
+
             // If component is a node, also remove it from the parent node
             Node@ node = cast<Node>(component);
             if ((node !is null) && (node.getParent() !is null))
@@ -340,7 +344,11 @@ void handleEntityListKey(StringHash eventType, VariantMap& eventData)
             if (selectedEntity is entity)
                 @selectedEntity = null;
 
+            uint id = entity.getID();
+            beginModify(id);
             editorScene.removeEntity(entity);
+            endModify(id);
+            
             updateSceneWindowEntity(entityItem, null);
             list.setSelection(index);
         }

+ 1 - 1
Bin/CoreData/Scripts/EditorUI.as

@@ -148,7 +148,7 @@ void centerDialog(UIElement@ element)
 void updateWindowTitle()
 {
     string sceneName = sceneFileName.empty() ? "Untitled" : getFileNameAndExtension(sceneFileName);
-    if (sceneUnsaved)
+    if (sceneModified)
         sceneName += "*";
     renderer.setWindowTitle("Urho3D editor - " + sceneName);
 }