Start fixing the editor

This commit is contained in:
Paul Chote
2010-12-29 19:03:45 +13:00
parent 58797c0d37
commit 829fe6530a
5 changed files with 47 additions and 38 deletions

View File

@@ -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.
@@ -244,7 +246,7 @@ namespace OpenRA.Editor
else
{
surface1.Map.PlayerCount = surface1.Map.Waypoints.Count;
surface1.Map.Save(loadedMapName);
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;
// TODO: Allow the user to choose map format (directory vs oramap)
loadedMapName = Path.Combine(nms.MapFolderPath, nms.txtNew.Text + ".oramap");
// try
// {
// Directory.CreateDirectory(mapZipName);
// }
// catch (Exception ed)
// {
// MessageBox.Show("Directory creation failed: {0}", ed.ToString());
// }
// 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<CountryInfo>().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 */

View File

@@ -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));

View File

@@ -41,6 +41,10 @@ namespace OpenRA.FileFormats
public Rectangle Bounds;
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;

View File

@@ -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<byte, byte>[1, 1];
Map map = new Map();
map.MapSize = new int2(1, 1);
map.Tileset = tileset;
map.MapResources = new TileReference<byte, byte>[1, 1];
var tile = OpenRA.Rules.TileSets[Tileset].Templates.First();
MapTiles = new TileReference<ushort, byte>[1, 1]
var tile = OpenRA.Rules.TileSets[map.Tileset].Templates.First();
map.MapTiles = new TileReference<ushort, byte>[1, 1]
{ { new TileReference<ushort, byte> {
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;

View File

@@ -45,7 +45,7 @@ namespace OpenRA
WidgetLoader = new WidgetLoader( this );
}
IEnumerable<string> FindMapsIn(string dir)
public static IEnumerable<string> 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);
}