diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 6a9cf41300..729b592a04 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -19,6 +19,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class SaveMapLogic : ChromeLogic { + enum MapFileType { Unpacked, OraMap } + + struct MapFileTypeInfo + { + public string Extension; + public string UiLabel; + } + [ObjectCreator.UseCtor] public SaveMapLogic(Widget widget, Action onSave, Action onExit, Map map, List playerDefinitions, List actorDefinitions) { @@ -85,32 +93,33 @@ namespace OpenRA.Mods.Common.Widgets.Logic directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapDirectories.Keys, setupItem); } + var attr = File.GetAttributes(map.Path); + var mapIsUnpacked = attr.HasFlag(FileAttributes.Directory); var filename = widget.Get("FILENAME"); - filename.Text = Path.GetFileNameWithoutExtension(map.Path); + filename.Text = mapIsUnpacked ? Path.GetFileName(map.Path) : Path.GetFileNameWithoutExtension(map.Path); + var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap; - var fileTypes = new Dictionary() + var fileTypes = new Dictionary() { - { ".oramap", ".oramap" }, - { "(unpacked)", "" } + { MapFileType.OraMap, new MapFileTypeInfo { Extension = ".oramap", UiLabel = ".oramap" } }, + { MapFileType.Unpacked, new MapFileTypeInfo { Extension = "", UiLabel = "(unpacked)" } } }; var typeDropdown = widget.Get("TYPE_DROPDOWN"); { - Func setupItem = (option, template) => + Func, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, - () => typeDropdown.Text == option, - () => typeDropdown.Text = option); - item.Get("LABEL").GetText = () => option; + () => fileType == option.Key, + () => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; }); + item.Get("LABEL").GetText = () => option.Value.UiLabel; return item; }; - typeDropdown.Text = map.Path != null ? Path.GetExtension(map.Path) : ".oramap"; - if (string.IsNullOrEmpty(typeDropdown.Text)) - typeDropdown.Text = fileTypes.First(t => t.Value == "").Key; + typeDropdown.Text = fileTypes[fileType].UiLabel; typeDropdown.OnClick = () => - typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes.Keys, setupItem); + typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, setupItem); } var close = widget.Get("BACK_BUTTON"); @@ -138,7 +147,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Create the map directory if required Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text)); - var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[typeDropdown.Text])); + var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[fileType].Extension)); // Invalidate the old map metadata if (map.Uid != null && combinedPath == map.Path)