From d11ded68c20fce9937bbb08c377348aa059c7909 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:12:29 +0100 Subject: [PATCH] CustomSkinEditor - Fixed Box Uv highlighting --- .../Forms/Skins-And-Textures/AddNewSkin.cs | 2 +- ...signer.cs => CustomSkinEditor.Designer.cs} | 5 +- ...stomModelEditor.cs => CustomSkinEditor.cs} | 48 +++++++++++-------- ...ditor.ja.resx => CustomSkinEditor.ja.resx} | 0 ...ModelEditor.resx => CustomSkinEditor.resx} | 0 PCK-Studio/MainForm.cs | 2 +- PCK-Studio/PckStudio.csproj | 14 +++--- Vendor/OMI-Lib | 2 +- 8 files changed, 39 insertions(+), 34 deletions(-) rename PCK-Studio/Forms/Skins-And-Textures/{CustomModelEditor.Designer.cs => CustomSkinEditor.Designer.cs} (99%) rename PCK-Studio/Forms/Skins-And-Textures/{CustomModelEditor.cs => CustomSkinEditor.cs} (92%) rename PCK-Studio/Forms/Skins-And-Textures/{CustomModelEditor.ja.resx => CustomSkinEditor.ja.resx} (100%) rename PCK-Studio/Forms/Skins-And-Textures/{CustomModelEditor.resx => CustomSkinEditor.resx} (100%) diff --git a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs index d21349fe..36ab7f02 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs @@ -280,7 +280,7 @@ namespace PckStudio.Popups skin.SetData(Resources.classic_template, ImageFormat.Png); - using CustomModelEditor generate = new CustomModelEditor(skin); + using CustomSkinEditor generate = new CustomSkinEditor(skin); if (generate.ShowDialog() == DialogResult.OK) { diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.Designer.cs b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs similarity index 99% rename from PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.Designer.cs rename to PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs index 8ea61e9c..d0463cac 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.Designer.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs @@ -1,6 +1,6 @@ namespace PckStudio.Forms { - partial class CustomModelEditor + partial class CustomSkinEditor { /// /// Required designer variable. @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); System.Windows.Forms.Label label5; - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CustomModelEditor)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CustomSkinEditor)); System.Windows.Forms.Label label3; System.Windows.Forms.Label label7; System.Windows.Forms.Label labelTextureMappingPreview; @@ -384,7 +384,6 @@ this.Controls.Add(label3); this.Controls.Add(label5); this.Controls.Add(this.uvPictureBox); - this.MaximizeBox = false; this.Name = "CustomModelEditor"; this.Style = MetroFramework.MetroColorStyle.Silver; this.Theme = MetroFramework.MetroThemeStyle.Dark; diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.cs b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs similarity index 92% rename from PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.cs rename to PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs index eb04b3e0..d4a3934e 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs @@ -1,14 +1,11 @@ using System; -using System.Text; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Linq; -using System.Windows.Forms; -using System.Collections; using System.IO; -using System.Text.RegularExpressions; +using System.Text; +using System.Drawing; +using System.Windows.Forms; +using System.Drawing.Imaging; +using System.Drawing.Drawing2D; +using System.Collections.Generic; using Newtonsoft.Json; using MetroFramework.Forms; @@ -21,7 +18,7 @@ using PckStudio.Forms.Editor; namespace PckStudio.Forms { - public partial class CustomModelEditor : MetroForm + public partial class CustomSkinEditor : MetroForm { private Image _previewImage; public Image PreviewImage => _previewImage; @@ -36,7 +33,7 @@ namespace PckStudio.Forms List modelOffsets = new List(); - public CustomModelEditor(PckFileData file) + public CustomSkinEditor(PckFileData file) { InitializeComponent(); @@ -55,6 +52,7 @@ namespace PckStudio.Forms var boxProperties = properties.GetProperties("BOX"); Array.ForEach(boxProperties, kv => renderer3D1.ModelData.Add(SkinBOX.FromString(kv.Value))); + modelPartListBox.DataSource = renderer3D1.ModelData; modelPartListBox.DisplayMember = "Type"; @@ -118,15 +116,10 @@ namespace PckStudio.Forms { using (var img = Image.FromFile(openFileDialog.FileName)) { - if ((img.Width == img.Height || img.Height == img.Width / 2)) + if (img.Width == img.Height || img.Height == img.Width / 2) { generateTextureCheckBox.Checked = false; - using (Graphics graphics = Graphics.FromImage(uvPictureBox.BackgroundImage)) - { - graphics.ApplyConfig(_graphicsConfig); - graphics.DrawImage(img, 0, 0, img.Width, img.Height); - } - uvPictureBox.Invalidate(); + renderer3D1.Texture = img; } else { @@ -320,8 +313,14 @@ namespace PckStudio.Forms private void renderer3D1_TextureChanging(object sender, Rendering.TextureChangingEventArgs e) { - // TODO: add validation for 64x64 and 64x32 - uvPictureBox.BackgroundImage = e.NewTexture; + var img = e.NewTexture; + if (img.Width != img.Height && img.Height != img.Width / 2) + { + e.Cancel = true; + MessageBox.Show("Invalid image dimensions.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + uvPictureBox.BackgroundImage = img; } private void listBox1_DoubleClick(object sender, EventArgs e) @@ -345,7 +344,14 @@ namespace PckStudio.Forms uvPictureBox.Image = new Bitmap(uvPictureBox.BackgroundImage.Width * scale, uvPictureBox.BackgroundImage.Height * scale); using (Graphics g = Graphics.FromImage(uvPictureBox.Image)) { - g.DrawPath(new Pen(Color.HotPink, 1f), box.GetUVGraphicsPath(new System.Numerics.Vector2(uvPictureBox.Image.Width / uvPictureBox.BackgroundImage.Width, uvPictureBox.Image.Height / uvPictureBox.BackgroundImage.Height))); + float penWidth = renderer3D1.UvTranslation.X * uvPictureBox.BackgroundImage.Width + renderer3D1.UvTranslation.Y * uvPictureBox.BackgroundImage.Height / 2f; + GraphicsPath graphicsPath = box.GetUVGraphicsPath( + new System.Numerics.Vector2( + scale * renderer3D1.UvTranslation.X * uvPictureBox.BackgroundImage.Width, + scale * renderer3D1.UvTranslation.Y * uvPictureBox.BackgroundImage.Height + ) + ); + g.DrawPath(new Pen(Color.HotPink, penWidth), graphicsPath); } uvPictureBox.Invalidate(); } diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.ja.resx b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.ja.resx similarity index 100% rename from PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.ja.resx rename to PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.ja.resx diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.resx b/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.resx similarity index 100% rename from PCK-Studio/Forms/Skins-And-Textures/CustomModelEditor.resx rename to PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.resx diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 582a50c9..70cb7c8f 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -434,7 +434,7 @@ namespace PckStudio { if (file.Properties.HasProperty("BOX")) { - using CustomModelEditor generate = new CustomModelEditor(file); + using CustomSkinEditor generate = new CustomSkinEditor(file); if (generate.ShowDialog() == DialogResult.OK) { entryDataTextBox.Text = entryTypeTextBox.Text = string.Empty; diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 358ea7a0..3380a05c 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -400,11 +400,11 @@ MainForm.cs - + Form - - CustomModelEditor.cs + + CustomSkinEditor.cs Form @@ -575,11 +575,11 @@ MainForm.cs Designer - - CustomModelEditor.cs + + CustomSkinEditor.cs - - CustomModelEditor.cs + + CustomSkinEditor.cs Designer diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index 3209ecca..c33a6ada 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit 3209ecca8568933fac8c20c20a9952ee3dc1b526 +Subproject commit c33a6adafe24d7dbbbc2503e5470d348b6bdb1c4