Added TexturePackInfoEditor

This commit is contained in:
MayNL
2026-07-04 22:36:23 -04:00
parent 03fce7304f
commit be0630fa90
7 changed files with 3143 additions and 2 deletions
+29 -2
View File
@@ -163,7 +163,7 @@ namespace PckStudio.Controls
[PckAssetType.TextureFile] = HandleTextureFile,
[PckAssetType.UIDataFile] = _ => throw new NotSupportedException("unused in-game"),
[PckAssetType.InfoFile] = null,
[PckAssetType.TexturePackInfoFile] = null,
[PckAssetType.TexturePackInfoFile] = HandleTexturePackInfoFile,
[PckAssetType.LocalisationFile] = HandleLocalisationFile,
[PckAssetType.GameRulesFile] = HandleGameRuleFile,
[PckAssetType.AudioFile] = HandleAudioFile,
@@ -473,6 +473,33 @@ namespace PckStudio.Controls
}
}
private void HandleTexturePackInfoFile(PckAsset asset)
{
try
{
OMI.ByteOrder endianness = BigEndianCheckBox.Checked ? OMI.ByteOrder.BigEndian : OMI.ByteOrder.LittleEndian;
ISaveContext<PckFile> saveContext = new DelegatedSaveContext<PckFile>(Settings.Default.AutoSaveChanges, (texturePackInfoFile) =>
{
asset.SetData(new PckFileWriter(texturePackInfoFile, endianness));
});
PckFile texturePackInfoFile = asset.GetData(new PckFileReader(endianness));
using TexturePackInfoEditor texturePackInfoEditor = new TexturePackInfoEditor(texturePackInfoFile, saveContext);
_wasModified = texturePackInfoEditor.ShowDialog(this) == DialogResult.OK;
}
catch (OverflowException)
{
MessageBox.Show(this, $"Failed to open {asset.Filename}\n" +
"Try converting the file by using the \"File Functions->Set PCK Endianness\" tool and try again.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to open {asset.Filename}\n" + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void HandleAudioFile(PckAsset asset)
{
try
@@ -490,7 +517,7 @@ namespace PckStudio.Controls
catch (OverflowException)
{
MessageBox.Show(this, $"Failed to open {asset.Filename}\n" +
"Try converting the file by using the \"Misc. Functions/Set PCK Endianness\" tool and try again.",
"Try converting the file by using the \"File Functions->Set PCK Endianness\" tool and try again.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
+147
View File
@@ -0,0 +1,147 @@
namespace PckStudio.Forms.Editor
{
partial class TexturePackInfoEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TexturePackInfoEditor));
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.iconPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox();
this.imageContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.comparisonPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).BeginInit();
this.imageContextMenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.comparisonPictureBox)).BeginInit();
this.SuspendLayout();
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.saveToolStripMenuItem1});
this.fileToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
resources.ApplyResources(this.fileToolStripMenuItem, "fileToolStripMenuItem");
//
// saveToolStripMenuItem1
//
resources.ApplyResources(this.saveToolStripMenuItem1, "saveToolStripMenuItem1");
this.saveToolStripMenuItem1.Name = "saveToolStripMenuItem1";
this.saveToolStripMenuItem1.Click += new System.EventHandler(this.saveToolStripMenuItem1_Click);
//
// menuStrip
//
resources.ApplyResources(this.menuStrip, "menuStrip");
this.menuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.menuStrip.Name = "menuStrip";
//
// iconPictureBox
//
this.iconPictureBox.BackgroundImage = global::PckStudio.Properties.Resources.pack;
resources.ApplyResources(this.iconPictureBox, "iconPictureBox");
this.iconPictureBox.BackgroundInterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.iconPictureBox.ContextMenuStrip = this.imageContextMenuStrip;
this.iconPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.iconPictureBox.Name = "iconPictureBox";
this.iconPictureBox.TabStop = false;
this.iconPictureBox.Tag = "icon";
this.iconPictureBox.Click += new System.EventHandler(this.pictureBox_Click);
//
// imageContextMenuStrip
//
this.imageContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.importToolStripMenuItem,
this.exportToolStripMenuItem});
this.imageContextMenuStrip.Name = "imageContextMenuStrip";
resources.ApplyResources(this.imageContextMenuStrip, "imageContextMenuStrip");
//
// importToolStripMenuItem
//
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
resources.ApplyResources(this.importToolStripMenuItem, "importToolStripMenuItem");
this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click);
//
// exportToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
resources.ApplyResources(this.exportToolStripMenuItem, "exportToolStripMenuItem");
this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click);
//
// comparisonPictureBox
//
this.comparisonPictureBox.BackgroundImage = global::PckStudio.Properties.Resources.Comparison;
resources.ApplyResources(this.comparisonPictureBox, "comparisonPictureBox");
this.comparisonPictureBox.BackgroundInterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.comparisonPictureBox.ContextMenuStrip = this.imageContextMenuStrip;
this.comparisonPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.comparisonPictureBox.Name = "comparisonPictureBox";
this.comparisonPictureBox.TabStop = false;
this.comparisonPictureBox.Tag = "comparison";
this.comparisonPictureBox.Click += new System.EventHandler(this.pictureBox_Click);
//
// TexturePackInfoEditor
//
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.comparisonPictureBox);
this.Controls.Add(this.iconPictureBox);
this.Controls.Add(this.menuStrip);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TexturePackInfoEditor";
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TexturePackInfoEditor_FormClosing);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).EndInit();
this.imageContextMenuStrip.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.comparisonPictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem1;
private System.Windows.Forms.MenuStrip menuStrip;
private ToolboxItems.InterpolationPictureBox iconPictureBox;
private ToolboxItems.InterpolationPictureBox comparisonPictureBox;
private System.Windows.Forms.ContextMenuStrip imageContextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem;
}
}
@@ -0,0 +1,137 @@
using OMI.Formats.Pck;
using PckStudio.Controls;
using PckStudio.Core.Extensions;
using PckStudio.Interfaces;
using PckStudio.Properties;
using PckStudio.ToolboxItems;
using System;
using System.Drawing;
using System.IO;
using System.Security.Cryptography;
using System.Windows.Forms;
namespace PckStudio.Forms.Editor
{
public partial class TexturePackInfoEditor : EditorForm<PckFile>
{
PckAsset iconAsset = null;
PckAsset comparisonAsset = null;
ImageConverter converter = new ImageConverter();
readonly string iconString = "icon.png";
readonly string comparisonString = "comparison.png";
public TexturePackInfoEditor(PckFile texturePackInfoFile, ISaveContext<PckFile> saveContext)
: base(texturePackInfoFile, saveContext)
{
texturePackInfoFile.TryGetAsset(iconString, PckAssetType.TextureFile, out iconAsset);
if (iconAsset == null)
resetIconImage();
texturePackInfoFile.TryGetAsset(comparisonString, PckAssetType.TextureFile, out comparisonAsset);
if (comparisonAsset == null)
resetComparisonImage();
InitializeComponent();
iconPictureBox.BackgroundImage = iconAsset.GetTexture();
comparisonPictureBox.BackgroundImage = comparisonAsset.GetTexture();
saveToolStripMenuItem1.Visible = !saveContext.AutoSave;
}
private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
{
Save();
DialogResult = DialogResult.OK;
}
private void resetIconImage()
{
iconAsset = new PckAsset(iconString, PckAssetType.TextureFile);
iconAsset.SetData((byte[])converter.ConvertTo(Resources.pack, typeof(byte[])));
}
private void resetComparisonImage()
{
comparisonAsset = new PckAsset(iconString, PckAssetType.TextureFile);
comparisonAsset.SetData((byte[])converter.ConvertTo(Resources.Comparison, typeof(byte[])));
}
private void TexturePackInfoEditor_FormClosing(object sender, FormClosingEventArgs e)
{
if (Settings.Default.AutoSaveChanges)
{
saveToolStripMenuItem1_Click(sender, EventArgs.Empty);
}
}
private void setImage(string filepath, in PckAsset asset, in InterpolationPictureBox pictureBox)
{
try
{
asset.SetData(File.ReadAllBytes(filepath));
pictureBox.BackgroundImage = asset.GetTexture();
}
catch (Exception ex)
{
bool icon = pictureBox == iconPictureBox;
pictureBox.Image = icon ? Resources.pack : Resources.Comparison;
if (icon)
resetIconImage();
else
resetComparisonImage();
MessageBox.Show(this, "Not a valid .PNG image or invalid image data found");
}
}
private void importImage(bool icon)
{
using var ofd = new OpenFileDialog();
string fileExt = ".png";
ofd.Filter = $"PNG Images (*{fileExt})|*{fileExt}";
if (ofd.ShowDialog(this) == DialogResult.OK)
{
if (icon)
setImage(ofd.FileName, iconAsset, iconPictureBox);
else
setImage(ofd.FileName, comparisonAsset, comparisonPictureBox);
}
}
private void importToolStripMenuItem_Click(object sender, EventArgs e)
{
bool icon = imageContextMenuStrip.SourceControl == iconPictureBox;
importImage(icon);
}
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
bool icon = imageContextMenuStrip.SourceControl == iconPictureBox;
string filename = icon ? iconString : comparisonString;
string fileExt = ".png";
using SaveFileDialog exFile = new SaveFileDialog();
exFile.FileName = filename;
exFile.Filter = $"PNG Images (*{fileExt})|*{fileExt}";
if (exFile.ShowDialog(this) != DialogResult.OK ||
// Makes sure chosen directory isn't null or whitespace AKA makes sure its usable
string.IsNullOrWhiteSpace(Path.GetDirectoryName(exFile.FileName)))
{
MessageBox.Show(this, "The chosen directory is invalid. Please choose a different one and try again.", "Node not extracted");
return;
}
File.WriteAllBytes(exFile.FileName, icon ? iconAsset.Data : comparisonAsset.Data);
}
private void pictureBox_Click(object sender, EventArgs e)
{
bool icon = sender == iconPictureBox;
importImage(icon);
}
}
}
File diff suppressed because it is too large Load Diff
+10
View File
@@ -183,6 +183,12 @@
<Compile Include="Forms\ContributorsForm.Designer.cs">
<DependentUpon>ContributorsForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editor\TexturePackInfoEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Editor\TexturePackInfoEditor.Designer.cs">
<DependentUpon>TexturePackInfoEditor.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editor\ModelEditor.cs">
<SubType>Form</SubType>
</Compile>
@@ -432,6 +438,10 @@
<EmbeddedResource Include="Forms\ContributorsForm.resx">
<DependentUpon>ContributorsForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editor\TexturePackInfoEditor.resx">
<DependentUpon>TexturePackInfoEditor.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editor\ModelEditor.resx">
<DependentUpon>ModelEditor.cs</DependentUpon>
</EmbeddedResource>
+10
View File
@@ -252,6 +252,16 @@ namespace PckStudio.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
public static System.Drawing.Bitmap Comparison {
get {
object obj = ResourceManager.GetObject("Comparison", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
+3
View File
@@ -442,4 +442,7 @@
<data name="leggings" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\skin_editor\leggings.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Comparison" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Comparison.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>