Add some usability features to the TilesetBuilder
- title bar shows tile position (x, y and tile nr (from left top)) - make 'overlays' button a toggle button and properly sync state with tileset surface - add export option for 'Template CellID <-> tile number' mapping - overlay pen color is now white (todo: make configurable)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
@@ -15,8 +16,12 @@ namespace OpenRA.TilesetBuilder
|
||||
public string InputMode;
|
||||
public Bitmap[] icon;
|
||||
public int TileSize;
|
||||
public int TilesPerRow;
|
||||
//private System.ComponentModel.IContainer components;
|
||||
|
||||
|
||||
public event Action<int, int, int> UpdateMouseTilePosition = (x, y, t) => { };
|
||||
|
||||
Template CurrentTemplate;
|
||||
|
||||
public bool ShowTerrainTypes
|
||||
@@ -67,19 +72,21 @@ namespace OpenRA.TilesetBuilder
|
||||
/* draw template outlines */
|
||||
foreach (var t in Templates)
|
||||
{
|
||||
System.Drawing.Pen pen = Pens.White;
|
||||
|
||||
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());
|
||||
e.Graphics.DrawLine(pen, (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());
|
||||
e.Graphics.DrawLine(pen, (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());
|
||||
e.Graphics.DrawLine(pen, (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());
|
||||
e.Graphics.DrawLine(pen, (TileSize * c).ToPoint(), (TileSize * (c + new int2(1, 0))).ToPoint());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +135,8 @@ namespace OpenRA.TilesetBuilder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpdateMouseTilePosition(pos.X, pos.Y, (pos.Y * TilesPerRow) + pos.X);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
|
||||
23
OpenRA.TilesetBuilder/frmBuilder.Designer.cs
generated
23
OpenRA.TilesetBuilder/frmBuilder.Designer.cs
generated
@@ -52,6 +52,7 @@
|
||||
this.toolStripButton15 = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButton14 = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButton16 = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
|
||||
this.surface1 = new OpenRA.TilesetBuilder.Surface();
|
||||
@@ -227,6 +228,7 @@
|
||||
this.toolStripButton1.Name = "toolStripButton1";
|
||||
this.toolStripButton1.Size = new System.Drawing.Size(118, 20);
|
||||
this.toolStripButton1.Text = "Template Tool";
|
||||
this.toolStripButton1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.toolStripButton1.Click += new System.EventHandler(this.TerrainTypeSelectorClicked);
|
||||
//
|
||||
// toolStrip1
|
||||
@@ -236,6 +238,7 @@
|
||||
this.toolStripButton15,
|
||||
this.toolStripButton2,
|
||||
this.toolStripButton14,
|
||||
this.toolStripButton16,
|
||||
this.toolStripSeparator1,
|
||||
this.toolStripButton3});
|
||||
this.toolStrip1.Location = new System.Drawing.Point(3, 0);
|
||||
@@ -250,6 +253,7 @@
|
||||
this.toolStripButton15.Name = "toolStripButton15";
|
||||
this.toolStripButton15.Size = new System.Drawing.Size(48, 22);
|
||||
this.toolStripButton15.Text = "New";
|
||||
this.toolStripButton15.ToolTipText = "Create new tileset";
|
||||
this.toolStripButton15.Click += new System.EventHandler(this.toolStripButton15_Click);
|
||||
//
|
||||
// toolStripButton2
|
||||
@@ -259,6 +263,7 @@
|
||||
this.toolStripButton2.Name = "toolStripButton2";
|
||||
this.toolStripButton2.Size = new System.Drawing.Size(51, 22);
|
||||
this.toolStripButton2.Text = "Save";
|
||||
this.toolStripButton2.ToolTipText = "Save Template definitions to file (*.tsx)";
|
||||
this.toolStripButton2.Click += new System.EventHandler(this.SaveClicked);
|
||||
//
|
||||
// toolStripButton14
|
||||
@@ -268,8 +273,19 @@
|
||||
this.toolStripButton14.Name = "toolStripButton14";
|
||||
this.toolStripButton14.Size = new System.Drawing.Size(59, 22);
|
||||
this.toolStripButton14.Text = "Export";
|
||||
this.toolStripButton14.ToolTipText = "Export defined Templates to files";
|
||||
this.toolStripButton14.Click += new System.EventHandler(this.ExportClicked);
|
||||
//
|
||||
// toolStripButton16
|
||||
//
|
||||
this.toolStripButton16.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton14.Image")));
|
||||
this.toolStripButton16.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.toolStripButton16.Name = "toolStripButton16";
|
||||
this.toolStripButton16.Size = new System.Drawing.Size(65, 22);
|
||||
this.toolStripButton16.Text = "Dump";
|
||||
this.toolStripButton16.ToolTipText = "Dump Template ID to tile number mapping to console";
|
||||
this.toolStripButton16.Click += new System.EventHandler(this.Export2Clicked);
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
@@ -282,6 +298,8 @@
|
||||
this.toolStripButton3.Name = "toolStripButton3";
|
||||
this.toolStripButton3.Size = new System.Drawing.Size(70, 22);
|
||||
this.toolStripButton3.Text = "Overlays";
|
||||
this.toolStripButton3.ToolTipText = "Show/hide terrain type overlays";
|
||||
this.toolStripButton3.CheckOnClick = true;
|
||||
this.toolStripButton3.Click += new System.EventHandler(this.ShowOverlaysClicked);
|
||||
//
|
||||
// surface1
|
||||
@@ -290,7 +308,7 @@
|
||||
this.surface1.ImagesList = this.imageList;
|
||||
this.surface1.Location = new System.Drawing.Point(0, 0);
|
||||
this.surface1.Name = "surface1";
|
||||
this.surface1.ShowTerrainTypes = true;
|
||||
this.surface1.ShowTerrainTypes = this.toolStripButton3.Checked;
|
||||
this.surface1.Size = new System.Drawing.Size(653, 454);
|
||||
this.surface1.TabIndex = 2;
|
||||
this.surface1.Text = "surface1";
|
||||
@@ -325,13 +343,14 @@
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton3;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton14;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton15;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton16;
|
||||
public System.Windows.Forms.ImageList imageList;
|
||||
private System.Windows.Forms.ToolStrip tsTerrainTypes;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private Surface surface1;
|
||||
private System.Windows.Forms.ToolStripLabel toolStripLabel2;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton15;
|
||||
private System.Windows.Forms.ToolStripButton toolStripButton1;
|
||||
private System.Windows.Forms.ToolStripLabel toolStripLabel3;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace OpenRA.TilesetBuilder
|
||||
}
|
||||
|
||||
surface1.Image = (Bitmap)rbitmap;
|
||||
surface1.TilesPerRow = surface1.Image.Size.Width / surface1.TileSize;
|
||||
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.Templates = new List<Template>();
|
||||
@@ -86,6 +87,13 @@ namespace OpenRA.TilesetBuilder
|
||||
int i = 0;
|
||||
surface1.icon = new Bitmap[DefTerrain.Keys.Count];
|
||||
TerrainType = new TerrainTypeInfo[DefTerrain.Keys.Count];
|
||||
|
||||
var title = this.Text;
|
||||
surface1.UpdateMouseTilePosition += (x, y, tileNr) =>
|
||||
{
|
||||
this.Text = "{0} - {1} ({2,3}, {3,3}) tileNr: {4,3}".F(title, txtTilesetName.Text, x, y, tileNr);
|
||||
};
|
||||
|
||||
surface1.Enabled = false;
|
||||
foreach (var deftype in DefTerrain)
|
||||
{
|
||||
@@ -107,6 +115,7 @@ namespace OpenRA.TilesetBuilder
|
||||
TerrainTypeButton.ToolTipText = deftype.Key;
|
||||
TerrainTypeButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
|
||||
TerrainTypeButton.Tag = i.ToString();
|
||||
TerrainTypeButton.ImageAlign = ContentAlignment.MiddleLeft;
|
||||
i++;
|
||||
tsTerrainTypes.Items.Add(TerrainTypeButton);
|
||||
}
|
||||
@@ -117,6 +126,7 @@ namespace OpenRA.TilesetBuilder
|
||||
this.size = size;
|
||||
surface1.TileSize = size;
|
||||
surface1.Image = (Bitmap)Image.FromFile(src);
|
||||
surface1.TilesPerRow = surface1.Image.Size.Width / surface1.TileSize;
|
||||
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.Templates = new List<Template>();
|
||||
@@ -219,16 +229,8 @@ namespace OpenRA.TilesetBuilder
|
||||
void SaveClicked(object sender, EventArgs e) { Save(); }
|
||||
void ShowOverlaysClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (surface1.ShowTerrainTypes == false)
|
||||
{
|
||||
surface1.ShowTerrainTypes = true;
|
||||
this.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
surface1.ShowTerrainTypes = false;
|
||||
this.Refresh();
|
||||
}
|
||||
surface1.ShowTerrainTypes = (sender as ToolStripButton).Checked;
|
||||
surface1.Invalidate();
|
||||
}
|
||||
|
||||
void ExportClicked(object sender, EventArgs e)
|
||||
@@ -236,6 +238,11 @@ namespace OpenRA.TilesetBuilder
|
||||
Export("Tilesets");
|
||||
}
|
||||
|
||||
void Export2Clicked(object sender, EventArgs e)
|
||||
{
|
||||
ExportTemplateToTileNumberMapping();
|
||||
}
|
||||
|
||||
string ExportPalette(List<Color> p, string file)
|
||||
{
|
||||
while (p.Count < 256) p.Add(Color.Black); // pad the palette out with extra blacks
|
||||
@@ -401,7 +408,8 @@ namespace OpenRA.TilesetBuilder
|
||||
{
|
||||
string ttype = "Clear";
|
||||
ttype = TerrainType[surface1.TerrainTypes[t.Key.X, t.Key.Y]].Type;
|
||||
template.Tiles.Add((byte)((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top)), ttype);
|
||||
var idx = ((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top));
|
||||
template.Tiles.Add((byte)idx, ttype);
|
||||
}
|
||||
|
||||
tileset.Templates.Add(cur, template);
|
||||
@@ -419,6 +427,36 @@ namespace OpenRA.TilesetBuilder
|
||||
Console.WriteLine("Finished export");
|
||||
}
|
||||
|
||||
public void ExportTemplateToTileNumberMapping()
|
||||
{
|
||||
Console.WriteLine("# start");
|
||||
Console.WriteLine("# TemplateID CellID tilenr TemplateW TemplateH XinTilesPNG YinTilesPNG");
|
||||
|
||||
ushort cur = 0;
|
||||
foreach (var tp in surface1.Templates)
|
||||
{
|
||||
foreach (var t in tp.Cells)
|
||||
{
|
||||
var idx = ((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top));
|
||||
|
||||
// TemplateID CellID tilenr TemplateW TemplateH XinTilesPNG YinTilesPNG
|
||||
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}",
|
||||
cur,
|
||||
idx,
|
||||
((t.Key.Y * surface1.TilesPerRow) + t.Key.X).ToString(),
|
||||
tp.Width,
|
||||
tp.Height,
|
||||
t.Key.X,
|
||||
t.Key.Y
|
||||
);
|
||||
}
|
||||
|
||||
cur++;
|
||||
}
|
||||
|
||||
Console.WriteLine("# end\n");
|
||||
}
|
||||
|
||||
private void toolStripContainer1_TopToolStripPanel_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -452,6 +490,5 @@ namespace OpenRA.TilesetBuilder
|
||||
{
|
||||
CreateNewTileset();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user