Added highlight for selected tiles in Atlas Editor

This commit is contained in:
MattN-L
2024-03-13 18:48:06 -04:00
parent ceceebfe4c
commit 42d6d44e2c
2 changed files with 34 additions and 18 deletions

View File

@@ -37,7 +37,6 @@
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.applyColorMaskToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.playAnimationsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.originalPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox();
this.selectTilePictureBox = new PckStudio.ToolboxItems.AnimationPictureBox();
@@ -72,8 +71,7 @@
this.menuStrip1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.viewToolStripMenuItem,
this.sToolStripMenuItem});
this.viewToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(20, 60);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(590, 24);
@@ -94,14 +92,14 @@
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(131, 22);
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// extractTileToolStripMenuItem
//
this.extractTileToolStripMenuItem.Name = "extractTileToolStripMenuItem";
this.extractTileToolStripMenuItem.Size = new System.Drawing.Size(131, 22);
this.extractTileToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.extractTileToolStripMenuItem.Text = "Extract Tile";
this.extractTileToolStripMenuItem.Click += new System.EventHandler(this.extractTileToolStripMenuItem_Click);
//
@@ -121,7 +119,7 @@
this.applyColorMaskToolStripMenuItem.CheckOnClick = true;
this.applyColorMaskToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.applyColorMaskToolStripMenuItem.Name = "applyColorMaskToolStripMenuItem";
this.applyColorMaskToolStripMenuItem.Size = new System.Drawing.Size(168, 22);
this.applyColorMaskToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.applyColorMaskToolStripMenuItem.Text = "Apply Color Mask";
this.applyColorMaskToolStripMenuItem.CheckedChanged += new System.EventHandler(this.applyColorMaskToolStripMenuItem_CheckedChanged);
//
@@ -131,16 +129,10 @@
this.playAnimationsToolStripMenuItem.CheckOnClick = true;
this.playAnimationsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.playAnimationsToolStripMenuItem.Name = "playAnimationsToolStripMenuItem";
this.playAnimationsToolStripMenuItem.Size = new System.Drawing.Size(168, 22);
this.playAnimationsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.playAnimationsToolStripMenuItem.Text = "Play Animations";
this.playAnimationsToolStripMenuItem.CheckedChanged += new System.EventHandler(this.playAnimationsToolStripMenuItem_CheckedChanged);
//
// sToolStripMenuItem
//
this.sToolStripMenuItem.Name = "sToolStripMenuItem";
this.sToolStripMenuItem.Size = new System.Drawing.Size(24, 20);
this.sToolStripMenuItem.Text = "s";
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.AutoSize = true;
@@ -340,6 +332,5 @@
private MetroFramework.Controls.MetroLabel variantLabel;
private MetroFramework.Controls.MetroButton clearColorButton;
private MetroFramework.Controls.MetroButton setColorButton;
private System.Windows.Forms.ToolStripMenuItem sToolStripMenuItem;
}
}

View File

@@ -37,13 +37,14 @@ namespace PckStudio.Forms.Editor
{
internal partial class TextureAtlasEditor : MetroForm
{
private Image _workingTexture;
public Image FinalTexture
{
get
{
if (DialogResult != DialogResult.OK)
return null;
return (Image)originalPictureBox.Image.Clone();
return _workingTexture;
}
}
@@ -96,6 +97,9 @@ namespace PckStudio.Forms.Editor
InitializeComponent();
AcquireColorTable(pckFile);
_workingTexture = atlas;
_areaSize = areaSize;
_pckFile = pckFile;
_rowCount = atlas.Width / areaSize.Width;
@@ -109,7 +113,9 @@ namespace PckStudio.Forms.Editor
"moon_phases" => (Tiles.MoonPhaseTileInfos, "moon_phases"),
_ => (null, null),
};
originalPictureBox.Image = atlas;
originalPictureBox.Image = (Image)((Bitmap)atlas).Clone(new Rectangle(new Point(0, 0), new Size(atlas.Width - 1, atlas.Height - 1)), PixelFormat.Format32bppArgb);
var images = atlas.Split(_areaSize, _imageLayout);
var tiles = images.enumerate().Select(
@@ -154,6 +160,25 @@ namespace PckStudio.Forms.Editor
dataTile = _selectedTile;
var graphicsConfig = new GraphicsConfig()
{
InterpolationMode = selectTilePictureBox.InterpolationMode,
PixelOffsetMode = PixelOffsetMode.HighQuality
};
using (var g = Graphics.FromImage(originalPictureBox.Image))
{
g.ApplyConfig(graphicsConfig);
g.Clear(Color.Transparent);
g.DrawImage(_workingTexture, new Point(0, 0));
g.DrawRectangle(
Pens.White,
new Rectangle(_selectedTile.Area.X, _selectedTile.Area.Y,
_selectedTile.Area.Width,
_selectedTile.Area.Height));
}
originalPictureBox.Invalidate();
if (string.IsNullOrEmpty(dataTile.Tile.InternalName))
{
selectTilePictureBox.Image = dataTile.Texture;
@@ -318,7 +343,7 @@ namespace PckStudio.Forms.Editor
};
if (texture.Size != _areaSize)
texture = texture.Resize(_areaSize, graphicsConfig);
using (var g = Graphics.FromImage(originalPictureBox.Image))
using (var g = Graphics.FromImage(_workingTexture))
{
g.ApplyConfig(graphicsConfig);
g.Fill(_selectedTile.Area, Color.Transparent);
@@ -390,7 +415,7 @@ namespace PckStudio.Forms.Editor
int index = GetSelectedImageIndex(
originalPictureBox.Size,
originalPictureBox.Image.Size,
_workingTexture.Size,
_areaSize,
e.Location,
originalPictureBox.SizeMode,