From ef05ed1dc76b36007acde1b9ab52e68a97fdaf29 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:43:21 +0100 Subject: [PATCH] CustomSkinEditor - Add functionality for setting skin parrt offsets --- .../Forms/Editor/CustomSkinEditor.Designer.cs | 31 +++++++++ PCK-Studio/Forms/Editor/CustomSkinEditor.cs | 67 +++++++++++++++---- PCK-Studio/Forms/Editor/CustomSkinEditor.resx | 24 +++++++ 3 files changed, 109 insertions(+), 13 deletions(-) diff --git a/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs b/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs index ef93b439..4fe0f0a3 100644 --- a/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs @@ -65,8 +65,11 @@ this.skinPartsTabPage = new System.Windows.Forms.TabPage(); this.skinOffsetsTabPage = new System.Windows.Forms.TabPage(); this.offsetListBox = new System.Windows.Forms.ListBox(); + this.offsetTabContextMenu = new MetroFramework.Controls.MetroContextMenu(this.components); + this.addOffsetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.renderer3D1 = new PckStudio.Rendering.SkinRenderer(); this.uvPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); + this.removeOffsetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); label5 = new System.Windows.Forms.Label(); label3 = new System.Windows.Forms.Label(); label7 = new System.Windows.Forms.Label(); @@ -83,6 +86,7 @@ this.metroTabControl1.SuspendLayout(); this.skinPartsTabPage.SuspendLayout(); this.skinOffsetsTabPage.SuspendLayout(); + this.offsetTabContextMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); this.SuspendLayout(); // @@ -376,9 +380,26 @@ // // offsetListBox // + this.offsetListBox.ContextMenuStrip = this.offsetTabContextMenu; resources.ApplyResources(this.offsetListBox, "offsetListBox"); this.offsetListBox.FormattingEnabled = true; this.offsetListBox.Name = "offsetListBox"; + this.offsetListBox.DoubleClick += new System.EventHandler(this.offsetListBox_DoubleClick); + // + // offsetTabContextMenu + // + this.offsetTabContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addOffsetToolStripMenuItem, + this.removeOffsetToolStripMenuItem}); + this.offsetTabContextMenu.Name = "offsetTabContextMenu"; + resources.ApplyResources(this.offsetTabContextMenu, "offsetTabContextMenu"); + this.offsetTabContextMenu.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // addOffsetToolStripMenuItem + // + this.addOffsetToolStripMenuItem.Name = "addOffsetToolStripMenuItem"; + resources.ApplyResources(this.addOffsetToolStripMenuItem, "addOffsetToolStripMenuItem"); + this.addOffsetToolStripMenuItem.Click += new System.EventHandler(this.addOffsetToolStripMenuItem_Click); // // renderer3D1 // @@ -405,6 +426,12 @@ this.uvPictureBox.Name = "uvPictureBox"; this.uvPictureBox.TabStop = false; // + // removeOffsetToolStripMenuItem + // + this.removeOffsetToolStripMenuItem.Name = "removeOffsetToolStripMenuItem"; + resources.ApplyResources(this.removeOffsetToolStripMenuItem, "removeOffsetToolStripMenuItem"); + this.removeOffsetToolStripMenuItem.Click += new System.EventHandler(this.removeOffsetToolStripMenuItem_Click); + // // CustomSkinEditor // resources.ApplyResources(this, "$this"); @@ -453,6 +480,7 @@ this.metroTabControl1.ResumeLayout(false); this.skinPartsTabPage.ResumeLayout(false); this.skinOffsetsTabPage.ResumeLayout(false); + this.offsetTabContextMenu.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -493,5 +521,8 @@ private System.Windows.Forms.TabPage skinPartsTabPage; private System.Windows.Forms.TabPage skinOffsetsTabPage; private System.Windows.Forms.ListBox offsetListBox; + private MetroFramework.Controls.MetroContextMenu offsetTabContextMenu; + private System.Windows.Forms.ToolStripMenuItem addOffsetToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem removeOffsetToolStripMenuItem; } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Editor/CustomSkinEditor.cs b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs index 1fa85833..cbd165ca 100644 --- a/PCK-Studio/Forms/Editor/CustomSkinEditor.cs +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs @@ -11,6 +11,8 @@ using PckStudio.Internal; using PckStudio.Extensions; using PckStudio.IO.CSMB; using PckStudio.FileFormats; +using System.Linq; +using PckStudio.Forms.Additional_Popups; namespace PckStudio.Forms.Editor { @@ -85,12 +87,13 @@ namespace PckStudio.Forms.Editor renderer3D1.Texture = skin.Texture; } - //skinOffsetListBindingSource = new BindingSource(renderer3D1.offsetSpecificMeshStorage, null); - //offsetListBox.DataSource = skinOffsetListBindingSource; - //offsetListBox.DisplayMember = "Value"; + skinOffsetListBindingSource = new BindingSource(renderer3D1.GetOffsets().ToArray(), null); + offsetListBox.DataSource = skinOffsetListBindingSource; + offsetListBox.DisplayMember = "Type"; + offsetListBox.ValueMember = "Value"; skinPartListBindingSource.ResetBindings(false); - //skinOffsetListBindingSource.ResetBindings(false); + skinOffsetListBindingSource.ResetBindings(false); } private void GenerateUVTextureMap(SkinBOX skinBox) @@ -144,16 +147,12 @@ namespace PckStudio.Forms.Editor private void buttonDone_Click(object sender, EventArgs e) { - //Debug.Fail("TODO: Implement"); _skin.AdditionalBoxes.Clear(); _skin.AdditionalBoxes.AddRange(renderer3D1.ModelData); - - // TODO: Get part offset list/IEnumerable from renderer - //_skin.PartOffsets.Clear(); - //_skin.PartOffsets.AddRange(); - - //_previewImage = renderer3D1.GetThumbnail(); - + _skin.PartOffsets.Clear(); + _skin.PartOffsets.AddRange(renderer3D1.GetOffsets()); + // just in case they're not the same instance + _skin.ANIM = renderer3D1.ANIM; DialogResult = DialogResult.OK; } @@ -309,10 +308,52 @@ namespace PckStudio.Forms.Editor renderer3D1.ShowArmor = showArmorCheckbox.Checked; } - private void skinPartListBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) + private void skinPartListBox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) deleteToolStripMenuItem_Click(sender, e); } + + private void ReloadOffsetList() + { + skinOffsetListBindingSource = new BindingSource(renderer3D1.GetOffsets().ToArray(), null); + offsetListBox.DataSource = skinOffsetListBindingSource; + skinOffsetListBindingSource.ResetBindings(false); + } + + private void addOffsetToolStripMenuItem_Click(object sender, EventArgs e) + { + var offsets = renderer3D1.GetOffsets().Select(offset => offset.Type).ToList(); + string[] available = SkinPartOffset.ValidModelOffsetTypes.Where(s => !offsets.Contains(s)).ToArray(); + using ItemSelectionPopUp typeSelection = new ItemSelectionPopUp(available); + using NumericPrompt valuePrompt = new NumericPrompt(0f, -100_000f, 100_000f); + if (typeSelection.ShowDialog() == DialogResult.OK && valuePrompt.ShowDialog() == DialogResult.OK) + { + renderer3D1.SetPartOffset(typeSelection.SelectedItem, (float)valuePrompt.SelectedValue); + ReloadOffsetList(); + } + } + + private void removeOffsetToolStripMenuItem_Click(object sender, EventArgs e) + { + if (offsetListBox.SelectedItem is not SkinPartOffset offset) + return; + renderer3D1.SetPartOffset(offset.Type, 0f); + ReloadOffsetList(); + } + + private void offsetListBox_DoubleClick(object sender, EventArgs e) + { + if (offsetListBox.SelectedItem is not SkinPartOffset offset) + return; + + using NumericPrompt valuePrompt = new NumericPrompt((float)offset.Value, -100_000f, 100_000f); + valuePrompt.ToolTipText = "Set new Value for " + offset.Type; + if (valuePrompt.ShowDialog() == DialogResult.OK) + { + renderer3D1.SetPartOffset(offset.Type, (float)valuePrompt.SelectedValue); + ReloadOffsetList(); + } + } } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Editor/CustomSkinEditor.resx b/PCK-Studio/Forms/Editor/CustomSkinEditor.resx index 5f688342..9359ff88 100644 --- a/PCK-Studio/Forms/Editor/CustomSkinEditor.resx +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.resx @@ -1017,6 +1017,30 @@ 0 + + 204, 17 + + + 180, 22 + + + Add Offset + + + 180, 22 + + + Remove Offset + + + 181, 70 + + + offsetTabContextMenu + + + MetroFramework.Controls.MetroContextMenu, MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a + Fill