diff --git a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs index 3554bdd436..d980c8d252 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs @@ -29,6 +29,8 @@ namespace OpenRA.Mods.Common.Traits int nextId; + public bool Modified; + public void WorldLoaded(World w, WorldRenderer wr) { Add(new OpenMapAction()); @@ -36,6 +38,7 @@ namespace OpenRA.Mods.Common.Traits public void Add(IEditorAction editorAction) { + Modified = true; editorAction.Execute(); if (undoStack.Count > 0) @@ -55,6 +58,8 @@ namespace OpenRA.Mods.Common.Traits if (!HasUndos()) return; + Modified = true; + var editorAction = undoStack.Pop(); undoStack.Peek().Status = EditorActionStatus.Active; editorAction.Action.Undo(); @@ -81,6 +86,8 @@ namespace OpenRA.Mods.Common.Traits if (!HasRedos()) return; + Modified = true; + var editorAction = redoStack.Pop(); editorAction.Status = EditorActionStatus.Active; @@ -114,6 +121,12 @@ namespace OpenRA.Mods.Common.Traits while (undoStack.Peek().Id != id) Redo(); } + + public bool HasUnsavedItems() + { + // Modified and last action isn't the OpenMapAction (+ no redos) + return Modified && !(undoStack.Peek().Action is OpenMapAction && !HasRedos()); + } } public enum EditorActionStatus diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 87f6980d82..c38036e926 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -339,9 +339,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic { hideMenu = true; var editorActorLayer = world.WorldActor.Trait(); + var actionManager = world.WorldActor.Trait(); Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs() { - { "onSave", (Action)(_ => hideMenu = false) }, + { "onSave", (Action)(_ => { hideMenu = false; actionManager.Modified = false; }) }, { "onExit", () => hideMenu = false }, { "map", world.Map }, { "playerDefinitions", editorActorLayer.Players.ToMiniYaml() }, @@ -355,15 +356,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (world.Type != WorldType.Editor) return; + var actionManager = world.WorldActor.Trait(); var button = AddButton("EXIT_EDITOR", "Exit Map Editor"); + + // Show dialog only if updated since last save button.OnClick = () => { - hideMenu = true; - ConfirmationDialogs.ButtonPrompt( - title: "Exit Map Editor", - text: "Exit and lose all unsaved changes?", - onConfirm: OnQuit, - onCancel: ShowMenu); + if (actionManager.HasUnsavedItems()) + { + hideMenu = true; + ConfirmationDialogs.ButtonPrompt( + title: "Exit Map Editor", + text: "Exit and lose all unsaved changes?", + onConfirm: OnQuit, + onCancel: ShowMenu); + } + else + OnQuit(); }; } }