mapactor rendering
This commit is contained in:
@@ -14,4 +14,10 @@ namespace OpenRA.Editor
|
|||||||
public ActorInfo Info;
|
public ActorInfo Info;
|
||||||
public bool Centered;
|
public bool Centered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BrushTemplate
|
||||||
|
{
|
||||||
|
public Bitmap Bitmap;
|
||||||
|
public ushort N;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ namespace OpenRA.Editor
|
|||||||
SizeMode = PictureBoxSizeMode.StretchImage
|
SizeMode = PictureBoxSizeMode.StretchImage
|
||||||
};
|
};
|
||||||
|
|
||||||
var p = Pair.New(n, bitmap);
|
var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = n };
|
||||||
ibox.Click += (_, e) => surface1.Brush = p;
|
ibox.Click += (_, e) => surface1.SetBrush(brushTemplate);
|
||||||
|
|
||||||
var template = tileset.walk[n];
|
var template = tileset.walk[n];
|
||||||
tilePalette.Controls.Add(ibox);
|
tilePalette.Controls.Add(ibox);
|
||||||
@@ -79,6 +79,8 @@ namespace OpenRA.Editor
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actorTemplates = new List<ActorTemplate>();
|
||||||
|
|
||||||
foreach (var a in Rules.Info.Keys)
|
foreach (var a in Rules.Info.Keys)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -93,15 +95,21 @@ namespace OpenRA.Editor
|
|||||||
SizeMode = PictureBoxSizeMode.StretchImage
|
SizeMode = PictureBoxSizeMode.StretchImage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ibox.Click += (_, e) => surface1.SetActor(template);
|
||||||
|
|
||||||
actorPalette.Controls.Add(ibox);
|
actorPalette.Controls.Add(ibox);
|
||||||
|
|
||||||
tt.SetToolTip(ibox,
|
tt.SetToolTip(ibox,
|
||||||
"{0}:{1}".F(
|
"{0}:{1}".F(
|
||||||
info.Name,
|
info.Name,
|
||||||
info.Category));
|
info.Category));
|
||||||
|
|
||||||
|
actorTemplates.Add( template);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
surface1.BindActorTemplates(actorTemplates);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocateGameRoot()
|
void LocateGameRoot()
|
||||||
@@ -183,7 +191,7 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitmap.UnlockBits(data);
|
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>() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Editor
|
namespace OpenRA.Editor
|
||||||
@@ -12,17 +13,29 @@ namespace OpenRA.Editor
|
|||||||
public TileSet TileSet { get; private set; }
|
public TileSet TileSet { get; private set; }
|
||||||
public Palette Palette { get; private set; }
|
public Palette Palette { get; private set; }
|
||||||
int2 Offset;
|
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)
|
public void Bind(Map m, TileSet ts, Palette p)
|
||||||
{
|
{
|
||||||
Map = m;
|
Map = m;
|
||||||
TileSet = ts;
|
TileSet = ts;
|
||||||
Palette = p;
|
Palette = p;
|
||||||
Brush = Pair.New((ushort)0, null as Bitmap);
|
Brush = null;
|
||||||
Chunks.Clear();
|
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>();
|
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
|
||||||
|
|
||||||
public Surface()
|
public Surface()
|
||||||
@@ -52,10 +65,12 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButtons.Left && Brush.Second != null)
|
if (e.Button == MouseButtons.Left && Brush != null)
|
||||||
DrawWithBrush();
|
DrawWithBrush();
|
||||||
|
if (e.Button == MouseButtons.Left && Actor != null)
|
||||||
|
DrawWithActor();
|
||||||
|
|
||||||
if (Brush.Second != null)
|
if (Brush != null || Actor != null)
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,8 +78,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.First];
|
var tile = TileSet.tiles[Brush.N];
|
||||||
var template = TileSet.walk[Brush.First];
|
var template = TileSet.walk[Brush.N];
|
||||||
var pos = GetBrushLocation();
|
var pos = GetBrushLocation();
|
||||||
|
|
||||||
for (var u = 0; u < template.Size.X; u++)
|
for (var u = 0; u < template.Size.X; u++)
|
||||||
@@ -75,7 +90,7 @@ namespace OpenRA.Editor
|
|||||||
var z = u + v * template.Size.X;
|
var z = u + v * template.Size.X;
|
||||||
if (tile.TileBitmapBytes[z] != null)
|
if (tile.TileBitmapBytes[z] != null)
|
||||||
Map.MapTiles[u + pos.X, v + pos.Y] =
|
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);
|
var ch = new int2((pos.X + u) / ChunkSize, (pos.Y + v) / ChunkSize);
|
||||||
if (Chunks.ContainsKey(ch))
|
if (Chunks.ContainsKey(ch))
|
||||||
@@ -87,15 +102,24 @@ namespace OpenRA.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawWithActor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(e);
|
base.OnMouseDown(e);
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Right)
|
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();
|
DrawWithBrush();
|
||||||
|
if (e.Button == MouseButtons.Left && Actor != null)
|
||||||
|
DrawWithActor();
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -139,6 +163,15 @@ namespace OpenRA.Editor
|
|||||||
return new int2(v.X / 24, v.Y / 24);
|
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)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
if (Map == null) return;
|
if (Map == null) return;
|
||||||
@@ -155,9 +188,15 @@ namespace OpenRA.Editor
|
|||||||
e.Graphics.DrawRectangle(CordonPen,
|
e.Graphics.DrawRectangle(CordonPen,
|
||||||
new Rectangle(Map.XOffset * 24 + Offset.X, Map.YOffset * 24 + Offset.Y, Map.Width * 24, Map.Height * 24));
|
new Rectangle(Map.XOffset * 24 + Offset.X, Map.YOffset * 24 + Offset.Y, Map.Width * 24, Map.Height * 24));
|
||||||
|
|
||||||
if (Brush.Second != null)
|
foreach (var ar in Map.Actors)
|
||||||
e.Graphics.DrawImage(Brush.Second,
|
DrawActor(e.Graphics, ar.Value.Location, ActorTemplates[ar.Value.Name]);
|
||||||
|
|
||||||
|
if (Brush != null)
|
||||||
|
e.Graphics.DrawImage(Brush.Bitmap,
|
||||||
(24 * GetBrushLocation() + Offset).ToPoint());
|
(24 * GetBrushLocation() + Offset).ToPoint());
|
||||||
|
|
||||||
|
if (Actor != null)
|
||||||
|
DrawActor(e.Graphics, GetBrushLocation(), Actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user