Refactored BoxEditor small

This commit is contained in:
miku-666
2022-12-02 20:55:50 +01:00
parent 6d1436ba84
commit ef9a337320
4 changed files with 60 additions and 63 deletions

View File

@@ -67,7 +67,7 @@
this.closeButton.Text = "Save";
this.closeButton.Theme = MetroFramework.MetroThemeStyle.Dark;
this.closeButton.UseSelectable = true;
this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
this.closeButton.Click += new System.EventHandler(this.saveButton_Click);
//
// toolTip
//

View File

@@ -1,62 +1,53 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using PckStudio.Classes.Utils;
namespace PckStudio.Forms.Utilities.Skins
{
public partial class BoxEditor : MetroFramework.Forms.MetroForm
{
public bool saved = false;
public string out_box;
public string Result;
class BOX
{
public BOX(string inBOX)
public string Parent;
public (float X, float Y, float Z) Pos;
public (float X, float Y, float Z) Size;
public float uvX, uvY;
public bool HideWithArmor;
public bool Mirror;
public float Inflation;
public BOX(string input)
{
string[] arguments = inBOX.Split(' ');
string[] arguments = Regex.Split(input, @"\s+");
try
{
parent = arguments[0];
posX = float.Parse(arguments[1]);
posY = float.Parse(arguments[2]);
posZ = float.Parse(arguments[3]);
sizeX = float.Parse(arguments[4]);
sizeY = float.Parse(arguments[5]);
sizeZ = float.Parse(arguments[6]);
Parent = arguments[0];
Pos.X = float.Parse(arguments[1]);
Pos.Y = float.Parse(arguments[2]);
Pos.Z = float.Parse(arguments[3]);
Size.X = float.Parse(arguments[4]);
Size.Y = float.Parse(arguments[5]);
Size.Z = float.Parse(arguments[6]);
uvX = float.Parse(arguments[7]);
uvY = float.Parse(arguments[8]);
hideWithArmor = arguments[9] == "1";
mirror = arguments[10] == "1";
inflation = float.Parse(arguments[11]);
HideWithArmor = arguments[9] == "1";
Mirror = arguments[10] == "1";
Inflation = float.Parse(arguments[11]);
}
catch (IndexOutOfRangeException ex2)
catch (IndexOutOfRangeException)
{
// This is normal as some box values can have less parameters but no more than 12
return;
}
catch (Exception ex)
{
parent = "invalid";
Parent = string.Empty;
}
}
public string parent;
public float posX, posY, posZ;
public float sizeX, sizeY, sizeZ;
public float uvX, uvY;
public bool hideWithArmor;
public bool mirror;
public float inflation;
}
public BoxEditor(string inBOX, bool hasInflation)
@@ -67,44 +58,35 @@ namespace PckStudio.Forms.Utilities.Skins
BOX box = new BOX(inBOX);
if (box.parent == "invalid" || !parentComboBox.Items.Contains(box.parent))
if (string.IsNullOrEmpty(box.Parent) || !parentComboBox.Items.Contains(box.Parent))
{
throw new Exception("Failed to parse BOX value");
}
parentComboBox.SelectedItem = parentComboBox.Items[parentComboBox.Items.IndexOf(box.parent)];
PosXUpDown.Value = (decimal)box.posX;
PosYUpDown.Value = (decimal)box.posY;
PosZUpDown.Value = (decimal)box.posZ;
SizeXUpDown.Value = (decimal)box.sizeX;
SizeYUpDown.Value = (decimal)box.sizeY;
SizeZUpDown.Value = (decimal)box.sizeZ;
parentComboBox.SelectedItem = parentComboBox.Items[parentComboBox.Items.IndexOf(box.Parent)];
PosXUpDown.Value = (decimal)box.Pos.X;
PosYUpDown.Value = (decimal)box.Pos.Y;
PosZUpDown.Value = (decimal)box.Pos.Z;
SizeXUpDown.Value = (decimal)box.Size.X;
SizeYUpDown.Value = (decimal)box.Size.Y;
SizeZUpDown.Value = (decimal)box.Size.Z;
uvXUpDown.Value = (decimal)box.uvX;
uvYUpDown.Value = (decimal)box.uvY;
armorCheckBox.Checked = box.hideWithArmor;
mirrorCheckBox.Checked = box.mirror;
inflationUpDown.Value = (decimal)box.inflation;
armorCheckBox.Checked = box.HideWithArmor;
mirrorCheckBox.Checked = box.Mirror;
inflationUpDown.Value = (decimal)box.Inflation;
}
private void closeButton_Click(object sender, EventArgs e)
private void saveButton_Click(object sender, EventArgs e)
{
out_box =
parentComboBox.SelectedItem.ToString() + " " +
PosXUpDown.Value.ToString() + " " +
PosYUpDown.Value.ToString() + " " +
PosZUpDown.Value.ToString() + " " +
SizeXUpDown.Value.ToString() + " " +
SizeYUpDown.Value.ToString() + " " +
SizeZUpDown.Value.ToString() + " " +
uvXUpDown.Value.ToString() + " " +
uvYUpDown.Value.ToString() + " " +
(armorCheckBox.Checked ? "1 " : "0 ") +
(mirrorCheckBox.Checked ? "1 " : "0 ") +
inflationUpDown.Value.ToString();
saved = true;
Result =
$"{parentComboBox.SelectedItem} " +
$"{PosXUpDown.Value} {PosYUpDown.Value} {PosZUpDown.Value} " +
$"{SizeXUpDown.Value} {SizeYUpDown.Value} {SizeZUpDown.Value} " +
$"{uvXUpDown.Value} {uvYUpDown.Value} " +
$"{(mirrorCheckBox.Checked ? "1 " : "0 ")} {(mirrorCheckBox.Checked ? "1 " : "0 ")} " +
$"{inflationUpDown.Value}";
DialogResult = DialogResult.OK;
Close();
}
}

View File

@@ -120,4 +120,19 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="parentLabel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="positionLabel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sizeLabel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="uvLabel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="inflationLabel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View File

@@ -969,7 +969,7 @@ namespace PckStudio
using BoxEditor diag = new BoxEditor(property.Item2, IsSubPCKNode(treeViewMain.SelectedNode.FullPath));
if (diag.ShowDialog(this) == DialogResult.OK)
{
file.properties[i] = new ValueTuple<string, string>("BOX", diag.out_box);
file.properties[i] = new ValueTuple<string, string>("BOX", diag.Result);
if (IsSubPCKNode(treeViewMain.SelectedNode.FullPath))
RebuildSubPCK(treeViewMain.SelectedNode);
ReloadMetaTreeView();