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