almost working renderer
This commit is contained in:
6
OpenRA.Editor/Form1.Designer.cs
generated
6
OpenRA.Editor/Form1.Designer.cs
generated
@@ -32,8 +32,8 @@
|
|||||||
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
|
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
|
||||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||||
this.tilePalette = new System.Windows.Forms.FlowLayoutPanel();
|
this.tilePalette = new System.Windows.Forms.FlowLayoutPanel();
|
||||||
this.surface1 = new OpenRA.Editor.Surface();
|
|
||||||
this.tt = new System.Windows.Forms.ToolTip(this.components);
|
this.tt = new System.Windows.Forms.ToolTip(this.components);
|
||||||
|
this.surface1 = new OpenRA.Editor.Surface();
|
||||||
this.toolStripContainer1.ContentPanel.SuspendLayout();
|
this.toolStripContainer1.ContentPanel.SuspendLayout();
|
||||||
this.toolStripContainer1.SuspendLayout();
|
this.toolStripContainer1.SuspendLayout();
|
||||||
this.splitContainer1.Panel1.SuspendLayout();
|
this.splitContainer1.Panel1.SuspendLayout();
|
||||||
@@ -81,6 +81,10 @@
|
|||||||
this.tilePalette.Size = new System.Drawing.Size(198, 680);
|
this.tilePalette.Size = new System.Drawing.Size(198, 680);
|
||||||
this.tilePalette.TabIndex = 0;
|
this.tilePalette.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// tt
|
||||||
|
//
|
||||||
|
this.tt.ShowAlways = true;
|
||||||
|
//
|
||||||
// surface1
|
// surface1
|
||||||
//
|
//
|
||||||
this.surface1.BackColor = System.Drawing.Color.Black;
|
this.surface1.BackColor = System.Drawing.Color.Black;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
surface1.TileSet = tileset;
|
surface1.TileSet = tileset;
|
||||||
surface1.Map = map;
|
surface1.Map = map;
|
||||||
|
surface1.Palette = palette;
|
||||||
|
|
||||||
// construct the palette of tiles
|
// construct the palette of tiles
|
||||||
|
|
||||||
@@ -44,8 +45,27 @@ namespace OpenRA.Editor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var bitmap = RenderTemplate(tileset, (ushort)n, palette);
|
var bitmap = RenderTemplate(tileset, (ushort)n, palette);
|
||||||
var ibox = new PictureBox { Image = bitmap, Width = bitmap.Width, Height = bitmap.Height };
|
var ibox = new PictureBox
|
||||||
|
{
|
||||||
|
Image = bitmap,
|
||||||
|
Width = bitmap.Width / 2,
|
||||||
|
Height = bitmap.Height / 2,
|
||||||
|
SizeMode = PictureBoxSizeMode.StretchImage
|
||||||
|
};
|
||||||
|
|
||||||
|
var p = Pair.New(n, bitmap);
|
||||||
|
ibox.Click += (_, e) => surface1.Brush = p;
|
||||||
|
|
||||||
|
var template = tileset.walk[n];
|
||||||
tilePalette.Controls.Add(ibox);
|
tilePalette.Controls.Add(ibox);
|
||||||
|
|
||||||
|
tt.SetToolTip(ibox,
|
||||||
|
"{1}:{0} ({3}x{4} {2})".F(
|
||||||
|
template.Name,
|
||||||
|
template.Index,
|
||||||
|
template.Bridge,
|
||||||
|
template.Size.X,
|
||||||
|
template.Size.Y));
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
@@ -77,7 +97,7 @@ namespace OpenRA.Editor
|
|||||||
var template = ts.walk[n];
|
var template = ts.walk[n];
|
||||||
var tile = ts.tiles[n];
|
var tile = ts.tiles[n];
|
||||||
|
|
||||||
var bitmap = new Bitmap(Surface.CellSize * template.Size.X, Surface.CellSize * template.Size.Y);
|
var bitmap = new Bitmap(24 * template.Size.X, 24 * template.Size.Y);
|
||||||
|
|
||||||
for( var u = 0; u < template.Size.X; u++ )
|
for( var u = 0; u < template.Size.X; u++ )
|
||||||
for( var v = 0; v < template.Size.Y; v++ )
|
for( var v = 0; v < template.Size.Y; v++ )
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ namespace OpenRA.Editor
|
|||||||
{
|
{
|
||||||
public Map Map { get; set; }
|
public Map Map { get; set; }
|
||||||
public TileSet TileSet { get; set; }
|
public TileSet TileSet { get; set; }
|
||||||
|
public Palette Palette { get; set; }
|
||||||
public int2 Offset { get; set; }
|
public int2 Offset { get; set; }
|
||||||
|
public Pair<ushort, Bitmap> Brush { get; set; }
|
||||||
|
|
||||||
|
Dictionary<int2, Bitmap> Chunks = new Dictionary<int2, Bitmap>();
|
||||||
|
|
||||||
public Surface()
|
public Surface()
|
||||||
: base()
|
: base()
|
||||||
@@ -26,23 +30,48 @@ namespace OpenRA.Editor
|
|||||||
|
|
||||||
public const int CellSize = 24;
|
public const int CellSize = 24;
|
||||||
static readonly Pen RedPen = new Pen(Color.Red);
|
static readonly Pen RedPen = new Pen(Color.Red);
|
||||||
|
int2 MousePos;
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
MousePos = new int2(e.Location);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
if (e.Button == MouseButtons.Right)
|
||||||
|
Brush = Pair.New((ushort)0, null as Bitmap);
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int ChunkSize = 8; // 8x8 chunks ==> 192x192 bitmaps.
|
||||||
|
|
||||||
|
Bitmap RenderChunk(int u, int v)
|
||||||
|
{
|
||||||
|
var bitmap = new Bitmap(ChunkSize * 24, ChunkSize * 24);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
if (Map == null) return;
|
if (Map == null) return;
|
||||||
if (TileSet == null) return;
|
if (TileSet == null) return;
|
||||||
|
|
||||||
var n = (ushort)14;
|
for( var u = Map.TopLeft.X - Map.TopLeft.X % ChunkSize; u < Map.BottomRight.X; u += ChunkSize )
|
||||||
|
for (var v = Map.TopLeft.Y - Map.TopLeft.Y % ChunkSize; v < Map.BottomRight.Y; v += ChunkSize)
|
||||||
|
{
|
||||||
|
var x = new int2(u,v);
|
||||||
|
if (!Chunks.ContainsKey(x)) Chunks[x] = RenderChunk(u, v);
|
||||||
|
e.Graphics.DrawImage(Chunks[x], u * ChunkSize * 24, v * ChunkSize * 24);
|
||||||
|
}
|
||||||
|
|
||||||
var template = TileSet.walk[n];
|
if (Brush.Second != null)
|
||||||
var tile = TileSet.tiles[n];
|
e.Graphics.DrawImage(Brush.Second,
|
||||||
|
(MousePos - new int2(MousePos.X % 24, MousePos.Y % 24)).ToPoint());
|
||||||
for( var u = 0; u < template.Size.X; u++ )
|
|
||||||
for( var v = 0; v < template.Size.Y; v++ )
|
|
||||||
if (template.TerrainType.ContainsKey(u + v * template.Size.X))
|
|
||||||
{
|
|
||||||
e.Graphics.DrawRectangle(RedPen, new Rectangle(CellSize * u, CellSize * v, CellSize, CellSize));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user