start splitting up tsb; fix a wtf in the save code
This commit is contained in:
@@ -24,6 +24,7 @@ namespace OpenRA.TilesetBuilder
|
|||||||
{
|
{
|
||||||
string srcfile;
|
string srcfile;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
public Form1( string src, int size )
|
public Form1( string src, int size )
|
||||||
{
|
{
|
||||||
srcfile = src;
|
srcfile = src;
|
||||||
@@ -31,11 +32,11 @@ namespace OpenRA.TilesetBuilder
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
surface1.TileSize = size;
|
surface1.TileSize = size;
|
||||||
surface1.Image = (Bitmap)Image.FromFile(src);
|
surface1.Image = (Bitmap)Image.FromFile(src);
|
||||||
|
surface1.Image.SetResolution(96, 96); // people keep being noobs about DPI, and GDI+ cares.
|
||||||
surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size]; /* all passable by default */
|
surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size]; /* all passable by default */
|
||||||
surface1.Templates = new List<Template>();
|
surface1.Templates = new List<Template>();
|
||||||
surface1.Size = surface1.Image.Size;
|
surface1.Size = surface1.Image.Size;
|
||||||
|
|
||||||
/* todo: load stuff from previous session */
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +79,7 @@ namespace OpenRA.TilesetBuilder
|
|||||||
w.WriteAttributeString("x", i.ToString());
|
w.WriteAttributeString("x", i.ToString());
|
||||||
w.WriteAttributeString("y", j.ToString());
|
w.WriteAttributeString("y", j.ToString());
|
||||||
w.WriteAttributeString("t", surface1.TerrainTypes[i, j].ToString());
|
w.WriteAttributeString("t", surface1.TerrainTypes[i, j].ToString());
|
||||||
|
w.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var t in surface1.Templates)
|
foreach (var t in surface1.Templates)
|
||||||
@@ -235,7 +237,7 @@ namespace OpenRA.TilesetBuilder
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (var x = 0; x < TileSize * TileSize; x++)
|
for (var x = 0; x < TileSize * TileSize; x++)
|
||||||
bw.Write((byte)0); /* todo: don't fill with air */
|
bw.Write((byte)0); /* todo: don't fill with air */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,125 +275,4 @@ namespace OpenRA.TilesetBuilder
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Template
|
|
||||||
{
|
|
||||||
public Dictionary<int2, bool> Cells = new Dictionary<int2, bool>();
|
|
||||||
|
|
||||||
public int Left { get { return Cells.Keys.Min(c => c.X); } }
|
|
||||||
public int Top { get { return Cells.Keys.Min(c => c.Y); } }
|
|
||||||
|
|
||||||
public int Right { get { return Cells.Keys.Max(c => c.X) + 1; } }
|
|
||||||
public int Bottom { get { return Cells.Keys.Max(c => c.Y) + 1; } }
|
|
||||||
|
|
||||||
public int Width { get { return Right - Left; } }
|
|
||||||
public int Height { get { return Bottom - Top; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
class Surface : Control
|
|
||||||
{
|
|
||||||
public Bitmap Image;
|
|
||||||
public int[,] TerrainTypes;
|
|
||||||
public List<Template> Templates = new List<Template>();
|
|
||||||
public bool ShowTerrainTypes = true;
|
|
||||||
public string InputMode;
|
|
||||||
public int TileSize;
|
|
||||||
|
|
||||||
Template CurrentTemplate;
|
|
||||||
|
|
||||||
public Surface()
|
|
||||||
{
|
|
||||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
||||||
SetStyle(ControlStyles.ResizeRedraw, true);
|
|
||||||
UpdateStyles();
|
|
||||||
}
|
|
||||||
|
|
||||||
Brush currentBrush = new SolidBrush(Color.FromArgb(60, Color.White));
|
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
|
||||||
{
|
|
||||||
if (Image == null || TerrainTypes == null || Templates == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* draw the background */
|
|
||||||
e.Graphics.DrawImageUnscaled(Image, 0, 0);
|
|
||||||
|
|
||||||
/* draw terrain type overlays */
|
|
||||||
if (ShowTerrainTypes)
|
|
||||||
for (var i = 0; i <= TerrainTypes.GetUpperBound(0); i++)
|
|
||||||
for (var j = 0; j <= TerrainTypes.GetUpperBound(1); j++)
|
|
||||||
if (TerrainTypes[i, j] != 0)
|
|
||||||
{
|
|
||||||
e.Graphics.FillRectangle(Brushes.Black, TileSize * i + 10, TileSize * j + 10, 10, 10);
|
|
||||||
e.Graphics.DrawString(TerrainTypes[i, j].ToString(),
|
|
||||||
Font, Brushes.LimeGreen, TileSize * i + 10, TileSize * j + 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* draw template outlines */
|
|
||||||
foreach (var t in Templates)
|
|
||||||
{
|
|
||||||
foreach (var c in t.Cells.Keys)
|
|
||||||
{
|
|
||||||
if (CurrentTemplate == t)
|
|
||||||
e.Graphics.FillRectangle(currentBrush, TileSize * c.X, TileSize * c.Y, TileSize, TileSize);
|
|
||||||
|
|
||||||
if (!t.Cells.ContainsKey(c + new int2(-1, 0)))
|
|
||||||
e.Graphics.DrawLine(Pens.Red, (TileSize * c).ToPoint(), (TileSize * (c + new int2(0, 1))).ToPoint());
|
|
||||||
if (!t.Cells.ContainsKey(c + new int2(+1, 0)))
|
|
||||||
e.Graphics.DrawLine(Pens.Red, (TileSize * (c + new int2(1, 0))).ToPoint(), (TileSize * (c + new int2(1, 1))).ToPoint());
|
|
||||||
if (!t.Cells.ContainsKey(c + new int2(0, +1)))
|
|
||||||
e.Graphics.DrawLine(Pens.Red, (TileSize * (c + new int2(0, 1))).ToPoint(), (TileSize * (c + new int2(1, 1))).ToPoint());
|
|
||||||
if (!t.Cells.ContainsKey(c + new int2(0, -1)))
|
|
||||||
e.Graphics.DrawLine(Pens.Red, (TileSize * c).ToPoint(), (TileSize * (c + new int2(1, 0))).ToPoint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
|
||||||
{
|
|
||||||
var pos = new int2( e.X / TileSize, e.Y / TileSize );
|
|
||||||
|
|
||||||
if (InputMode == null)
|
|
||||||
{
|
|
||||||
if (e.Button == MouseButtons.Left)
|
|
||||||
{
|
|
||||||
CurrentTemplate = Templates.FirstOrDefault(t => t.Cells.ContainsKey(pos));
|
|
||||||
if (CurrentTemplate == null)
|
|
||||||
Templates.Add(CurrentTemplate = new Template { Cells = new Dictionary<int2, bool> { { pos, true } } });
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Right)
|
|
||||||
{
|
|
||||||
Templates.RemoveAll(t => t.Cells.ContainsKey(pos));
|
|
||||||
CurrentTemplate = null;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TerrainTypes[pos.X, pos.Y] = int.Parse(InputMode);
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
|
||||||
{
|
|
||||||
var pos = new int2(e.X / TileSize, e.Y / TileSize);
|
|
||||||
|
|
||||||
if (InputMode == null)
|
|
||||||
{
|
|
||||||
if (e.Button == MouseButtons.Left && CurrentTemplate != null)
|
|
||||||
{
|
|
||||||
if (!CurrentTemplate.Cells.ContainsKey(pos))
|
|
||||||
{
|
|
||||||
CurrentTemplate.Cells[pos] = true;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,10 @@
|
|||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Surface.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Template.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
114
OpenRA.TilesetBuilder/Surface.cs
Normal file
114
OpenRA.TilesetBuilder/Surface.cs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace OpenRA.TilesetBuilder
|
||||||
|
{
|
||||||
|
class Surface : Control
|
||||||
|
{
|
||||||
|
public Bitmap Image;
|
||||||
|
public int[,] TerrainTypes;
|
||||||
|
public List<Template> Templates = new List<Template>();
|
||||||
|
public bool ShowTerrainTypes = true;
|
||||||
|
public string InputMode;
|
||||||
|
public int TileSize;
|
||||||
|
|
||||||
|
Template CurrentTemplate;
|
||||||
|
|
||||||
|
public Surface()
|
||||||
|
{
|
||||||
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||||
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
|
SetStyle(ControlStyles.ResizeRedraw, true);
|
||||||
|
UpdateStyles();
|
||||||
|
}
|
||||||
|
|
||||||
|
Brush currentBrush = new SolidBrush(Color.FromArgb(60, Color.White));
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
if (Image == null || TerrainTypes == null || Templates == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* draw the background */
|
||||||
|
e.Graphics.DrawImageUnscaled(Image, 0, 0);
|
||||||
|
|
||||||
|
/* draw terrain type overlays */
|
||||||
|
if (ShowTerrainTypes)
|
||||||
|
for (var i = 0; i <= TerrainTypes.GetUpperBound(0); i++)
|
||||||
|
for (var j = 0; j <= TerrainTypes.GetUpperBound(1); j++)
|
||||||
|
if (TerrainTypes[i, j] != 0)
|
||||||
|
{
|
||||||
|
e.Graphics.FillRectangle(Brushes.Black, TileSize * i + 10, TileSize * j + 10, 10, 10);
|
||||||
|
e.Graphics.DrawString(TerrainTypes[i, j].ToString(),
|
||||||
|
Font, Brushes.LimeGreen, TileSize * i + 10, TileSize * j + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw template outlines */
|
||||||
|
foreach (var t in Templates)
|
||||||
|
{
|
||||||
|
foreach (var c in t.Cells.Keys)
|
||||||
|
{
|
||||||
|
if (CurrentTemplate == t)
|
||||||
|
e.Graphics.FillRectangle(currentBrush, TileSize * c.X, TileSize * c.Y, TileSize, TileSize);
|
||||||
|
|
||||||
|
if (!t.Cells.ContainsKey(c + new int2(-1, 0)))
|
||||||
|
e.Graphics.DrawLine(Pens.Red, (TileSize * c).ToPoint(), (TileSize * (c + new int2(0, 1))).ToPoint());
|
||||||
|
if (!t.Cells.ContainsKey(c + new int2(+1, 0)))
|
||||||
|
e.Graphics.DrawLine(Pens.Red, (TileSize * (c + new int2(1, 0))).ToPoint(), (TileSize * (c + new int2(1, 1))).ToPoint());
|
||||||
|
if (!t.Cells.ContainsKey(c + new int2(0, +1)))
|
||||||
|
e.Graphics.DrawLine(Pens.Red, (TileSize * (c + new int2(0, 1))).ToPoint(), (TileSize * (c + new int2(1, 1))).ToPoint());
|
||||||
|
if (!t.Cells.ContainsKey(c + new int2(0, -1)))
|
||||||
|
e.Graphics.DrawLine(Pens.Red, (TileSize * c).ToPoint(), (TileSize * (c + new int2(1, 0))).ToPoint());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
var pos = new int2(e.X / TileSize, e.Y / TileSize);
|
||||||
|
|
||||||
|
if (InputMode == null)
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButtons.Left)
|
||||||
|
{
|
||||||
|
CurrentTemplate = Templates.FirstOrDefault(t => t.Cells.ContainsKey(pos));
|
||||||
|
if (CurrentTemplate == null)
|
||||||
|
Templates.Add(CurrentTemplate = new Template { Cells = new Dictionary<int2, bool> { { pos, true } } });
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Button == MouseButtons.Right)
|
||||||
|
{
|
||||||
|
Templates.RemoveAll(t => t.Cells.ContainsKey(pos));
|
||||||
|
CurrentTemplate = null;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TerrainTypes[pos.X, pos.Y] = int.Parse(InputMode);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
var pos = new int2(e.X / TileSize, e.Y / TileSize);
|
||||||
|
|
||||||
|
if (InputMode == null)
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButtons.Left && CurrentTemplate != null)
|
||||||
|
{
|
||||||
|
if (!CurrentTemplate.Cells.ContainsKey(pos))
|
||||||
|
{
|
||||||
|
CurrentTemplate.Cells[pos] = true;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
OpenRA.TilesetBuilder/Template.cs
Normal file
19
OpenRA.TilesetBuilder/Template.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.TilesetBuilder
|
||||||
|
{
|
||||||
|
class Template
|
||||||
|
{
|
||||||
|
public Dictionary<int2, bool> Cells = new Dictionary<int2, bool>();
|
||||||
|
|
||||||
|
public int Left { get { return Cells.Keys.Min(c => c.X); } }
|
||||||
|
public int Top { get { return Cells.Keys.Min(c => c.Y); } }
|
||||||
|
|
||||||
|
public int Right { get { return Cells.Keys.Max(c => c.X) + 1; } }
|
||||||
|
public int Bottom { get { return Cells.Keys.Max(c => c.Y) + 1; } }
|
||||||
|
|
||||||
|
public int Width { get { return Right - Left; } }
|
||||||
|
public int Height { get { return Bottom - Top; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user