mapactor rendering

This commit is contained in:
Chris Forbes
2010-05-10 18:05:03 +12:00
parent 0673fc23bf
commit 2921618067
3 changed files with 67 additions and 14 deletions

View File

@@ -14,4 +14,10 @@ namespace OpenRA.Editor
public ActorInfo Info;
public bool Centered;
}
class BrushTemplate
{
public Bitmap Bitmap;
public ushort N;
}
}

View File

@@ -62,8 +62,8 @@ namespace OpenRA.Editor
SizeMode = PictureBoxSizeMode.StretchImage
};
var p = Pair.New(n, bitmap);
ibox.Click += (_, e) => surface1.Brush = p;
var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = n };
ibox.Click += (_, e) => surface1.SetBrush(brushTemplate);
var template = tileset.walk[n];
tilePalette.Controls.Add(ibox);
@@ -79,6 +79,8 @@ namespace OpenRA.Editor
catch { }
}
var actorTemplates = new List<ActorTemplate>();
foreach (var a in Rules.Info.Keys)
{
try
@@ -93,15 +95,21 @@ namespace OpenRA.Editor
SizeMode = PictureBoxSizeMode.StretchImage
};
ibox.Click += (_, e) => surface1.SetActor(template);
actorPalette.Controls.Add(ibox);
tt.SetToolTip(ibox,
"{0}:{1}".F(
info.Name,
info.Category));
actorTemplates.Add( template);
}
catch { }
}
surface1.BindActorTemplates(actorTemplates);
}
void LocateGameRoot()
@@ -183,7 +191,7 @@ namespace OpenRA.Editor
}
bitmap.UnlockBits(data);
return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<Building>() };
return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
}
}

View File

@@ -2,6 +2,7 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Editor
@@ -12,17 +13,29 @@ namespace OpenRA.Editor
public TileSet TileSet { get; private set; }
public Palette Palette { get; private set; }
int2 Offset;
public Pair<ushort, Bitmap> Brush;
public BrushTemplate Brush;
public ActorTemplate Actor;
Dictionary<string, ActorTemplate> ActorTemplates = new Dictionary<string, ActorTemplate>();
public void Bind(Map m, TileSet ts, Palette p)
{
Map = m;
TileSet = ts;
Palette = p;
Brush = Pair.New((ushort)0, null as Bitmap);
Brush = null;
Chunks.Clear();
}
public void SetBrush(BrushTemplate brush) { Actor = null; Brush = brush; }
public void SetActor(ActorTemplate actor) { Brush = null; Actor = actor; }
public void BindActorTemplates(IEnumerable<ActorTemplate> templates)
{
ActorTemplates = templates.ToDictionary(a => a.Info.Name.ToLowerInvariant());
}
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
public Surface()
@@ -52,10 +65,12 @@ namespace OpenRA.Editor
}
else
{
if (e.Button == MouseButtons.Left && Brush.Second != null)
if (e.Button == MouseButtons.Left && Brush != null)
DrawWithBrush();
if (e.Button == MouseButtons.Left && Actor != null)
DrawWithActor();
if (Brush.Second != null)
if (Brush != null || Actor != null)
Invalidate();
}
}
@@ -63,8 +78,8 @@ namespace OpenRA.Editor
void DrawWithBrush()
{
// change the bits in the map
var tile = TileSet.tiles[Brush.First];
var template = TileSet.walk[Brush.First];
var tile = TileSet.tiles[Brush.N];
var template = TileSet.walk[Brush.N];
var pos = GetBrushLocation();
for (var u = 0; u < template.Size.X; u++)
@@ -75,7 +90,7 @@ namespace OpenRA.Editor
var z = u + v * template.Size.X;
if (tile.TileBitmapBytes[z] != null)
Map.MapTiles[u + pos.X, v + pos.Y] =
new TileReference<ushort, byte> { type = Brush.First, image = (byte)z, index = (byte)z };
new TileReference<ushort, byte> { type = Brush.N, image = (byte)z, index = (byte)z };
var ch = new int2((pos.X + u) / ChunkSize, (pos.Y + v) / ChunkSize);
if (Chunks.ContainsKey(ch))
@@ -87,15 +102,24 @@ namespace OpenRA.Editor
}
}
void DrawWithActor()
{
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Right)
Brush = Pair.New((ushort)0, null as Bitmap);
{
Actor = null;
Brush = null;
}
if (e.Button == MouseButtons.Left && Brush.Second != null)
if (e.Button == MouseButtons.Left && Brush != null)
DrawWithBrush();
if (e.Button == MouseButtons.Left && Actor != null)
DrawWithActor();
Invalidate();
}
@@ -139,6 +163,15 @@ namespace OpenRA.Editor
return new int2(v.X / 24, v.Y / 24);
}
void DrawActor(System.Drawing.Graphics g, int2 p, ActorTemplate t)
{
g.DrawImage(t.Bitmap,
((24 * p + Offset
- (t.Centered
? new int2(t.Bitmap.Width / 2 - 12, t.Bitmap.Height / 2 - 12)
: int2.Zero)).ToPoint()));
}
protected override void OnPaint(PaintEventArgs e)
{
if (Map == null) return;
@@ -155,9 +188,15 @@ namespace OpenRA.Editor
e.Graphics.DrawRectangle(CordonPen,
new Rectangle(Map.XOffset * 24 + Offset.X, Map.YOffset * 24 + Offset.Y, Map.Width * 24, Map.Height * 24));
if (Brush.Second != null)
e.Graphics.DrawImage(Brush.Second,
foreach (var ar in Map.Actors)
DrawActor(e.Graphics, ar.Value.Location, ActorTemplates[ar.Value.Name]);
if (Brush != null)
e.Graphics.DrawImage(Brush.Bitmap,
(24 * GetBrushLocation() + Offset).ToPoint());
if (Actor != null)
DrawActor(e.Graphics, GetBrushLocation(), Actor);
}
}
}