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
This commit is contained in:
@@ -158,12 +158,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var close = widget.Get<ButtonWidget>("BACK_BUTTON");
|
||||
close.OnClick = () => { Ui.CloseWindow(); onExit(); };
|
||||
|
||||
var save = widget.Get<ButtonWidget>("SAVE_BUTTON");
|
||||
save.OnClick = () =>
|
||||
Action<string> 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<ButtonWidget>("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);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user