From b2050ae1aae5cc1fc40d0b8ce8207d1256bb9bb3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 20 Jun 2015 19:30:59 +0100 Subject: [PATCH] Use the map save dialog to set new map properties. --- .../Widgets/Logic/Editor/NewMapLogic.cs | 35 +++++++++---------- .../Widgets/Logic/Editor/SaveMapLogic.cs | 16 ++++++--- .../Widgets/Logic/Ingame/IngameMenuLogic.cs | 5 ++- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs index c9d07117b4..8810cb67fb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs @@ -68,26 +68,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic map.PlayerDefinitions = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length).ToMiniYaml(); map.FixOpenAreas(modRules); - var userMapFolder = Game.ModData.Manifest.MapFolders.First(f => f.Value == "User").Key; + Action afterSave = uid => + { + ConnectionLogic.Connect(System.Net.IPAddress.Loopback.ToString(), + Game.CreateLocalServer(uid), "", + () => Game.LoadEditor(uid), + () => { Game.CloseServer(); onExit(); }); - // Ignore optional flag - if (userMapFolder.StartsWith("~")) - userMapFolder = userMapFolder.Substring(1); + Ui.CloseWindow(); + onSelect(uid); + }; - var mapDir = Platform.ResolvePath(userMapFolder); - Directory.CreateDirectory(mapDir); - var tempLocation = Path.Combine(mapDir, "temp") + ".oramap"; - map.Save(tempLocation); // TODO: load it right away and save later properly - - var newMap = new Map(tempLocation); - Game.ModData.MapCache[newMap.Uid].UpdateFromMap(newMap, MapClassification.User); - - ConnectionLogic.Connect(System.Net.IPAddress.Loopback.ToString(), - Game.CreateLocalServer(newMap.Uid), - "", - () => { Game.LoadEditor(newMap.Uid); }, - () => { Game.CloseServer(); onExit(); }); - onSelect(newMap.Uid); + Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs() + { + { "onSave", afterSave }, + { "onExit", () => { Ui.CloseWindow(); onExit(); } }, + { "map", map }, + { "playerDefinitions", map.PlayerDefinitions }, + { "actorDefinitions", map.ActorDefinitions } + }); }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index f23752e1c8..6753f4ab98 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public class SaveMapLogic { [ObjectCreator.UseCtor] - public SaveMapLogic(Widget widget, Action onExit, Map map, EditorActorLayer editorActorLayer) + public SaveMapLogic(Widget widget, Action onSave, Action onExit, Map map, List playerDefinitions, List actorDefinitions) { var title = widget.Get("TITLE"); title.Text = map.Title; @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return item; }; - var mapDirectory = Platform.UnresolvePath(Path.GetDirectoryName(map.Path)); + var mapDirectory = map.Path != null ? Platform.UnresolvePath(Path.GetDirectoryName(map.Path)) : null; var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory); if (initialDirectory == null) @@ -125,8 +125,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic map.Description = description.Text; map.Author = author.Text; map.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text); - map.ActorDefinitions = editorActorLayer.Save(); - map.PlayerDefinitions = editorActorLayer.Players.ToMiniYaml(); + + if (actorDefinitions != null) + map.ActorDefinitions = actorDefinitions; + + if (playerDefinitions != null) + map.PlayerDefinitions = playerDefinitions; + map.RequiresMod = Game.ModData.Manifest.Mod.Id; var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[typeDropdown.Text])); @@ -145,7 +150,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic Console.WriteLine("Saved current map at {0}", combinedPath); Ui.CloseWindow(); - onExit(); + + onSave(map.Uid); }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index f06b6be483..4460f912de 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -102,11 +102,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic saveMapButton.OnClick = () => { hideMenu = true; + var editorActorLayer = world.WorldActor.Trait(); Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs() { + { "onSave", (Action)(_ => hideMenu = false) }, { "onExit", () => hideMenu = false }, { "map", world.Map }, - { "editorActorLayer", world.WorldActor.Trait() } + { "playerDefinitions", editorActorLayer.Players.ToMiniYaml() }, + { "actorDefinitions", editorActorLayer.Save() } }); };