diff --git a/PCK-Studio/Extensions/BlendMode.cs b/PCK-Studio/Extensions/BlendMode.cs index 79fac7f3..76709d50 100644 --- a/PCK-Studio/Extensions/BlendMode.cs +++ b/PCK-Studio/Extensions/BlendMode.cs @@ -8,6 +8,7 @@ Average, DescendingOrder, AscendingOrder, - Screen + Screen, + Overlay } } \ No newline at end of file diff --git a/PCK-Studio/Extensions/ColorExtensions.cs b/PCK-Studio/Extensions/ColorExtensions.cs index 47e101c3..3ff94a3d 100644 --- a/PCK-Studio/Extensions/ColorExtensions.cs +++ b/PCK-Studio/Extensions/ColorExtensions.cs @@ -33,6 +33,7 @@ namespace PckStudio.Extensions BlendMode.AscendingOrder => source > overlay ? overlay : source, BlendMode.DescendingOrder => source < overlay ? overlay : source, BlendMode.Screen => 1f - (1f - source) * (1f - overlay), + BlendMode.Overlay => source < 0.5f ? 2f * source * overlay : 1f - 2f * (1f - source) * (1f - overlay), _ => 0.0f }; return MathExtensions.Clamp(resultValue, 0.0f, 1.0f); diff --git a/PCK-Studio/Forms/Additional-Popups/CreditsForm.Designer.cs b/PCK-Studio/Forms/Additional-Popups/CreditsForm.Designer.cs index e7eb9d93..8802f918 100644 --- a/PCK-Studio/Forms/Additional-Popups/CreditsForm.Designer.cs +++ b/PCK-Studio/Forms/Additional-Popups/CreditsForm.Designer.cs @@ -28,111 +28,131 @@ /// private void InitializeComponent() { + System.Windows.Forms.PictureBox pictureBox1; + MetroFramework.Controls.MetroLabel metroLabel1; + MetroFramework.Controls.MetroLabel metroLabel2; + MetroFramework.Controls.MetroLabel metroLabel3; + MetroFramework.Controls.MetroLabel metroLabel4; + MetroFramework.Controls.MetroLabel metroLabel5; + MetroFramework.Controls.MetroLabel metroLabel6; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CreditsForm)); this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel2 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel3 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel6 = new MetroFramework.Controls.MetroLabel(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.buildLabel = new MetroFramework.Controls.MetroLabel(); + pictureBox1 = new System.Windows.Forms.PictureBox(); + metroLabel1 = new MetroFramework.Controls.MetroLabel(); + metroLabel2 = new MetroFramework.Controls.MetroLabel(); + metroLabel3 = new MetroFramework.Controls.MetroLabel(); + metroLabel4 = new MetroFramework.Controls.MetroLabel(); + metroLabel5 = new MetroFramework.Controls.MetroLabel(); + metroLabel6 = new MetroFramework.Controls.MetroLabel(); + ((System.ComponentModel.ISupportInitialize)(pictureBox1)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // - this.pictureBox1.BackColor = System.Drawing.Color.Transparent; - this.pictureBox1.Enabled = false; - this.pictureBox1.Image = global::PckStudio.Properties.Resources.Splash; - this.pictureBox1.Location = new System.Drawing.Point(4, 5); - this.pictureBox1.Margin = new System.Windows.Forms.Padding(0, 0, 11, 0); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(550, 293); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); - this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_Click); + pictureBox1.BackColor = System.Drawing.Color.Transparent; + pictureBox1.Enabled = false; + pictureBox1.Image = global::PckStudio.Properties.Resources.Splash; + pictureBox1.Location = new System.Drawing.Point(4, 5); + pictureBox1.Margin = new System.Windows.Forms.Padding(0, 0, 11, 0); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new System.Drawing.Size(550, 293); + pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + pictureBox1.TabIndex = 0; + pictureBox1.TabStop = false; // // metroLabel1 // - this.metroLabel1.AutoSize = true; - this.metroLabel1.Enabled = false; - this.metroLabel1.Location = new System.Drawing.Point(4, 301); - this.metroLabel1.Name = "metroLabel1"; - this.metroLabel1.Size = new System.Drawing.Size(250, 19); - this.metroLabel1.TabIndex = 1; - this.metroLabel1.Text = "Restored and maintained by PhoenixARC"; - this.metroLabel1.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel1.AutoSize = true; + metroLabel1.Enabled = false; + metroLabel1.Location = new System.Drawing.Point(4, 301); + metroLabel1.Name = "metroLabel1"; + metroLabel1.Size = new System.Drawing.Size(250, 19); + metroLabel1.TabIndex = 1; + metroLabel1.Text = "Restored and maintained by PhoenixARC"; + metroLabel1.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel2 // - this.metroLabel2.AutoSize = true; - this.metroLabel2.Enabled = false; - this.metroLabel2.Location = new System.Drawing.Point(314, 301); - this.metroLabel2.Name = "metroLabel2"; - this.metroLabel2.Size = new System.Drawing.Size(269, 19); - this.metroLabel2.TabIndex = 2; - this.metroLabel2.Text = "Utilizing the Nobledez Website by Newagent"; - this.metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel2.AutoSize = true; + metroLabel2.Enabled = false; + metroLabel2.Location = new System.Drawing.Point(314, 301); + metroLabel2.Name = "metroLabel2"; + metroLabel2.Size = new System.Drawing.Size(269, 19); + metroLabel2.TabIndex = 2; + metroLabel2.Text = "Utilizing the Nobledez Website by Newagent"; + metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel3 // - this.metroLabel3.AutoSize = true; - this.metroLabel3.Enabled = false; - this.metroLabel3.Location = new System.Drawing.Point(314, 339); - this.metroLabel3.Name = "metroLabel3"; - this.metroLabel3.Size = new System.Drawing.Size(212, 19); - this.metroLabel3.TabIndex = 3; - this.metroLabel3.Text = "3D skin renderer by Łukasz Rejman"; - this.metroLabel3.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel3.AutoSize = true; + metroLabel3.Enabled = false; + metroLabel3.Location = new System.Drawing.Point(314, 339); + metroLabel3.Name = "metroLabel3"; + metroLabel3.Size = new System.Drawing.Size(212, 19); + metroLabel3.TabIndex = 3; + metroLabel3.Text = "3D skin renderer by Łukasz Rejman"; + metroLabel3.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel4 // - this.metroLabel4.AutoSize = true; - this.metroLabel4.Enabled = false; - this.metroLabel4.Location = new System.Drawing.Point(314, 320); - this.metroLabel4.Name = "metroLabel4"; - this.metroLabel4.Size = new System.Drawing.Size(199, 19); - this.metroLabel4.TabIndex = 4; - this.metroLabel4.Text = "3D renderer found by Newagent"; - this.metroLabel4.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel4.AutoSize = true; + metroLabel4.Enabled = false; + metroLabel4.Location = new System.Drawing.Point(314, 320); + metroLabel4.Name = "metroLabel4"; + metroLabel4.Size = new System.Drawing.Size(199, 19); + metroLabel4.TabIndex = 4; + metroLabel4.Text = "3D renderer found by Newagent"; + metroLabel4.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel5 // - this.metroLabel5.AutoSize = true; - this.metroLabel5.Enabled = false; - this.metroLabel5.Location = new System.Drawing.Point(4, 320); - this.metroLabel5.Name = "metroLabel5"; - this.metroLabel5.Size = new System.Drawing.Size(300, 19); - this.metroLabel5.TabIndex = 5; - this.metroLabel5.Text = "Additional development by MattNL and Miku-666"; - this.metroLabel5.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel5.AutoSize = true; + metroLabel5.Enabled = false; + metroLabel5.Location = new System.Drawing.Point(4, 320); + metroLabel5.Name = "metroLabel5"; + metroLabel5.Size = new System.Drawing.Size(300, 19); + metroLabel5.TabIndex = 5; + metroLabel5.Text = "Additional development by MattNL and Miku-666"; + metroLabel5.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel6 // - this.metroLabel6.AutoSize = true; - this.metroLabel6.Enabled = false; - this.metroLabel6.Location = new System.Drawing.Point(4, 339); - this.metroLabel6.Name = "metroLabel6"; - this.metroLabel6.Size = new System.Drawing.Size(203, 19); - this.metroLabel6.TabIndex = 6; - this.metroLabel6.Text = "Code base overhaul by Miku-666"; - this.metroLabel6.Theme = MetroFramework.MetroThemeStyle.Dark; + metroLabel6.AutoSize = true; + metroLabel6.Enabled = false; + metroLabel6.Location = new System.Drawing.Point(4, 339); + metroLabel6.Name = "metroLabel6"; + metroLabel6.Size = new System.Drawing.Size(203, 19); + metroLabel6.TabIndex = 6; + metroLabel6.Text = "Code base overhaul by Miku-666"; + metroLabel6.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // buildLabel + // + this.buildLabel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(12)))), ((int)(((byte)(34)))), ((int)(((byte)(56))))); + this.buildLabel.Enabled = false; + this.buildLabel.ForeColor = System.Drawing.SystemColors.Control; + this.buildLabel.Location = new System.Drawing.Point(314, 30); + this.buildLabel.Name = "buildLabel"; + this.buildLabel.Size = new System.Drawing.Size(212, 171); + this.buildLabel.TabIndex = 7; + this.buildLabel.Text = "Build Information"; + this.buildLabel.TextAlign = System.Drawing.ContentAlignment.TopRight; + this.buildLabel.Theme = MetroFramework.MetroThemeStyle.Dark; // // CreditsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(585, 364); - this.Controls.Add(this.metroLabel6); - this.Controls.Add(this.metroLabel1); - this.Controls.Add(this.metroLabel5); - this.Controls.Add(this.metroLabel4); - this.Controls.Add(this.metroLabel3); - this.Controls.Add(this.metroLabel2); - this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.buildLabel); + this.Controls.Add(metroLabel6); + this.Controls.Add(metroLabel1); + this.Controls.Add(metroLabel5); + this.Controls.Add(metroLabel4); + this.Controls.Add(metroLabel3); + this.Controls.Add(metroLabel2); + this.Controls.Add(pictureBox1); this.DisplayHeader = false; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; @@ -144,7 +164,7 @@ this.Style = MetroFramework.MetroColorStyle.Black; this.Text = "programInfo"; this.Theme = MetroFramework.MetroThemeStyle.Dark; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(pictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -153,12 +173,6 @@ #endregion private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; - private System.Windows.Forms.PictureBox pictureBox1; - private MetroFramework.Controls.MetroLabel metroLabel1; - private MetroFramework.Controls.MetroLabel metroLabel2; - private MetroFramework.Controls.MetroLabel metroLabel3; - private MetroFramework.Controls.MetroLabel metroLabel4; - private MetroFramework.Controls.MetroLabel metroLabel5; - private MetroFramework.Controls.MetroLabel metroLabel6; - } + private MetroFramework.Controls.MetroLabel buildLabel; + } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Additional-Popups/CreditsForm.cs b/PCK-Studio/Forms/Additional-Popups/CreditsForm.cs index fb62cf3e..3f0b2ae5 100644 --- a/PCK-Studio/Forms/Additional-Popups/CreditsForm.cs +++ b/PCK-Studio/Forms/Additional-Popups/CreditsForm.cs @@ -1,24 +1,22 @@ using System; using System.Windows.Forms; using MetroFramework.Forms; +using PckStudio.Internal; namespace PckStudio { public partial class CreditsForm : MetroForm { - int count = 0; public CreditsForm() { InitializeComponent(); +#if BETA + buildLabel.Text = $"[Beta] {ApplicationBuildInfo.BetaBuildVersion}@{CommitInfo.BranchName}"; +#elif DEBUG + buildLabel.Text = $"[Debug] {CommitInfo.BranchName}@{CommitInfo.CommitHash}"; +#else + buildLabel.Text = string.Empty; +#endif } - - private void pictureBox1_Click(object sender, EventArgs e) - { - if (++count == 5) - { - MessageBox.Show("🌸Miku🌸 was here!"); - count = 0; - } - } - } + } } diff --git a/PCK-Studio/Forms/Additional-Popups/CreditsForm.resx b/PCK-Studio/Forms/Additional-Popups/CreditsForm.resx index 02993faf..b7a2f32a 100644 --- a/PCK-Studio/Forms/Additional-Popups/CreditsForm.resx +++ b/PCK-Studio/Forms/Additional-Popups/CreditsForm.resx @@ -117,6 +117,27 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + False + + + False + + + False + + + False + + + False + + + False + + + False + 17, 17 diff --git a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs index 202670c2..baad3b6c 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs @@ -9,6 +9,7 @@ using OMI.Formats.Pck; using PckStudio.Internal; using PckStudio.Forms.Editor; using PckStudio.Classes.IO._3DST; +using PckStudio.Properties; namespace PckStudio { @@ -24,7 +25,6 @@ namespace PckStudio SkinANIM anim = new SkinANIM(); eSkinType skinType; - PckFile.PCKProperties generatedModel = new PckFile.PCKProperties(); enum eSkinType : int { @@ -281,28 +281,22 @@ namespace PckStudio //Prompt for skin model generator if (MessageBox.Show("Create your own custom skin model?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) != DialogResult.Yes) return; - - generateModel generate = new generateModel(generatedModel, Properties.Resources.classic_template); - if (generate.ShowDialog() == DialogResult.OK) //Opens Model Generator Dialog + using var ms = new MemoryStream(); + Resources.classic_template.Save(ms, ImageFormat.Png); + skin.SetData(ms.ToArray()); + + generateModel generate = new generateModel(skin); + + if (generate.ShowDialog() == DialogResult.OK) { - try + displayBox.Image = generate.PreviewImage; + buttonDone.Enabled = true; + labelSelectTexture.Visible = false; + if (skinType != eSkinType._64x64 && skinType != eSkinType._64x64HD) { - using (FileStream stream = File.OpenRead(Application.StartupPath + "\\temp.png")) - { - skinPictureBoxTexture.Image = Image.FromStream(stream); - } - buttonDone.Enabled = true; - labelSelectTexture.Visible = false; - if (skinType != eSkinType._64x64 && skinType != eSkinType._64x64HD) - { - buttonSkin.Location = new Point(buttonSkin.Location.X - skinPictureBoxTexture.Width, buttonSkin.Location.Y); - skinType = eSkinType._64x64; - } - } - catch (Exception ex) - { - MessageBox.Show(ex.ToString()); + buttonSkin.Location = new Point(buttonSkin.Location.X - skinPictureBoxTexture.Width, buttonSkin.Location.Y); + skinType = eSkinType._64x64; } } } diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs index cc34372d..58d03853 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.Designer.cs @@ -29,7 +29,12 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + System.Windows.Forms.Label label6; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(generateModel)); + System.Windows.Forms.Label label5; + System.Windows.Forms.Label label3; + System.Windows.Forms.Label label7; + System.Windows.Forms.Label labelTextureMappingPreview; this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.createToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cloneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -52,21 +57,16 @@ this.label13 = new System.Windows.Forms.Label(); this.offsetHead = new System.Windows.Forms.TextBox(); this.label12 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); this.comboParent = new System.Windows.Forms.ComboBox(); - this.label5 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); this.buttonEXPORT = new System.Windows.Forms.Button(); - this.label7 = new System.Windows.Forms.Label(); this.buttonIMPORT = new System.Windows.Forms.Button(); - this.texturePreview = new System.Windows.Forms.PictureBox(); - this.labelTextureMappingPreview = new System.Windows.Forms.Label(); + this.uvPictureBox = new PckStudio.PictureBoxWithInterpolationMode(); this.buttonImportModel = new System.Windows.Forms.Button(); this.displayBox = new System.Windows.Forms.PictureBox(); this.buttonExportModel = new System.Windows.Forms.Button(); this.OpenJSONButton = new System.Windows.Forms.Button(); this.buttonTemplate = new MetroFramework.Controls.MetroButton(); - this.checkTextureGenerate = new MetroFramework.Controls.MetroCheckBox(); + this.generateTextureCheckBox = new MetroFramework.Controls.MetroCheckBox(); this.checkGuide = new MetroFramework.Controls.MetroCheckBox(); this.checkBoxArmor = new MetroFramework.Controls.MetroCheckBox(); this.SizeXUpDown = new System.Windows.Forms.NumericUpDown(); @@ -87,12 +87,17 @@ this.U = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.V = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.listViewBoxes = new System.Windows.Forms.ListView(); + label6 = new System.Windows.Forms.Label(); + label5 = new System.Windows.Forms.Label(); + label3 = new System.Windows.Forms.Label(); + label7 = new System.Windows.Forms.Label(); + labelTextureMappingPreview = new System.Windows.Forms.Label(); this.contextMenuStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.tabBody.SuspendLayout(); this.tabPage1.SuspendLayout(); this.myTablePanel2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.texturePreview)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.displayBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeXUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeYUpDown)).BeginInit(); @@ -104,6 +109,36 @@ ((System.ComponentModel.ISupportInitialize)(this.PosXUpDown)).BeginInit(); this.SuspendLayout(); // + // label6 + // + resources.ApplyResources(label6, "label6"); + label6.ForeColor = System.Drawing.Color.White; + label6.Name = "label6"; + // + // label5 + // + resources.ApplyResources(label5, "label5"); + label5.ForeColor = System.Drawing.Color.White; + label5.Name = "label5"; + // + // label3 + // + resources.ApplyResources(label3, "label3"); + label3.ForeColor = System.Drawing.Color.White; + label3.Name = "label3"; + // + // label7 + // + resources.ApplyResources(label7, "label7"); + label7.ForeColor = System.Drawing.Color.White; + label7.Name = "label7"; + // + // labelTextureMappingPreview + // + resources.ApplyResources(labelTextureMappingPreview, "labelTextureMappingPreview"); + labelTextureMappingPreview.ForeColor = System.Drawing.Color.White; + labelTextureMappingPreview.Name = "labelTextureMappingPreview"; + // // contextMenuStrip1 // this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); @@ -260,12 +295,6 @@ this.label12.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(64)))), ((int)(((byte)(0))))); this.label12.Name = "label12"; // - // label6 - // - resources.ApplyResources(this.label6, "label6"); - this.label6.ForeColor = System.Drawing.Color.White; - this.label6.Name = "label6"; - // // comboParent // this.comboParent.FormattingEnabled = true; @@ -280,18 +309,6 @@ this.comboParent.Name = "comboParent"; this.comboParent.SelectedValueChanged += new System.EventHandler(this.comboParent_SelectedIndexChanged); // - // label5 - // - resources.ApplyResources(this.label5, "label5"); - this.label5.ForeColor = System.Drawing.Color.White; - this.label5.Name = "label5"; - // - // label3 - // - resources.ApplyResources(this.label3, "label3"); - this.label3.ForeColor = System.Drawing.Color.White; - this.label3.Name = "label3"; - // // buttonEXPORT // resources.ApplyResources(this.buttonEXPORT, "buttonEXPORT"); @@ -300,12 +317,6 @@ this.buttonEXPORT.UseVisualStyleBackColor = true; this.buttonEXPORT.Click += new System.EventHandler(this.buttonEXPORT_Click); // - // label7 - // - resources.ApplyResources(this.label7, "label7"); - this.label7.ForeColor = System.Drawing.Color.White; - this.label7.Name = "label7"; - // // buttonIMPORT // resources.ApplyResources(this.buttonIMPORT, "buttonIMPORT"); @@ -314,18 +325,13 @@ this.buttonIMPORT.UseVisualStyleBackColor = true; this.buttonIMPORT.Click += new System.EventHandler(this.buttonIMPORT_Click); // - // texturePreview + // uvPictureBox // - this.texturePreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - resources.ApplyResources(this.texturePreview, "texturePreview"); - this.texturePreview.Name = "texturePreview"; - this.texturePreview.TabStop = false; - // - // labelTextureMappingPreview - // - resources.ApplyResources(this.labelTextureMappingPreview, "labelTextureMappingPreview"); - this.labelTextureMappingPreview.ForeColor = System.Drawing.Color.White; - this.labelTextureMappingPreview.Name = "labelTextureMappingPreview"; + this.uvPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + resources.ApplyResources(this.uvPictureBox, "uvPictureBox"); + this.uvPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + this.uvPictureBox.Name = "uvPictureBox"; + this.uvPictureBox.TabStop = false; // // buttonImportModel // @@ -367,12 +373,12 @@ this.buttonTemplate.UseSelectable = true; this.buttonTemplate.Click += new System.EventHandler(this.buttonTemplate_Click); // - // checkTextureGenerate + // generateTextureCheckBox // - resources.ApplyResources(this.checkTextureGenerate, "checkTextureGenerate"); - this.checkTextureGenerate.Name = "checkTextureGenerate"; - this.checkTextureGenerate.Theme = MetroFramework.MetroThemeStyle.Dark; - this.checkTextureGenerate.UseSelectable = true; + resources.ApplyResources(this.generateTextureCheckBox, "generateTextureCheckBox"); + this.generateTextureCheckBox.Name = "generateTextureCheckBox"; + this.generateTextureCheckBox.Theme = MetroFramework.MetroThemeStyle.Dark; + this.generateTextureCheckBox.UseSelectable = true; // // checkGuide // @@ -380,7 +386,7 @@ this.checkGuide.Name = "checkGuide"; this.checkGuide.Theme = MetroFramework.MetroThemeStyle.Dark; this.checkGuide.UseSelectable = true; - this.checkGuide.CheckedChanged += new System.EventHandler(this.render); + this.checkGuide.CheckedChanged += new System.EventHandler(this.Render); // // checkBoxArmor // @@ -388,7 +394,7 @@ this.checkBoxArmor.Name = "checkBoxArmor"; this.checkBoxArmor.Theme = MetroFramework.MetroThemeStyle.Dark; this.checkBoxArmor.UseSelectable = true; - this.checkBoxArmor.CheckedChanged += new System.EventHandler(this.render); + this.checkBoxArmor.CheckedChanged += new System.EventHandler(this.Render); // // SizeXUpDown // @@ -523,7 +529,7 @@ // // listViewBoxes // - this.listViewBoxes.Activation = System.Windows.Forms.ItemActivation.OneClick; + this.listViewBoxes.BorderStyle = System.Windows.Forms.BorderStyle.None; this.listViewBoxes.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.Part, this.X, @@ -563,7 +569,7 @@ this.Controls.Add(this.SizeXUpDown); this.Controls.Add(this.checkBoxArmor); this.Controls.Add(this.checkGuide); - this.Controls.Add(this.checkTextureGenerate); + this.Controls.Add(this.generateTextureCheckBox); this.Controls.Add(this.buttonTemplate); this.Controls.Add(this.displayBox); this.Controls.Add(this.listViewBoxes); @@ -571,19 +577,19 @@ this.Controls.Add(this.buttonExportModel); this.Controls.Add(this.buttonImportModel); this.Controls.Add(this.buttonEXPORT); - this.Controls.Add(this.labelTextureMappingPreview); - this.Controls.Add(this.texturePreview); + this.Controls.Add(labelTextureMappingPreview); + this.Controls.Add(this.uvPictureBox); this.Controls.Add(this.comboParent); - this.Controls.Add(this.label6); + this.Controls.Add(label6); this.Controls.Add(this.buttonIMPORT); this.Controls.Add(this.groupBox1); - this.Controls.Add(this.label7); + this.Controls.Add(label7); this.Controls.Add(this.rotateLeftBtn); this.Controls.Add(this.rotateRightBtn); this.Controls.Add(this.labelView); this.Controls.Add(this.buttonDone); - this.Controls.Add(this.label3); - this.Controls.Add(this.label5); + this.Controls.Add(label3); + this.Controls.Add(label5); this.MaximizeBox = false; this.Name = "generateModel"; this.Style = MetroFramework.MetroColorStyle.Silver; @@ -597,7 +603,7 @@ this.tabPage1.ResumeLayout(false); this.myTablePanel2.ResumeLayout(false); this.myTablePanel2.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.texturePreview)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.displayBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeXUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SizeYUpDown)).EndInit(); @@ -623,15 +629,10 @@ private System.Windows.Forms.Button buttonExportModel; private System.Windows.Forms.PictureBox displayBox; private System.Windows.Forms.Button buttonImportModel; - private System.Windows.Forms.Label labelTextureMappingPreview; - private System.Windows.Forms.PictureBox texturePreview; + private PckStudio.PictureBoxWithInterpolationMode uvPictureBox; private System.Windows.Forms.Button buttonIMPORT; - private System.Windows.Forms.Label label7; private System.Windows.Forms.Button buttonEXPORT; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label5; private System.Windows.Forms.ComboBox comboParent; - private System.Windows.Forms.Label label6; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.TabControl tabBody; private System.Windows.Forms.TabPage tabPage1; @@ -649,7 +650,7 @@ private System.Windows.Forms.Button rotateRightBtn; private System.Windows.Forms.Label labelView; private MetroFramework.Controls.MetroButton buttonTemplate; - private MetroFramework.Controls.MetroCheckBox checkTextureGenerate; + private MetroFramework.Controls.MetroCheckBox generateTextureCheckBox; private MetroFramework.Controls.MetroCheckBox checkGuide; private MetroFramework.Controls.MetroCheckBox checkBoxArmor; private System.Windows.Forms.NumericUpDown SizeXUpDown; diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index 60b0154f..76a43af3 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -13,27 +13,41 @@ using Newtonsoft.Json; using MetroFramework.Forms; using OMI.Formats.Pck; using PckStudio.Internal; +using PckStudio.Extensions; +using System.Runtime.CompilerServices; +using System.Diagnostics; +using System.Text; namespace PckStudio { [Obsolete] public partial class generateModel : MetroForm { - PictureBox skinPreview = new PictureBox(); + [Obsolete("We don't need a full control to get an image")] + private PictureBox skinPreview = new PictureBox(); - eViewDirection direction = eViewDirection.front; + private Image _previewImage; + public Image PreviewImage => _previewImage; - enum eViewDirection + private ViewDirection direction = ViewDirection.front; + + private enum ViewDirection { front, + right, back, left, - right } - PckFile.PCKProperties boxes; + private PckFile.FileData _file; + private SkinANIM _ANIM; - Color backgroundColor = Color.FromArgb(0xff, 0x50, 0x50, 0x50); + private static Color _backgroundColor = Color.FromArgb(0xff, 0x50, 0x50, 0x50); + private static GraphicsConfig _graphicsConfig = new GraphicsConfig() + { + InterpolationMode = InterpolationMode.NearestNeighbor, + PixelOffsetMode = PixelOffsetMode.HighQuality, + }; private static readonly string[] ValidModelBoxTypes = new string[] { @@ -95,7 +109,7 @@ namespace PckStudio List modelBoxes = new List(); List modelOffsets = new List(); - class ModelOffset + private class ModelOffset { public string Name; public float YOffset; @@ -105,22 +119,29 @@ namespace PckStudio Name = name; YOffset = yOffset; } - public ValueTuple ToProperty() + public (string, string) ToProperty() { string value = $"{Name} Y {YOffset}"; - return new ValueTuple("OFFSET", value.Replace(',','.')); + return ("OFFSET", value.Replace(',','.')); } } - public generateModel(PckFile.PCKProperties skinProperties, Image texture) + public generateModel(PckFile.FileData file) { MessageBox.Show(this, "This feature is now considered deprecated and will no longer recieve updates. A better alternative is currently under development. Use at your own risk.", "Deprecated Feature", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); InitializeComponent(); - boxes = skinProperties; - texturePreview.Image = texture; + + _file = file; + if (file.Size > 0) + { + using (var ms = new MemoryStream(file.Data)) + { + uvPictureBox.Image = Image.FromStream(ms); + } + } comboParent.Items.Clear(); - ValidModelBoxTypes.ToList().ForEach(p => comboParent.Items.Add(p)); - loadData(); + comboParent.Items.AddRange(ValidModelBoxTypes); + LoadData(file.Properties); } private static readonly Regex sWhitespace = new Regex(@"\s+"); public static string ReplaceWhitespace(string input, string replacement) @@ -128,55 +149,36 @@ namespace PckStudio return sWhitespace.Replace(input, replacement); } - //loads data from mode list - private void loadData() + private void LoadData(PckFile.PCKProperties properties) { - foreach (var property in boxes) - { - switch (property.Key) + comboParent.Enabled = properties.GetProperties("BOX").All(kv => { + var box = SkinBOX.FromString(kv.Value); + if (ValidModelBoxTypes.Contains(box.Type)) { - case "BOX": - { - var box = SkinBOX.FromString(property.Value); - - string name = box.Type; - if (ValidModelBoxTypes.Contains(name)) - { - modelBoxes.Add(box); - } - - comboParent.Enabled = true; - break; - } - - case "OFFSET": - { - string[] offset = ReplaceWhitespace(property.Value, ",").TrimEnd('\n', '\r', ' ').Split(','); - if (offset.Length < 3) continue; - string name = offset[0]; - string dimension = offset[1]; // "Y" - if (dimension != "Y") continue; - float value = float.Parse(offset[2]); - if (ValidModelOffsetTypes.Contains(name)) - modelOffsets.Add(new ModelOffset(name, value)); - break; - } - case "ANIM": - { - try - { - //ANIM = (eANIMFlags)int.Parse(property.Item2, System.Globalization.NumberStyles.HexNumber); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - break; - } + modelBoxes.Add(box); + return true; } - } - updateListView(); - render(); + return false; + }); + properties.GetProperties("OFFSET").All(kv => { + string[] offset = ReplaceWhitespace(kv.Value, ",").TrimEnd('\n', '\r', ' ').Split(','); + if (offset.Length < 3) + return false; + string name = offset[0]; + if (offset[1] != "Y") + return false; + float value = float.Parse(offset[2]); + if (ValidModelOffsetTypes.Contains(name)) + { + modelOffsets.Add(new ModelOffset(name, value)); + return true; + } + return false; + }); + + _ANIM = properties.GetPropertyValue("ANIM", SkinANIM.FromString); + UpdateListView(); + Rerender(); } //Rename model part/item @@ -185,25 +187,32 @@ namespace PckStudio listViewBoxes.SelectedItems[0].BeginEdit(); } + private void Rerender([CallerMemberName] string caller = default!) + { + Debug.WriteLine($"Call from {caller}", category: nameof(Rerender)); + Render(this, EventArgs.Empty); + if (generateTextureCheckBox.Checked) + GenerateUVTextureMap(); + } + // Graphic Rendering // Builds an image based on the view - private void render(object sender = null, EventArgs e = null) + private void Render(object sender, EventArgs e) { - //buttonTemplate.Enabled = listViewBoxes.Items.Count == 0; - //setZ(); //Organizes Z layers - Bitmap bitmapModelPreview = new Bitmap(displayBox.Width, displayBox.Height); //Creates Model Display layer + buttonTemplate.Enabled = listViewBoxes.Items.Count == 0; + OrganizesZLayer(); + Bitmap bitmapModelPreview = new Bitmap(displayBox.Width, displayBox.Height); // Creates Model Display layer using (Graphics graphics = Graphics.FromImage(bitmapModelPreview)) { - graphics.Clear(backgroundColor); - graphics.InterpolationMode = InterpolationMode.NearestNeighbor; - // makes sure it reders/draws the full pixel in top left corner - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.ApplyConfig(_graphicsConfig); + graphics.Clear(_backgroundColor); + float headbodyY = (displayBox.Height / 2) + 25; // 25 float armY = (displayBox.Height / 2) + 35; // -60; float legY = (displayBox.Height / 2) + 85; // -80; float groundLevel = (displayBox.Height / 2) + 145; graphics.DrawLine(Pens.White, 0, groundLevel, displayBox.Width, groundLevel); - float gfx_scale = texturePreview.Image.Width / 64; // used for displaying larger graphics properly; 64 is the base skin width for all models + float renderScale = uvPictureBox.Image.Width / 64; // used for displaying larger graphics properly; 64 is the base skin width for all models // Chooses Render settings based on current direction foreach (ListViewItem listViewItem in listViewBoxes.Items) @@ -215,7 +224,7 @@ namespace PckStudio switch (direction) { - case eViewDirection.front: + case ViewDirection.front: { //Sets X & Y based on model part class // listViewItem.Text -> part.Type @@ -278,8 +287,8 @@ namespace PckStudio break; } - //Maps imported Texture if auto texture is disabled - if (!checkTextureGenerate.Checked) + // Maps imported Texture if texture generation is disabled + if (!generateTextureCheckBox.Checked) { RectangleF destRect = new RectangleF( x + part.Pos.X * 5, @@ -287,11 +296,11 @@ namespace PckStudio part.Size.X * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z) * gfx_scale, - (part.UV.Y + part.Size.Z) * gfx_scale, - part.Size.X * gfx_scale, - part.Size.Y * gfx_scale); - graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); + (part.UV.X + part.Size.Z) * renderScale, + (part.UV.Y + part.Size.Z) * renderScale, + part.Size.X * renderScale, + part.Size.Y * renderScale); + graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); } else { @@ -301,7 +310,7 @@ namespace PckStudio break; } - case eViewDirection.left: + case ViewDirection.left: { //Sets X & Y based on model part class switch (part.Type) @@ -351,8 +360,8 @@ namespace PckStudio break; } - //Maps imported Texture if auto texture is disabled - if (!checkTextureGenerate.Checked) + // Maps imported Texture if auto texture is disabled + if (!generateTextureCheckBox.Checked) { RectangleF destRect = new RectangleF( x + part.Pos.Z * 5, @@ -360,11 +369,11 @@ namespace PckStudio part.Size.Z * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z + part.Size.X) * gfx_scale, - (part.UV.Y + part.Size.Z) * gfx_scale, - part.Size.Z * gfx_scale, - part.Size.Y * gfx_scale); - graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); + (part.UV.X + part.Size.Z + part.Size.X) * renderScale, + (part.UV.Y + part.Size.Z) * renderScale, + part.Size.Z * renderScale, + part.Size.Y * renderScale); + graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); } else { @@ -375,7 +384,7 @@ namespace PckStudio break; } - case eViewDirection.back: + case ViewDirection.back: { //Sets X & Y based on model part class switch (part.Type) @@ -430,7 +439,7 @@ namespace PckStudio } //Maps imported Texture if auto texture is disabled - if (!checkTextureGenerate.Checked) + if (!generateTextureCheckBox.Checked) { RectangleF destRect = new RectangleF( x + part.Pos.X * 5, @@ -438,11 +447,11 @@ namespace PckStudio part.Size.X * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z * 2 + part.Size.X) * gfx_scale, - (part.UV.Y + part.Size.Z) * gfx_scale, - part.Size.X * gfx_scale, - part.Size.Y * gfx_scale); - graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); + (part.UV.X + part.Size.Z * 2 + part.Size.X) * renderScale, + (part.UV.Y + part.Size.Z) * renderScale, + part.Size.X * renderScale, + part.Size.Y * renderScale); + graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); } else { @@ -453,7 +462,7 @@ namespace PckStudio break; } - case eViewDirection.right: + case ViewDirection.right: //Sets X & Y based on model part class switch (part.Type) { @@ -502,7 +511,7 @@ namespace PckStudio break; } //Maps imported Texture if auto texture is disabled - if (!checkTextureGenerate.Checked) + if (!generateTextureCheckBox.Checked) { RectangleF destRect = new RectangleF( x + part.Pos.Z * 5, @@ -510,11 +519,11 @@ namespace PckStudio part.Size.Z * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.UV.X + part.Size.Z + part.Size.X) * gfx_scale, - (part.UV.Y + part.Size.Z) * gfx_scale, - part.Size.Z * gfx_scale, - part.Size.Y * gfx_scale); - graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); + (part.UV.X + part.Size.Z + part.Size.X) * renderScale, + (part.UV.Y + part.Size.Z) * renderScale, + part.Size.Z * renderScale, + part.Size.Y * renderScale); + graphics.DrawImage(uvPictureBox.Image, destRect, srcRect, GraphicsUnit.Pixel); } else { @@ -531,16 +540,17 @@ namespace PckStudio if (checkGuide.Checked) DrawGuideLines(graphics); } - displayBox.Image = bitmapModelPreview; // Sets created preview graphics to display box + displayBox.Image = bitmapModelPreview; } - private void MapTexture() + private void GenerateUVTextureMap() { - if (checkTextureGenerate.Checked) + if (generateTextureCheckBox.Checked) { - Bitmap bitmapAutoTexture = new Bitmap(texturePreview.Width, texturePreview.Height); - using (Graphics graphics = Graphics.FromImage(bitmapAutoTexture)) + Random rng = new Random(); + using (Graphics graphics = Graphics.FromImage(uvPictureBox.Image)) { + graphics.ApplyConfig(_graphicsConfig); foreach (var part in modelBoxes) { float width = part.Size.X * 2; @@ -548,8 +558,9 @@ namespace PckStudio float length = part.Size.Z * 2; float u = part.UV.X * 2; float v = part.UV.Y * 2; - Random r = new Random(); - Brush brush = new SolidBrush(Color.FromArgb(r.Next(int.MinValue, int.MaxValue))); + int argb = rng.Next(-16777216, -1); // 0xFF000000 - 0xFFFFFFFF + var color = Color.FromArgb(argb); + Brush brush = new SolidBrush(color); graphics.FillRectangle(brush, u + length, v, width, length); graphics.FillRectangle(brush, u + length + width, v, width, length); graphics.FillRectangle(brush, u, length + v, length, height); @@ -558,263 +569,268 @@ namespace PckStudio graphics.FillRectangle(brush, u + length + width * 2, v + length, length, height); } } - texturePreview.Image = bitmapAutoTexture; + uvPictureBox.Invalidate(); } } - //Checks and sets Z layering - private void setZ() + // Checks and sets Z layering + private void OrganizesZLayer() { foreach (ListViewItem listViewItem in listViewBoxes.Items) listViewItem.SubItems.Add("unchecked"); - if (direction == eViewDirection.front) + float surfaceCenter = displayBox.Width / 2; + + switch (direction) { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) + case ViewDirection.front: { - if (listViewItemCurrent.SubItems[9].Text == "unchecked") + foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) { - float x = 0; - if (listViewItemCurrent.Tag.ToString() == "HEAD") - x = displayBox.Width / 2; - else if (listViewItemCurrent.Tag.ToString() == "BODY") - x = displayBox.Width / 2; - else if (listViewItemCurrent.Tag.ToString() == "ARM0") - x = 178; - else if (listViewItemCurrent.Tag.ToString() == "ARM1") - x = 228; - else if (listViewItemCurrent.Tag.ToString() == "LEG0") - x = 193; - else if (listViewItemCurrent.Tag.ToString() == "LEG1") - x = 213; - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) + if (listViewItemCurrent.SubItems[9].Text == "unchecked") { - if (listViewItemComparing.SubItems[9].Text == "unchecked" && (int)double.Parse(listViewItemCurrent.SubItems[3].Text) + (int)double.Parse(listViewItemCurrent.SubItems[6].Text) < (int)double.Parse(listViewItemComparing.SubItems[3].Text) + (int)double.Parse(listViewItemComparing.SubItems[6].Text)) + float x = 0; + if (listViewItemCurrent.Text == "HEAD") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "BODY") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "ARM0") + x = 178; + else if (listViewItemCurrent.Text == "ARM1") + x = 228; + else if (listViewItemCurrent.Text == "LEG0") + x = 193; + else if (listViewItemCurrent.Text == "LEG1") + x = 213; + + bool flag = false; + int index = listViewItemCurrent.Index; + foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) { - if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) + var val1 = double.Parse(listViewItemCurrent.SubItems[3].Text) + double.Parse(listViewItemCurrent.SubItems[6].Text); + var val2 = double.Parse(listViewItemComparing.SubItems[3].Text) + double.Parse(listViewItemComparing.SubItems[6].Text); + if (listViewItemComparing.SubItems[9].Text == "unchecked" && + val1 < val2) { - index = listViewItemComparing.Index + 1; - flag = true; + if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) + { + index = listViewItemComparing.Index + 1; + flag = true; + } } } + listViewItemCurrent.SubItems[9].Text = "checked"; + if (flag) + { + ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + listViewBoxes.Items.Insert(index, listViewItem2); + listViewItemCurrent.Remove(); + } } - listViewItemCurrent.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag == true) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - listViewItemCurrent.Remove(); - } - } - else - { - checkedItems += 1; } } - } while (checkedItems < listViewBoxes.Items.Count); - } - else if (direction == eViewDirection.left) - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItem1 in listViewBoxes.Items) + break; + case ViewDirection.right: { - if (listViewItem1.SubItems[listViewItem1.SubItems.Count - 1].Text == "unchecked") + int checkedItems = 0; + do { - float x = 0; - if (listViewItem1.Tag.ToString() == "HEAD") - x = displayBox.Width / 2; - else if (listViewItem1.Tag.ToString() == "BODY") - x = displayBox.Width / 2; - else if (listViewItem1.Tag.ToString() == "ARM0") - x = 178; - else if (listViewItem1.Tag.ToString() == "ARM1") - x = 228; - else if (listViewItem1.Tag.ToString() == "LEG0") - x = 193; - else if (listViewItem1.Tag.ToString() == "LEG1") - x = 213; - bool flag = false; - int index = listViewItem1.Index; - foreach (ListViewItem listViewItem2 in listViewBoxes.Items) + foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) { - if (listViewItem2.SubItems[9].Text == "unchecked") + if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") { - int y = 0; - if (listViewItem2.Tag.ToString() == "HEAD") - y = displayBox.Width / 2; - else if (listViewItem2.Tag.ToString() == "BODY") - y = displayBox.Width / 2; - else if (listViewItem2.Tag.ToString() == "ARM0") - y = 178; - else if (listViewItem2.Tag.ToString() == "ARM1") - y = 228; - else if (listViewItem2.Tag.ToString() == "LEG0") - y = 193; - else if (listViewItem2.Tag.ToString() == "LEG1") - y = 213; - if ((int)double.Parse(listViewItem1.SubItems[1].Text) + (int)double.Parse(listViewItem1.SubItems[4].Text) + x < (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + float x = 0; + if (listViewItemCurrent.Text == "HEAD") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "BODY") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "ARM0") + x = 178; + else if (listViewItemCurrent.Text == "ARM1") + x = 228; + else if (listViewItemCurrent.Text == "LEG0") + x = 193; + else if (listViewItemCurrent.Text == "LEG1") + x = 213; + bool flag = false; + int index = listViewItemCurrent.Index; + foreach (ListViewItem listViewItem2 in listViewBoxes.Items) { - index = listViewItem2.Index + 1; - flag = true; + if (listViewItem2.SubItems[9].Text == "unchecked") + { + int y = 0; + if (listViewItem2.Text == "HEAD") + y = (int)surfaceCenter; + else if (listViewItem2.Text == "BODY") + y = (int)surfaceCenter; + else if (listViewItem2.Text == "ARM0") + y = 178; + else if (listViewItem2.Text == "ARM1") + y = 228; + else if (listViewItem2.Text == "LEG0") + y = 193; + else if (listViewItem2.Text == "LEG1") + y = 213; + if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) - x > (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + { + index = listViewItem2.Index + 1; + flag = true; + } + } + } + listViewItemCurrent.SubItems[9].Text = "checked"; + checkedItems += 1; + if (flag) + { + ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + listViewBoxes.Items.Insert(index, listViewItem2); + if (listViewBoxes.SelectedItems.Count != 0) + { + //if (selected.Index == listViewItem1.Index) + //{ + // selected = listViewItem2; + //} + } + listViewItemCurrent.Remove(); } } - } - listViewItem1.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag == true) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItem1.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) + else { - //if (selected.Index == listViewItem1.Index) - //{ - // selected = listViewItem2; - //} + checkedItems += 1; } - listViewItem1.Remove(); } - } - else - { - checkedItems += 1; - } + } while (checkedItems < listViewBoxes.Items.Count); } - } while (checkedItems < listViewBoxes.Items.Count); - } - else if (direction == eViewDirection.back) - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItemCurrent in this.listViewBoxes.Items) + break; + case ViewDirection.back: { - if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") + int checkedItems = 0; + do { - bool flag = false; - int index = listViewItemCurrent.Index; - foreach (ListViewItem listViewItemComparing in this.listViewBoxes.Items) + foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) { - if (listViewItemComparing.SubItems[9].Text == "unchecked" && (int)double.Parse(listViewItemCurrent.SubItems[3].Text) + (int)double.Parse(listViewItemCurrent.SubItems[6].Text) > (int)double.Parse(listViewItemComparing.SubItems[3].Text) + (int)double.Parse(listViewItemComparing.SubItems[6].Text)) + if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") { - if (listViewItemComparing.Index < this.listViewBoxes.Items.Count + 1) + bool flag = false; + int index = listViewItemCurrent.Index; + foreach (ListViewItem listViewItemComparing in listViewBoxes.Items) { - index = listViewItemComparing.Index + 1; - flag = true; + if (listViewItemComparing.SubItems[9].Text == "unchecked" && (int)double.Parse(listViewItemCurrent.SubItems[3].Text) + (int)double.Parse(listViewItemCurrent.SubItems[6].Text) > (int)double.Parse(listViewItemComparing.SubItems[3].Text) + (int)double.Parse(listViewItemComparing.SubItems[6].Text)) + { + if (listViewItemComparing.Index < listViewBoxes.Items.Count + 1) + { + index = listViewItemComparing.Index + 1; + flag = true; + } + } + } + listViewItemCurrent.SubItems[9].Text = "checked"; + checkedItems += 1; + if (flag) + { + ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + listViewBoxes.Items.Insert(index, listViewItem2); + if (listViewBoxes.SelectedItems.Count != 0) + { + //if (selected.Index == listViewItemCurrent.Index) + //{ + // selected = listViewItem2; + //} + } + listViewItemCurrent.Remove(); } } - } - listViewItemCurrent.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag == true) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) + else { - //if (selected.Index == listViewItemCurrent.Index) - //{ - // selected = listViewItem2; - //} + checkedItems += 1; } - listViewItemCurrent.Remove(); } - } - else - { - checkedItems += 1; - } + } while (checkedItems < listViewBoxes.Items.Count); } - } while (checkedItems < listViewBoxes.Items.Count); - } - else if (direction == eViewDirection.right) - { - int checkedItems = 0; - do - { - foreach (ListViewItem listViewItem1 in listViewBoxes.Items) + break; + case ViewDirection.left: { - if (listViewItem1.SubItems[listViewItem1.SubItems.Count - 1].Text == "unchecked") + int checkedItems = 0; + do { - float x = 0; - if (listViewItem1.Tag.ToString() == "HEAD") - x = displayBox.Width / 2; - else if (listViewItem1.Tag.ToString() == "BODY") - x = displayBox.Width / 2; - else if (listViewItem1.Tag.ToString() == "ARM0") - x = 178; - else if (listViewItem1.Tag.ToString() == "ARM1") - x = 228; - else if (listViewItem1.Tag.ToString() == "LEG0") - x = 193; - else if (listViewItem1.Tag.ToString() == "LEG1") - x = 213; - bool flag = false; - int index = listViewItem1.Index; - foreach (ListViewItem listViewItem2 in listViewBoxes.Items) + foreach (ListViewItem listViewItemCurrent in listViewBoxes.Items) { - if (listViewItem2.SubItems[9].Text == "unchecked") + if (listViewItemCurrent.SubItems[listViewItemCurrent.SubItems.Count - 1].Text == "unchecked") { - int y = 0; - if (listViewItem2.Tag.ToString() == "HEAD") - y = displayBox.Width / 2; - else if (listViewItem2.Tag.ToString() == "BODY") - y = displayBox.Width / 2; - else if (listViewItem2.Tag.ToString() == "ARM0") - y = 178; - else if (listViewItem2.Tag.ToString() == "ARM1") - y = 228; - else if (listViewItem2.Tag.ToString() == "LEG0") - y = 193; - else if (listViewItem2.Tag.ToString() == "LEG1") - y = 213; - if ((int)double.Parse(listViewItem1.SubItems[1].Text) + (int)double.Parse(listViewItem1.SubItems[4].Text) - x > (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + float x = 0; + if (listViewItemCurrent.Text == "HEAD") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "BODY") + x = surfaceCenter; + else if (listViewItemCurrent.Text == "ARM0") + x = 178; + else if (listViewItemCurrent.Text == "ARM1") + x = 228; + else if (listViewItemCurrent.Text == "LEG0") + x = 193; + else if (listViewItemCurrent.Text == "LEG1") + x = 213; + bool flag = false; + int index = listViewItemCurrent.Index; + foreach (ListViewItem listViewItem2 in listViewBoxes.Items) { - index = listViewItem2.Index + 1; - flag = true; + if (listViewItem2.SubItems[9].Text == "unchecked") + { + int y = 0; + if (listViewItem2.Text == "HEAD") + y = (int)surfaceCenter; + else if (listViewItem2.Text == "BODY") + y = (int)surfaceCenter; + else if (listViewItem2.Text == "ARM0") + y = 178; + else if (listViewItem2.Text == "ARM1") + y = 228; + else if (listViewItem2.Text == "LEG0") + y = 193; + else if (listViewItem2.Text == "LEG1") + y = 213; + if ((int)double.Parse(listViewItemCurrent.SubItems[1].Text) + (int)double.Parse(listViewItemCurrent.SubItems[4].Text) + x < (int)double.Parse(listViewItem2.SubItems[1].Text) + (int)double.Parse(listViewItem2.SubItems[4].Text) + y && listViewItem2.Index + 1 < this.listViewBoxes.Items.Count + 1) + { + index = listViewItem2.Index + 1; + flag = true; + } + } + } + listViewItemCurrent.SubItems[9].Text = "checked"; + checkedItems += 1; + if (flag == true) + { + ListViewItem listViewItem2 = (ListViewItem)listViewItemCurrent.Clone(); + listViewBoxes.Items.Insert(index, listViewItem2); + if (listViewBoxes.SelectedItems.Count != 0) + { + //if (selected.Index == listViewItem1.Index) + //{ + // selected = listViewItem2; + //} + } + listViewItemCurrent.Remove(); } } - } - listViewItem1.SubItems[9].Text = "checked"; - checkedItems += 1; - if (flag == true) - { - ListViewItem listViewItem2 = (ListViewItem)listViewItem1.Clone(); - listViewBoxes.Items.Insert(index, listViewItem2); - if (listViewBoxes.SelectedItems.Count != 0) + else { - //if (selected.Index == listViewItem1.Index) - //{ - // selected = listViewItem2; - //} + checkedItems += 1; } - listViewItem1.Remove(); } - } - else - { - checkedItems += 1; - } + } while (checkedItems < listViewBoxes.Items.Count); } - } while (checkedItems < listViewBoxes.Items.Count); + break; + default: + break; } } private void DrawGuideLines(Graphics g) { - int centerHeightPoint = displayBox.Height / 2; - int centerWidthPoint = displayBox.Width / 2; - int headbodyY = centerHeightPoint + 25; //25 - int legY = centerHeightPoint + 85; // - 80; - bool isSide = direction == eViewDirection.left || direction == eViewDirection.right; + Point center = new Point(displayBox.Height / 2, displayBox.Width / 2); + int headbodyY = center.Y + 25; //25 + int legY = center.Y + 85; // - 80; + bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; if (!isSide) { g.DrawLine(Pens.Red, 0, headbodyY + float.Parse(offsetHead.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetHead.Text) * 5); @@ -822,11 +838,11 @@ namespace PckStudio g.DrawLine(Pens.Blue, 0, headbodyY + float.Parse(offsetArms.Text) * 5, displayBox.Width, headbodyY + float.Parse(offsetArms.Text) * 5); g.DrawLine(Pens.Purple, 0, legY + float.Parse(offsetLegs.Text) * 5, displayBox.Width, legY + float.Parse(offsetLegs.Text) * 5); } - g.DrawLine(Pens.Red, centerWidthPoint, 0, centerWidthPoint, displayBox.Height); - g.DrawLine(Pens.Blue, centerWidthPoint + 30, 0, centerWidthPoint + 30, displayBox.Height); - g.DrawLine(Pens.Blue, centerWidthPoint - 30, 0, centerWidthPoint - 30, displayBox.Height); - g.DrawLine(Pens.Purple, centerWidthPoint - 10, 0, centerWidthPoint - 10, displayBox.Height); - g.DrawLine(Pens.Purple, centerWidthPoint + 10, 0, centerWidthPoint + 10, displayBox.Height); + g.DrawLine(Pens.Red, center.X, 0, center.X, displayBox.Height); + g.DrawLine(Pens.Blue, center.X + 30, 0, center.X + 30, displayBox.Height); + g.DrawLine(Pens.Blue, center.X - 30, 0, center.X - 30, displayBox.Height); + g.DrawLine(Pens.Purple, center.X - 10, 0, center.X - 10, displayBox.Height); + g.DrawLine(Pens.Purple, center.X + 10, 0, center .X + 10, displayBox.Height); } private void DrawArmorOffsets(Graphics g) @@ -838,7 +854,7 @@ namespace PckStudio int legY = centerPointHeight + 85; // - 80; SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(80, 50, 50, 75)); g.FillRectangle(semiTransBrush, centerPointWidth, (float)(headbodyY - 40 /*+ offsetHelmet.Value * 5*/), 40, 40); // Helmet - bool isSide = direction == eViewDirection.left || direction == eViewDirection.right; + bool isSide = direction == ViewDirection.left || direction == ViewDirection.right; if (isSide) { g.FillRectangle(semiTransBrush, centerPointWidth - 10, headbodyY, 20, 60); // Chest @@ -859,27 +875,21 @@ namespace PckStudio } - - //Loads Columns private void generateModel_Load(object sender, EventArgs e) { if (Screen.PrimaryScreen.Bounds.Height >= 780 && Screen.PrimaryScreen.Bounds.Width >= 1080) { return; } - render(); + Rerender(); } - - //Creates Item private void createToolStripMenuItem_Click(object sender, EventArgs e) { - modelBoxes.Add(SkinBOX.FromString("NEW_BOX 0 0 0 1 1 1 0 0 0 0 0")); - updateListView(); - render(); + modelBoxes.Add(SkinBOX.Empty); + UpdateListView(); + Rerender(); } - - //Manages the selection of a item private void listView1_SelectedIndexChanged(object sender, EventArgs e) { changeColorToolStripMenuItem.Visible = false; @@ -898,7 +908,7 @@ namespace PckStudio SizeZUpDown.Value = (decimal)part.Size.Z; TextureXUpDown.Value = (decimal)part.UV.X; TextureYUpDown.Value = (decimal)part.UV.Y; - render(); + Rerender(); } } @@ -921,7 +931,7 @@ namespace PckStudio TextureXUpDown.Enabled = true; TextureYUpDown.Enabled = true; } - //render(); + Rerender(); } private void SizeXUpDown_ValueChanged(object sender, EventArgs e) @@ -931,8 +941,8 @@ namespace PckStudio { part.Size.X = (float)SizeXUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } private void SizeYUpDown_ValueChanged(object sender, EventArgs e) @@ -942,8 +952,8 @@ namespace PckStudio { part.Size.Y = (float)SizeYUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } private void SizeZUpDown_ValueChanged(object sender, EventArgs e) @@ -953,8 +963,8 @@ namespace PckStudio { part.Size.Z = (float)SizeZUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } private void PosXUpDown_ValueChanged(object sender, EventArgs e) @@ -964,8 +974,8 @@ namespace PckStudio { part.Pos.X = (float)PosXUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } @@ -976,8 +986,8 @@ namespace PckStudio { part.Pos.Y = (float)PosYUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } @@ -988,36 +998,28 @@ namespace PckStudio { part.Pos.Z = (float)PosZUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } private void rotateRightBtn_Click(object sender, EventArgs e) { - if (direction == eViewDirection.front) - direction = eViewDirection.left; - else if (direction == eViewDirection.left) - direction = eViewDirection.back; - else if (direction == eViewDirection.back) - direction = eViewDirection.right; - else if (direction == eViewDirection.right) - direction = eViewDirection.front; + if (direction == ViewDirection.front) + direction = ViewDirection.left; + else + --direction; labelView.Text = $"View: {direction}"; - render(); + Rerender(); } private void rotateLeftBtn_Click(object sender, EventArgs e) { - if (direction == eViewDirection.front) - direction = eViewDirection.right; - else if (direction == eViewDirection.right) - direction = eViewDirection.back; - else if (direction == eViewDirection.back) - direction = eViewDirection.left; - else if (direction == eViewDirection.left) - direction = eViewDirection.front; + if (direction == ViewDirection.left) + direction = ViewDirection.front; + else + ++direction; labelView.Text = $"View: {direction}"; - render(); + Rerender(); } @@ -1029,8 +1031,8 @@ namespace PckStudio { part.UV.X = (int)TextureXUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } @@ -1042,28 +1044,27 @@ namespace PckStudio { part.UV.Y = (int)TextureYUpDown.Value; } - updateListView(); - render(); + UpdateListView(); + Rerender(); } //Export Current Skin Texture private void buttonEXPORT_Click(object sender, EventArgs e) { - Bitmap bitmap = new Bitmap(texturePreview.Image, 64, 64); - SaveFileDialog saveFileDialog = new SaveFileDialog(); + Bitmap bitmap = new Bitmap(uvPictureBox.Image, 64, 64); + using SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PNG Image Files | *.png"; - if (saveFileDialog.ShowDialog() != DialogResult.OK) - return; - bitmap.Save(saveFileDialog.FileName, ImageFormat.Png); - saveFileDialog.Dispose(); + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + bitmap.Save(saveFileDialog.FileName, ImageFormat.Png); + } } //Imports Skin Texture private void buttonIMPORT_Click(object sender, EventArgs e) { - OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "PNG Image Files | *.png"; openFileDialog.Title = "Select Skin Texture"; @@ -1074,15 +1075,14 @@ namespace PckStudio { if ((img.Width == img.Height || img.Height == img.Width / 2)) { - checkTextureGenerate.Checked = false; - Bitmap bitmap = new Bitmap(img.Width, img.Width); - using (Graphics graphics = Graphics.FromImage(bitmap)) + generateTextureCheckBox.Checked = false; + using (Graphics graphics = Graphics.FromImage(uvPictureBox.Image)) { + graphics.ApplyConfig(_graphicsConfig); graphics.DrawImage(img, 0, 0, img.Width, img.Height); - graphics.InterpolationMode = InterpolationMode.NearestNeighbor; } - texturePreview.Image = bitmap; - render(); + uvPictureBox.Invalidate(); + Rerender(); } else { @@ -1092,54 +1092,51 @@ namespace PckStudio } } - - //Creates Model Data and Finalizes + // Creates Model Data and Finalizes private void buttonDone_Click(object sender, EventArgs e) { - Bitmap bitmap1 = new Bitmap(displayBox.Width, displayBox.Height); foreach (var part in modelBoxes) { - boxes.Add("BOX", part); + _file.Properties.Add("BOX", part); } - Bitmap bitmap2 = new Bitmap(64, 64); - using (Graphics graphics = Graphics.FromImage(bitmap2)) - { - graphics.DrawImage(texturePreview.Image, 0, 0, 64, 64); - graphics.InterpolationMode = InterpolationMode.NearestNeighbor; - } - skinPreview.Image = bitmap1; - texturePreview.Image.Save(Application.StartupPath + "\\temp.png"); + //Bitmap bitmap2 = new Bitmap(64, 64); + //using (Graphics graphics = Graphics.FromImage(bitmap2)) + //{ + // graphics.ApplyConfig(_graphicsConfig); + // graphics.DrawImage(uvPictureBox.Image, 0, 0, 64, 64); + //} + _previewImage = new Bitmap(displayBox.Width, displayBox.Height); Close(); } - //Renders model after texture change + // Renders model after texture change private void texturePreview_BackgroundImageChanged(object sender, EventArgs e) { - render(); + Rerender(); } - //Trigger Dialog to select model part/item color + // Trigger Dialog to select model part/item color private void listView1_DoubleClick(object sender, EventArgs e) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == DialogResult.OK) listViewBoxes.SelectedItems[0].ForeColor = colorDialog.Color; - render(); + Rerender(); } //Re-renders head with updated x-offset private void offsetHead_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Re-renders body with updated x-offset private void offsetBody_TextAlignChanged(object sender, EventArgs e) { - render(); + Rerender(); } @@ -1153,11 +1150,11 @@ namespace PckStudio modelBoxes.Add(SkinBOX.FromString("LEG0 -2 0 -2 4 12 4 0 16 0 0 0")); modelBoxes.Add(SkinBOX.FromString("LEG1 -2 0 -2 4 12 4 0 16 0 1 0")); comboParent.Enabled = true; - updateListView(); - render(); + UpdateListView(); + Rerender(); } - private void updateListView() + private void UpdateListView() { listViewBoxes.Items.Clear(); foreach (var part in modelBoxes) @@ -1176,7 +1173,7 @@ namespace PckStudio } } - //Exports model (int)doubleo reusable project file + // Exports model as csm file private void buttonExportModel_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); @@ -1199,7 +1196,7 @@ namespace PckStudio } - //Imports model from reusable project file + // Imports model from csm file private void buttonImportModel_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); @@ -1232,12 +1229,10 @@ namespace PckStudio } } comboParent.Enabled = true; - updateListView(); - render(); + UpdateListView(); + Rerender(); } - - //Clones Item private void cloneToolStripMenuItem_Click(object sender, EventArgs e) { try @@ -1262,53 +1257,50 @@ namespace PckStudio } } - - //Deletes Item private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewBoxes.SelectedItems[0] == null) return; listViewBoxes.SelectedItems[0].Remove(); - render(); + Rerender(); } - //Changes item color private void changeColorToolStripMenuItem_Click(object sender, EventArgs e) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == DialogResult.OK) listViewBoxes.SelectedItems[0].ForeColor = colorDialog.Color; - render(); + Rerender(); } //Re-renders tool with updated x-offset private void offsetTool_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Re-renders helmet with updated x-offset private void offsetHelmet_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Re-renders pants with updated x-offset private void offsetPants_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Re-renders leggings with updated x-offset private void offsetLeggings_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Re-renders boots with updated x-offset private void offsetBoots_TextChanged(object sender, EventArgs e) { - render(); + Rerender(); } //Item Selection @@ -1346,7 +1338,7 @@ namespace PckStudio TextureXUpDown.Enabled = false; TextureYUpDown.Enabled = false; comboParent.Enabled = false; - render(); + Rerender(); } //currently scrapped @@ -1368,16 +1360,16 @@ namespace PckStudio { if (modelBoxes.Remove(part)) listViewBoxes.SelectedItems[0].Remove(); - render(); + Rerender(); } } private void generateModel_SizeChanged(object sender, EventArgs e) { - render(); + Rerender(); } - + // TODO private void OpenJSONButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); @@ -1399,101 +1391,100 @@ namespace PckStudio ++num3; } while (num3 < y); - IEnumerator enumerator = listView.Items.GetEnumerator(); - try + + + foreach (ListViewItem current in listView.Items) { - label_33: - if (enumerator.MoveNext()) - { - ListViewItem current = (ListViewItem)enumerator.Current; - ListViewItem listViewItem = new ListViewItem(); - int num4 = 0; - do + ListViewItem listViewItem = new ListViewItem(); + int num4 = 0; + foreach (string text in str1.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { - foreach (string text in str1.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) + ++num4; + if (num4 == 1 + 11 * current.Index) + listViewItem.Text = text; + else if (num4 == 2 + 11 * current.Index) + listViewItem.Tag = text; + else if (num4 == 4 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 5 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 6 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 7 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 8 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 9 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 10 + 11 * current.Index) + listViewItem.SubItems.Add(text); + else if (num4 == 11 + 11 * current.Index) { - ++num4; - if (num4 == 1 + 11 * current.Index) - listViewItem.Text = text; - else if (num4 == 2 + 11 * current.Index) - listViewItem.Tag = (object)text; - else if (num4 == 4 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 5 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 6 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 7 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 8 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 9 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 10 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 11 + 11 * current.Index) - { - listViewItem.SubItems.Add(text); - this.listViewBoxes.Items.Add(listViewItem); - } + listViewItem.SubItems.Add(text); + listViewBoxes.Items.Add(listViewItem); } } - while (num4 < x); - goto label_33; - } - } - finally - { - IDisposable disposable = enumerator as IDisposable; - if (disposable != null) - disposable.Dispose(); } } - render(); + Rerender(); } + [Obsolete("Just whyyyyy")] public string JSONToCSM(string InputFilePath) { - dynamic jsonDe = JsonConvert.DeserializeObject(File.ReadAllText(InputFilePath)); - string CSMData = ""; - foreach (CSMJObjectGroup group in jsonDe.groups) + CSMJObject jsonDe = JsonConvert.DeserializeObject(File.ReadAllText(InputFilePath)); + StringBuilder sb = new StringBuilder(); + foreach (CSMJObjectGroup group in jsonDe.Groups) { - string PARENT = group.name; + string PARENT = group.Name; foreach (int i in group.children) { - string name = jsonDe.elements[i].name; - float PosX = jsonDe.elements[i].from[0] + group.origin[0]; - float PosY = jsonDe.elements[i].from[1] + group.origin[1]; - float PosZ = jsonDe.elements[i].from[2] + group.origin[2]; - float SizeX = jsonDe.elements[i].to[0] - jsonDe.elements[i].from[0]; - float SizeY = jsonDe.elements[i].to[1] - jsonDe.elements[i].from[1]; - float SizeZ = jsonDe.elements[i].to[2] - jsonDe.elements[i].from[2]; + string name = jsonDe.Elements[i].Name; + float PosX = jsonDe.Elements[i].from[0] + group.origin[0]; + float PosY = jsonDe.Elements[i].from[1] + group.origin[1]; + float PosZ = jsonDe.Elements[i].from[2] + group.origin[2]; + float SizeX = jsonDe.Elements[i].to[0] - jsonDe.Elements[i].from[0]; + float SizeY = jsonDe.Elements[i].to[1] - jsonDe.Elements[i].from[1]; + float SizeZ = jsonDe.Elements[i].to[2] - jsonDe.Elements[i].from[2]; float U = 0; float V = 0; - CSMData += name + "\n" + PARENT + "\n" + name + "\n" + PosX + "\n" + PosY + "\n" + PosZ + "\n" + SizeX + "\n" + SizeY + "\n" + SizeZ + "\n" + U + "\n" + V + "\n"; + sb.AppendLine(name + "\n" + PARENT + "\n" + name + "\n" + PosX + "\n" + PosY + "\n" + PosZ + "\n" + SizeX + "\n" + SizeY + "\n" + SizeZ + "\n" + U + "\n" + V); } } - return CSMData; + return sb.ToString(); } } class CSMJObject { - public string credit; - public int[] texture_size; - public CSMJObjectElement[] elements; - public CSMJObjectGroup[] groups; + [JsonProperty("credit")] + public string Credit { get; set; } + + [JsonProperty("texture_size")] + public int[] TextureSize; + + [JsonProperty("elements")] + public CSMJObjectElement[] Elements; + + [JsonProperty("groups")] + public CSMJObjectGroup[] Groups; } + class CSMJObjectElement { - public string name; + [JsonProperty("name")] + public string Name { get; set; } + public float[] from; public float[] to; } + class CSMJObjectGroup { - public string name; + [JsonProperty("name")] + public string Name { get; set; } + public float[] origin; public int[] children; } diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx b/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx index 13b60d8d..1fa4fc59 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.resx @@ -117,10 +117,177 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + False + + + + True + + + + NoControl + + + + 23, 459 + + + 38, 13 + + + 137 + + + Parent + + + label6 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 22 + + + False + + + True + + + NoControl + + + 691, 357 + + + 44, 13 + + + 127 + + + Position + + + label5 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 31 + + + False + + + True + + + NoControl + + + 691, 259 + + + 27, 13 + + + 142 + + + Size + + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 30 + + + False + + + True + + + NoControl + + + 654, 236 + + + 22, 13 + + + 131 + + + UV + + + label7 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 25 + + + False + + + True + + + NoControl + + + 655, 56 + + + 128, 13 + + + 113 + + + Texture Mapping Preview + + + labelTextureMappingPreview + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 19 + 17, 17 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -199,7 +366,6 @@ System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Flat @@ -212,7 +378,6 @@ 130, 22 - 111 @@ -696,36 +861,6 @@ 24 - - True - - - NoControl - - - 23, 459 - - - 38, 13 - - - 137 - - - Parent - - - label6 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 22 - HEAD @@ -765,66 +900,6 @@ 21 - - True - - - NoControl - - - 691, 357 - - - 44, 13 - - - 127 - - - Position - - - label5 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 31 - - - True - - - NoControl - - - 691, 259 - - - 27, 13 - - - 142 - - - Size - - - label3 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 30 - Flat @@ -855,36 +930,6 @@ 18 - - True - - - NoControl - - - 654, 236 - - - 22, 13 - - - 131 - - - UV - - - label7 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 25 - Flat @@ -915,63 +960,33 @@ 23 - + NoControl - + 655, 72 - + 128, 128 - + Zoom - + 112 - - texturePreview + + uvPictureBox - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + PckStudio.PictureBoxWithInterpolationMode, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null - + $this - + 20 - - True - - - NoControl - - - 655, 56 - - - 128, 13 - - - 113 - - - Texture Mapping Preview - - - labelTextureMappingPreview - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 19 - Flat @@ -1113,31 +1128,31 @@ 12 - + True - + 23, 556 - + 140, 15 - + 147 - + Auto Generate Texture - - checkTextureGenerate + + generateTextureCheckBox - + MetroFramework.Controls.MetroCheckBox, MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a - + $this - + 11 diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 15632136..4aeb16a1 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -74,13 +74,6 @@ namespace PckStudio labelVersion.Text = $"{Application.ProductName}: {Application.ProductVersion}"; ChangelogRichTextBox.Text = Resources.CHANGELOG; -#if BETA - labelVersion.Text += $"{ApplicationBuildInfo.BetaBuildVersion}@{CommitInfo.BranchName}"; -#endif -#if DEBUG - labelVersion.Text += $" (Debug build: {CommitInfo.BranchName}@{CommitInfo.CommitHash})"; -#endif - pckFileTypeHandler = new Dictionary>(15) { [PckFile.FileData.FileType.SkinFile] = HandleSkinFile, @@ -437,22 +430,22 @@ namespace PckStudio public void HandleSkinFile(PckFile.FileData file) { - using (var ms = new MemoryStream(file.Data)) + if (file.Properties.HasProperty("BOX")) { - var texture = Image.FromStream(ms); - if (file.Properties.HasProperty("BOX")) + using generateModel generate = new generateModel(file); + if (generate.ShowDialog() == DialogResult.OK) { - using generateModel generate = new generateModel(file.Properties, texture); - if (generate.ShowDialog() == DialogResult.OK) - { - entryDataTextBox.Text = entryTypeTextBox.Text = string.Empty; - wasModified = true; - ReloadMetaTreeView(); - } - return; + entryDataTextBox.Text = entryTypeTextBox.Text = string.Empty; + wasModified = true; + ReloadMetaTreeView(); } - - var skinViewer = new SkinPreview(texture, file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString)); + return; + } + + using(var ms = new MemoryStream(file.Data)) + { + var img = Image.FromStream(ms); + var skinViewer = new SkinPreview(img, file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString)); skinViewer.ShowDialog(this); skinViewer.Dispose(); } diff --git a/PCK-Studio/PckNodeSorter.cs b/PCK-Studio/PckNodeSorter.cs index 67ff8d37..b2568055 100644 --- a/PCK-Studio/PckNodeSorter.cs +++ b/PCK-Studio/PckNodeSorter.cs @@ -1,42 +1,56 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; using System.Windows.Forms; using OMI.Formats.Pck; namespace PckStudio { - public class PckNodeSorter : System.Collections.IComparer, IComparer + public class PckNodeSorter : IComparer, IComparer { private bool CheckForSkinAndCapeFiles(TreeNode node) { - if (node.Tag is PckFile.FileData file) + if (IsPckFile(node, out PckFile.FileData file)) + return file.Filetype == PckFile.FileData.FileType.SkinFile || file.Filetype == PckFile.FileData.FileType.CapeFile; + return false; + } + + private bool IsPckFile(TreeNode node) => IsPckFile(node, out _); + private bool IsPckFile(TreeNode node, out PckFile.FileData file) + { + if (node.Tag is PckFile.FileData _file) { - return file.Filetype == PckFile.FileData.FileType.SkinFile || - file.Filetype == PckFile.FileData.FileType.CapeFile; + file = _file; + return true; } + file = null; return false; } public int Compare(TreeNode first, TreeNode second) { - // ignore these files in order to preserve skin(and cape) files - if (CheckForSkinAndCapeFiles(first)) - { - return 0; - } - if (CheckForSkinAndCapeFiles(second)) - { - return 0; - } + if (IsPckFile(first) && !IsPckFile(second)) + return -1; + if (!IsPckFile(first) && IsPckFile(second)) + return 1; - int result = first.Text.CompareTo(second.Text); - if (result != 0) return result; - return first.ImageIndex.CompareTo(second.ImageIndex); + if (CheckForSkinAndCapeFiles(first)) + return -1; + if (CheckForSkinAndCapeFiles(second)) + return 1; + + return first.Text.CompareTo(second.Text); + // weird fail save + //return first.ImageIndex.CompareTo(second.ImageIndex); } - int System.Collections.IComparer.Compare(object x, object y) + int IComparer.Compare(object x, object y) { - return x is TreeNode NodeX && y is TreeNode NodeY ? Compare(NodeX, NodeY) : 0; + if (x is not TreeNode NodeX) + return -1; + if (y is not TreeNode NodeY) + return 1; + return Compare(NodeX, NodeY); } } } \ No newline at end of file diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index c9dfbc34..6d5ceed9 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -1,5 +1,5 @@  - + preview @@ -18,45 +18,6 @@ false true - - - - - - - - - - $(GitHash) - $(GitBranch) - - - - - - $(IntermediateOutputPath)GitAssemblyInfo.cs - - - - - - - - - <_Parameter1>GitHash - <_Parameter2>$(BuildHash) - - - <_Parameter1>GitBranch - <_Parameter2>$(BuildBranch) - - - - - - - - Debug AnyCPU @@ -807,4 +768,57 @@ --> + + + + + + + + + + + + $(GitHash) + $(GitBranch) + + + + + + $(IntermediateOutputPath)GitAssemblyInfo.cs + + + + + + + + + <_Parameter1>GitHash + <_Parameter2>$(BuildHash) + + + <_Parameter1>GitBranch + <_Parameter2>$(BuildBranch) + + + + + + + + + + + + + $([System.DateTime]::Now.ToString('yyyy-MM-dd')) + + + + \ No newline at end of file diff --git a/PCK-Studio/Program.cs b/PCK-Studio/Program.cs index a086894c..fd1dad39 100644 --- a/PCK-Studio/Program.cs +++ b/PCK-Studio/Program.cs @@ -11,7 +11,7 @@ namespace PckStudio public static readonly string ProjectUrl = "https://github.com/PhoenixARC/-PCK-Studio"; public static readonly string BaseAPIUrl = "http://api.pckstudio.xyz/api/pck"; public static readonly string BackUpAPIUrl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/"; - public static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PCK-Studio"); + public static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.ProductName); public static readonly string AppDataCache = Path.Combine(AppData, "cache"); public static MainForm MainInstance { get; private set; }