From 11a2e6e19bb043ab8a0adb0243afab23b2c2aa40 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:31:41 +0300 Subject: [PATCH] Add more confirmation dialogue to the map editor When saving on top of another map, or when saving on a map that has been edited outside the map editor --- .../Widgets/Logic/Editor/SaveMapLogic.cs | 51 ++++++++++++++++--- .../Widgets/Logic/Ingame/IngameMenuLogic.cs | 9 ++-- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index c180272764..186df0f1a2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -158,12 +158,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var close = widget.Get("BACK_BUTTON"); close.OnClick = () => { Ui.CloseWindow(); onExit(); }; - var save = widget.Get("SAVE_BUTTON"); - save.OnClick = () => + Action saveMap = (string combinedPath) => { - if (string.IsNullOrEmpty(filename.Text)) - return; - map.Title = title.Text; map.Author = author.Text; @@ -175,8 +171,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic map.RequiresMod = modData.Manifest.Id; - var combinedPath = Platform.ResolvePath(Path.Combine(selectedDirectory.Folder.Name, filename.Text + fileTypes[fileType].Extension)); - try { if (!(map.Package is IReadWritePackage package) || package.Name != combinedPath) @@ -205,6 +199,49 @@ namespace OpenRA.Mods.Common.Widgets.Logic confirmText: "OK"); } }; + + var save = widget.Get("SAVE_BUTTON"); + save.OnClick = () => + { + if (string.IsNullOrEmpty(filename.Text)) + return; + + var combinedPath = Platform.ResolvePath(Path.Combine(selectedDirectory.Folder.Name, filename.Text + fileTypes[fileType].Extension)); + + if (map.Package?.Name != combinedPath) + { + // When creating a new map or when file paths don't match + if (modData.MapCache.Any(m => m.Status == MapStatus.Available && m.Package?.Name == combinedPath)) + { + ConfirmationDialogs.ButtonPrompt( + title: "Warning", + text: "By saving you will overwrite\n an already existing map.", + confirmText: "Save", + onConfirm: () => saveMap(combinedPath), + onCancel: () => { }); + + return; + } + } + else + { + // When file paths match + var recentUid = modData.MapCache.GetUpdatedMap(map.Uid); + if (recentUid != null && map.Uid != recentUid && modData.MapCache[recentUid].Status == MapStatus.Available) + { + ConfirmationDialogs.ButtonPrompt( + title: "Warning", + text: "The map has been edited from outside the editor.\n By saving you may overwrite progress", + confirmText: "Save", + onConfirm: () => saveMap(combinedPath), + onCancel: () => { }); + + return; + } + } + + saveMap(combinedPath); + }; } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index adbcb56990..838c7d6967 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -389,12 +389,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Show dialog only if updated since last save button.OnClick = () => { - if (actionManager.HasUnsavedItems()) + var map = modData.MapCache.GetUpdatedMap(world.Map.Uid); + var deletedOrUnavailable = map == null || modData.MapCache[map].Status != MapStatus.Available; + if (actionManager.HasUnsavedItems() || deletedOrUnavailable) { hideMenu = true; ConfirmationDialogs.ButtonPrompt( - title: "Exit Map Editor", - text: "Exit and lose all unsaved changes?", + title: "Warning", + text: deletedOrUnavailable ? "The map may have been deleted outside the editor" : "Exit and lose all unsaved changes?", + confirmText: deletedOrUnavailable ? "Exit anyway" : "Exit", onConfirm: OnQuit, onCancel: ShowMenu); }