Fix editor

This commit is contained in:
Paul Chote
2010-06-26 14:56:51 +12:00
parent 920b4f6856
commit 49d7833b04
2 changed files with 16 additions and 25 deletions

View File

@@ -101,29 +101,21 @@ namespace OpenRA.Editor
void PrepareMapResources(Manifest manifest, Map map) void PrepareMapResources(Manifest manifest, Map map)
{ {
Rules.LoadRules(manifest, map); Rules.LoadRules(manifest, map);
tileset = Rules.TileSets[map.Theater];
// we're also going to need a tileset...
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>()
.FirstOrDefault(t => t.Theater == map.Theater);
tileset = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix);
colors = theaterInfo.MapColors;
var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true); var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true);
surface1.Bind(map, tileset, palette); surface1.Bind(map, tileset, palette);
// construct the palette of tiles // construct the palette of tiles
var palettes = new[] { tilePalette, actorPalette, resourcePalette }; var palettes = new[] { tilePalette, actorPalette, resourcePalette };
foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); } foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); }
foreach (var n in tileset.tiles.Keys) foreach (var t in tileset.Templates)
{ {
try try
{ {
var bitmap = RenderTemplate(tileset, (ushort)n, palette); var bitmap = RenderTemplate(tileset, (ushort)t.Key, palette);
var ibox = new PictureBox var ibox = new PictureBox
{ {
Image = bitmap, Image = bitmap,
@@ -132,16 +124,16 @@ namespace OpenRA.Editor
SizeMode = PictureBoxSizeMode.StretchImage SizeMode = PictureBoxSizeMode.StretchImage
}; };
var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = n }; var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key };
ibox.Click += (_, e) => surface1.SetBrush(brushTemplate); ibox.Click += (_, e) => surface1.SetBrush(brushTemplate);
var template = tileset.walk[n]; var template = t.Value;
tilePalette.Controls.Add(ibox); tilePalette.Controls.Add(ibox);
tt.SetToolTip(ibox, tt.SetToolTip(ibox,
"{1}:{0} ({3}x{4} {2})".F( "{1}:{0} ({3}x{4} {2})".F(
template.Name, template.Image,
template.Index, template.Id,
template.Bridge, template.Bridge,
template.Size.X, template.Size.X,
template.Size.Y)); template.Size.Y));
@@ -156,7 +148,7 @@ namespace OpenRA.Editor
try try
{ {
var info = Rules.Info[a]; var info = Rules.Info[a];
var template = RenderActor(info, theaterInfo.Suffix, palette); var template = RenderActor(info, tileset.TileSuffix, palette);
var ibox = new PictureBox var ibox = new PictureBox
{ {
Image = template.Bitmap, Image = template.Bitmap,
@@ -187,7 +179,7 @@ namespace OpenRA.Editor
{ {
try try
{ {
var template = RenderResourceType(a, theaterInfo.Suffix, palette); var template = RenderResourceType(a, tileset.TileSuffix, palette);
var ibox = new PictureBox var ibox = new PictureBox
{ {
Image = template.Bitmap, Image = template.Bitmap,
@@ -217,8 +209,8 @@ namespace OpenRA.Editor
static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p) static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p)
{ {
var template = ts.walk[n]; var template = ts.Templates[n];
var tile = ts.tiles[n]; var tile = ts.Tiles[n];
var bitmap = new Bitmap(24 * template.Size.X, 24 * template.Size.Y); var bitmap = new Bitmap(24 * template.Size.X, 24 * template.Size.Y);
var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
@@ -388,8 +380,7 @@ namespace OpenRA.Editor
using (var nmd = new NewMapDialog()) using (var nmd = new NewMapDialog())
{ {
nmd.theater.Items.Clear(); nmd.theater.Items.Clear();
nmd.theater.Items.AddRange(Rules.Info["world"].Traits.WithInterface<TheaterInfo>() nmd.theater.Items.AddRange(Rules.TileSets.Select(a => a.Value.Name).ToArray());
.Select(a => a.Theater).ToArray());
nmd.theater.SelectedIndex = 0; nmd.theater.SelectedIndex = 0;
if (DialogResult.OK == nmd.ShowDialog()) if (DialogResult.OK == nmd.ShowDialog())

View File

@@ -136,8 +136,8 @@ namespace OpenRA.Editor
void DrawWithBrush() void DrawWithBrush()
{ {
// change the bits in the map // change the bits in the map
var tile = TileSet.tiles[Brush.N]; var tile = TileSet.Tiles[Brush.N];
var template = TileSet.walk[Brush.N]; var template = TileSet.Templates[Brush.N];
var pos = GetBrushLocation(); var pos = GetBrushLocation();
if (ModifierKeys == Keys.Shift) if (ModifierKeys == Keys.Shift)
@@ -294,7 +294,7 @@ namespace OpenRA.Editor
for (var j = 0; j < ChunkSize; j++) for (var j = 0; j < ChunkSize; j++)
{ {
var tr = Map.MapTiles[u * ChunkSize + i, v * ChunkSize + j]; var tr = Map.MapTiles[u * ChunkSize + i, v * ChunkSize + j];
var tile = TileSet.tiles[tr.type]; var tile = TileSet.Tiles[tr.type];
var index = (tr.image < tile.TileBitmapBytes.Count) ? tr.image : (byte)0; var index = (tr.image < tile.TileBitmapBytes.Count) ? tr.image : (byte)0;
var rawImage = tile.TileBitmapBytes[index]; var rawImage = tile.TileBitmapBytes[index];
for (var x = 0; x < 24; x++) for (var x = 0; x < 24; x++)