diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index 0a1dbff02c..edf0430807 100755 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -61,8 +61,10 @@ namespace OpenRA.Editor Game.modData = new ModData(currentMod); + System.Console.WriteLine("Loading map: {0}",mapname); + // load the map - var map = new Map(new Folder(mapname, 0)); + var map = new Map(mapname); // upgrade maps that have no player definitions. editor doesnt care, // but this breaks the game pretty badly. @@ -243,8 +245,8 @@ namespace OpenRA.Editor SaveAsClicked(sender, e); else { - surface1.Map.PlayerCount = surface1.Map.Waypoints.Count; - surface1.Map.Save(loadedMapName); + surface1.Map.PlayerCount = surface1.Map.Waypoints.Count; + surface1.Map.Save(); dirty = false; } @@ -267,17 +269,10 @@ namespace OpenRA.Editor if (nms.txtNew.Text == "") nms.txtNew.Text = "unnamed"; - string mapZipName = Path.Combine(nms.MapFolderPath, nms.txtNew.Text + ".oramap"); - loadedMapName = mapZipName; - -// try -// { -// Directory.CreateDirectory(mapZipName); -// } -// catch (Exception ed) -// { -// MessageBox.Show("Directory creation failed: {0}", ed.ToString()); -// } + // TODO: Allow the user to choose map format (directory vs oramap) + loadedMapName = Path.Combine(nms.MapFolderPath, nms.txtNew.Text + ".oramap"); + + // TODO: Change surface1.Map.Container if necessary SaveClicked(sender, e); } @@ -297,8 +292,9 @@ namespace OpenRA.Editor if (DialogResult.OK == nms.ShowDialog()) { - string mapfoldername = Path.Combine(nms.MapFolderPath, nms.txtNew.Text); - LoadMap(mapfoldername); + var path = nms.txtNew.Tag as string; + System.Console.WriteLine("OpenClicked: {0}", path); + LoadMap(path); } } } @@ -313,7 +309,7 @@ namespace OpenRA.Editor if (DialogResult.OK == nmd.ShowDialog()) { - var map = new Map(nmd.theater.SelectedItem as string); + var map = Map.NewWithTileset(nmd.theater.SelectedItem as string); map.Resize((int)nmd.width.Value, (int)nmd.height.Value); map.ResizeCordon((int)nmd.cordonLeft.Value, (int)nmd.cordonTop.Value, @@ -371,7 +367,8 @@ namespace OpenRA.Editor map.Players.Add("Neutral", new PlayerReference("Neutral", Rules.Info["world"].Traits.WithInterface().First().Race, true, true)); - map.Save(savePath); + // TODO: Set map.Container using savePath + map.Save(); LoadMap(savePath); loadedMapName = null; /* editor needs to think this hasnt been saved */ diff --git a/OpenRA.Editor/MapSelect.cs b/OpenRA.Editor/MapSelect.cs index 8b24a9fd66..bc77d2dadb 100644 --- a/OpenRA.Editor/MapSelect.cs +++ b/OpenRA.Editor/MapSelect.cs @@ -18,13 +18,14 @@ namespace OpenRA.Editor void MapSelect_Load(object sender, EventArgs e) { - DirectoryInfo directory = new DirectoryInfo(MapFolderPath); - DirectoryInfo[] directories = directory.GetDirectories(); MapList.Items.Clear(); txtPathOut.Text = MapFolderPath; - foreach (DirectoryInfo subDirectory in directories) + + foreach (var map in ModData.FindMapsIn(MapFolderPath)) { - ListViewItem map1 = new ListViewItem(subDirectory.Name); + ListViewItem map1 = new ListViewItem(); + map1.Tag = map; + map1.Text = Path.GetFileNameWithoutExtension(map); map1.ImageIndex = 0; MapList.Items.Add(map1); } @@ -39,12 +40,15 @@ namespace OpenRA.Editor if (MapList.SelectedItems.Count == 1) { txtNew.Text = MapList.SelectedItems[0].Text; - var map = new Map(new Folder(Path.Combine(MapFolderPath, MapList.SelectedItems[0].Text), 0)); + txtNew.Tag = MapList.SelectedItems[0].Tag; + System.Console.WriteLine(MapList.SelectedItems[0]); + var map = new Map(txtNew.Tag as string); txtTitle.Text = map.Title; txtAuthor.Text = map.Author; txtTheater.Text = map.Tileset; txtDesc.Text = map.Description; pbMinimap.Image = null; + try { pbMinimap.Image = Minimap.AddStaticResources(map, Minimap.TerrainBitmap(map, true)); diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs index 6a69540090..ea757b2135 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.FileFormats/Map/MapStub.cs @@ -40,7 +40,11 @@ namespace OpenRA.FileFormats [FieldLoader.Load] public int2 BottomRight; public Rectangle Bounds; - public MapStub() {} // Hack for the editor - not used for anything important + public MapStub() {} // Hack for the editor - not used for anything important + + public MapStub(string path) + : this(FileSystem.OpenPackage(path, int.MaxValue)) {} + public MapStub(IFolder container) { Container = container; diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index cd22daecd4..b5cfb2e12e 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -53,25 +53,28 @@ namespace OpenRA // Do nothing; not a valid map (editor hack) } - public Map(string tileset) + public static Map NewWithTileset(string tileset) { - MapSize = new int2(1, 1); - Tileset = tileset; - MapResources = new TileReference[1, 1]; + Map map = new Map(); + map.MapSize = new int2(1, 1); + map.Tileset = tileset; + map.MapResources = new TileReference[1, 1]; - var tile = OpenRA.Rules.TileSets[Tileset].Templates.First(); - MapTiles = new TileReference[1, 1] + var tile = OpenRA.Rules.TileSets[map.Tileset].Templates.First(); + map.MapTiles = new TileReference[1, 1] { { new TileReference { type = tile.Key, image = (byte)(tile.Value.PickAny ? 0xffu : 0), index = (byte)(tile.Value.PickAny ? 0xffu : 0) } } }; - PlayerCount = 0; - ResizeCordon(0,0,0,0); + map.PlayerCount = 0; + map.ResizeCordon(0,0,0,0); - Title = "Name your map here"; - Description = "Describe your map here"; - Author = "Your name here"; + map.Title = "Name your map here"; + map.Description = "Describe your map here"; + map.Author = "Your name here"; + + return map; } class Format2ActorReference @@ -82,6 +85,7 @@ namespace OpenRA public string Owner = null; } + public Map(string path) : this(FileSystem.OpenPackage(path, int.MaxValue)) {} public Map(MapStub stub) : this(stub.Container) {} public Map(IFolder package) : base(package) @@ -192,7 +196,7 @@ namespace OpenRA LoadBinaryData(); } - public void Save(string filepath) + public void Save() { // Todo: save to a zip file in the support dir by default MapFormat = 3; diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 8be768f12c..4ba598690f 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -45,7 +45,7 @@ namespace OpenRA WidgetLoader = new WidgetLoader( this ); } - IEnumerable FindMapsIn(string dir) + public static IEnumerable FindMapsIn(string dir) { string[] NoMaps = { }; @@ -62,7 +62,7 @@ namespace OpenRA { var paths = mods.SelectMany(p => FindMapsIn("mods/" + p + "/maps/")); - return paths.Select(p => new MapStub(FileSystem.OpenPackage(p, int.MaxValue))) + return paths.Select(p => new MapStub(p)) .ToDictionary(m => m.Uid); }