Some fixes.

USD1 fixes and also start to impliment an editor for USD1.
Fix L8 and LA8 displaying.
Fix channel compents. Temporaily uses the swizzle parameter. Todo, do these by shader.
Material saving fixes for bflyt version 8 and higher
This commit is contained in:
KillzXGaming 2019-09-03 18:58:58 -04:00
parent 74f69eb1d8
commit 4a92d0320a
18 changed files with 1367 additions and 121 deletions

View file

@ -237,7 +237,6 @@ namespace LayoutBXLYT.Cafe
public MAT1 MaterialList { get; set; }
public FNL1 FontList { get; set; }
public CNT1 Container { get; set; }
public USD1 UserData { get; set; }
//As of now this should be empty but just for future proofing
private List<SectionCommon> UnknownSections = new List<SectionCommon>();
@ -414,7 +413,7 @@ namespace LayoutBXLYT.Cafe
Container = new CNT1(reader, this);
break;*/
case "usd1":
UserData = new USD1(reader, this);
((PAN1)currentPane).UserData = new USD1(reader, this);
break;
//If the section is not supported store the raw bytes
default:
@ -474,12 +473,6 @@ namespace LayoutBXLYT.Cafe
WritePanes(writer, RootPane, this, ref sectionCount);
WriteGroupPanes(writer, RootGroup, this, ref sectionCount);
if (UserData != null)
{
WriteSection(writer, "usd1", UserData, () => UserData.Write(writer, this));
sectionCount++;
}
foreach (var section in UnknownSections)
{
WriteSection(writer, section.Signature, section, () => section.Write(writer, this));
@ -504,6 +497,13 @@ namespace LayoutBXLYT.Cafe
WriteSection(writer, pane.Signature, pane,() => pane.Write(writer, header));
sectionCount++;
if (pane is IUserDataContainer && ((IUserDataContainer)pane).UserData != null)
{
var userData = ((IUserDataContainer)pane).UserData;
WriteSection(writer, "usd1", userData, () => userData.Write(writer, this));
sectionCount++;
}
if (pane.HasChildern)
{
sectionCount += 2;
@ -1183,11 +1183,9 @@ namespace LayoutBXLYT.Cafe
}
}
public class USD1 : SectionCommon
public class USD1 : UserData
{
public List<UserDataEntry> Entries = new List<UserDataEntry>();
public USD1(FileReader reader, Header header)
public USD1(FileReader reader, Header header) : base()
{
long startPos = reader.Position - 8;
@ -1195,7 +1193,7 @@ namespace LayoutBXLYT.Cafe
reader.ReadUInt16(); //padding
for (int i = 0; i < numEntries; i++)
Entries.Add(new UserDataEntry(reader, startPos, header));
Entries.Add(new USD1Entry(reader, startPos, header));
}
public override void Write(FileWriter writer, BxlytHeader header)
@ -1205,60 +1203,42 @@ namespace LayoutBXLYT.Cafe
writer.Write((ushort)Entries.Count);
writer.Write((ushort)0);
long enryPos = writer.Position;
for (int i = 0; i < Entries.Count; i++)
Entries[i].Write(writer, startPos, header);
((USD1Entry)Entries[i]).Write(writer, header);
for (int i = 0; i < Entries.Count; i++)
{
writer.WriteUint32Offset(Entries[i]._pos + 4, Entries[i]._pos);
switch (Entries[i].Type)
{
case UserDataType.String:
writer.WriteString(Entries[i].GetString());
break;
case UserDataType.Int:
writer.Write(Entries[i].GetInts());
break;
case UserDataType.Float:
writer.Write(Entries[i].GetFloats());
break;
}
writer.WriteUint32Offset(Entries[i]._pos, Entries[i]._pos);
writer.WriteString(Entries[i].Name);
}
}
}
public class UserDataEntry
public class USD1Entry : UserDataEntry
{
public string Name { get; set; }
public DataType Type { get; private set; }
public byte Unknown { get; set; }
private object data;
public string GetString()
{
return (string)data;
}
public float[] GetFloats()
{
return (float[])data;
}
public int[] GetInts()
{
return (int[])data;
}
public void SetStrings(string[] value)
{
data = value;
Type = DataType.String;
}
public void GetFloats(float [] value)
{
data = value;
Type = DataType.Float;
}
public void GetInts(int[] value)
{
data = value;
Type = DataType.Int;
}
public UserDataEntry(FileReader reader, long startPos, Header header)
public USD1Entry(FileReader reader, long startPos, Header header)
{
long pos = reader.Position;
uint nameOffset = reader.ReadUInt32();
uint dataOffset = reader.ReadUInt32();
ushort dataLength = reader.ReadUInt16();
Type = reader.ReadEnum<DataType>(false);
Type = reader.ReadEnum<UserDataType>(false);
Unknown = reader.ReadByte();
long datapos = reader.Position;
@ -1274,16 +1254,16 @@ namespace LayoutBXLYT.Cafe
reader.SeekBegin(pos + dataOffset);
switch (Type)
{
case DataType.String:
case UserDataType.String:
if (dataLength != 0)
data = reader.ReadString((int)dataLength);
else
data = reader.ReadZeroTerminatedString();
break;
case DataType.Int:
case UserDataType.Int:
data = reader.ReadInt32s((int)dataLength);
break;
case DataType.Float:
case UserDataType.Float:
data = reader.ReadSingles((int)dataLength);
break;
}
@ -1292,32 +1272,15 @@ namespace LayoutBXLYT.Cafe
reader.SeekBegin(datapos);
}
public void Write(FileWriter writer, long startPos, BxlytHeader header)
public void Write(FileWriter writer, BxlytHeader header)
{
long pos = writer.Position;
_pos = writer.Position;
writer.Write(0); //nameOffset
writer.Write(0); //dataOffset
writer.Write(GetDataLength());
writer.Write((ushort)GetDataLength());
writer.Write(Type, false);
writer.Write(Unknown);
writer.WriteUint32Offset(pos + 4, pos);
switch (Type)
{
case DataType.String:
writer.Write((string)data);
break;
case DataType.Int:
writer.Write((int[])data);
break;
case DataType.Float:
writer.Write((float[])data);
break;
}
writer.WriteUint32Offset(pos, pos);
writer.WriteString(Name);
}
private int GetDataLength()
@ -1330,13 +1293,6 @@ namespace LayoutBXLYT.Cafe
return ((float[])data).Length;
return 0;
}
public enum DataType : byte
{
String,
Int,
Float,
}
}
public class PIC1 : PAN1
@ -1431,7 +1387,7 @@ namespace LayoutBXLYT.Cafe
}
}
public class PAN1 : BasePane
public class PAN1 : BasePane, IUserDataContainer
{
public override string Signature { get; } = "pan1";
@ -1510,9 +1466,12 @@ namespace LayoutBXLYT.Cafe
[DisplayName("Parts Flag"), CategoryAttribute("Flags")]
public byte PaneMagFlags { get; set; }
[DisplayName("User Data"), CategoryAttribute("User Data")]
[DisplayName("User Data Info"), CategoryAttribute("User Data")]
public string UserDataInfo { get; set; }
[DisplayName("User Data"), CategoryAttribute("User Data")]
public UserData UserData { get; set; }
public PAN1() : base()
{

View file

@ -13,7 +13,10 @@ namespace LayoutBXLYT.Cafe
{
GenType = reader.ReadEnum<MatrixType>(false);
Source = reader.ReadEnum<TextureGenerationType>(false);
unkData = reader.ReadBytes(6);
if (header.VersionMajor >= 8)
unkData = reader.ReadBytes(0xE);
else
unkData = reader.ReadBytes(6);
}
public void Write(FileWriter writer)

View file

@ -141,8 +141,8 @@ namespace LayoutBXLYT
public bool IsHit(int X, int Y)
{
if ((X > Rectangle.X) && (X < Rectangle.X + Rectangle.Width) &&
(Y > Rectangle.Y) && (Y < Rectangle.Y + Rectangle.Height))
if ((X > Translate.X) && (X < Translate.X + Width) &&
(Y > Translate.Y) && (Y < Translate.Y + Height))
return true;
else
return false;
@ -163,6 +163,76 @@ namespace LayoutBXLYT
Bottom = 2
};
public interface IUserDataContainer
{
UserData UserData { get; set; }
}
public class UserData : SectionCommon
{
public List<UserDataEntry> Entries { get; set; }
public UserData()
{
Entries = new List<UserDataEntry>();
}
public override void Write(FileWriter writer, BxlytHeader header)
{
}
}
public class UserDataEntry
{
public string Name { get; set; }
public UserDataType Type { get; set; }
public byte Unknown { get; set; }
public object data;
public string GetString()
{
return (string)data;
}
public float[] GetFloats()
{
return (float[])data;
}
public int[] GetInts()
{
return (int[])data;
}
public void SetValue(string[] value)
{
data = value;
Type = UserDataType.String;
}
public void SetValue(float[] value)
{
data = value;
Type = UserDataType.Float;
}
public void SetValue(int[] value)
{
data = value;
Type = UserDataType.Int;
}
internal long _pos;
}
public enum UserDataType : byte
{
String,
Int,
Float,
}
public class BxlytHeader : IDisposable
{
public string FileName
@ -262,16 +332,6 @@ namespace LayoutBXLYT
BottomPoint = bottom;
}
public float X
{
get { return Width / 2; }
}
public float Y
{
get { return Height / 2; }
}
public float Width
{
get { return LeftPoint - RightPoint; }

View file

@ -328,6 +328,7 @@
<Compile Include="GL\GXToOpenGL.cs" />
<Compile Include="GL\KCL_Render.cs" />
<Compile Include="GL\LM2_Render.cs" />
<Compile Include="GUI\BFLYT\BflytShader.cs" />
<Compile Include="GUI\BFLYT\FileSelector.cs">
<SubType>Form</SubType>
</Compile>
@ -364,6 +365,18 @@
<Compile Include="GUI\BFLYT\LayoutViewer.Designer.cs">
<DependentUpon>LayoutViewer.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\UserDataEditor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="GUI\BFLYT\UserDataEditor.Designer.cs">
<DependentUpon>UserDataEditor.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\UserDataParser.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\UserDataParser.Designer.cs">
<DependentUpon>UserDataParser.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BotwActorEditorControl.cs">
<SubType>UserControl</SubType>
</Compile>
@ -1142,6 +1155,12 @@
<EmbeddedResource Include="GUI\BFLYT\LayoutViewer.resx">
<DependentUpon>LayoutViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\BFLYT\UserDataEditor.resx">
<DependentUpon>UserDataEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\BFLYT\UserDataParser.resx">
<DependentUpon>UserDataParser.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\BFRES\BatchEditBaseAnimDataForm.resx">
<DependentUpon>BatchEditBaseAnimDataForm.cs</DependentUpon>
</EmbeddedResource>

View file

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Graphics.OpenGL;
using OpenTK;
namespace LayoutBXLYT
{
public class BflytShader : IDisposable
{
private int program;
private int vertexShader;
private int fragmentShader;
public BflytShader()
{
program = CompileShaders();
}
public void Dispose()
{
GL.DeleteProgram(program);
}
public string VertexShader
{
get
{
StringBuilder vert = new StringBuilder();
return vert.ToString();
}
}
public string FragmentShader
{
get
{
StringBuilder frag = new StringBuilder();
return frag.ToString();
}
}
private int CompileShaders()
{
vertexShader = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(vertexShader, VertexShader);
GL.CompileShader(vertexShader);
fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
GL.ShaderSource(fragmentShader, FragmentShader);
GL.CompileShader(fragmentShader);
var program = GL.CreateProgram();
GL.AttachShader(program, vertexShader);
GL.AttachShader(program, fragmentShader);
GL.LinkProgram(program);
GL.DetachShader(program, vertexShader);
GL.DetachShader(program, fragmentShader);
GL.DeleteShader(vertexShader);
GL.DeleteShader(fragmentShader);
return program;
}
}
}

View file

@ -31,6 +31,7 @@ namespace LayoutBXLYT
imgList.Images.Add("NullPane", FirstPlugin.Properties.Resources.NullPane);
imgList.Images.Add("PicturePane", FirstPlugin.Properties.Resources.PicturePane);
imgList.Images.Add("QuickAcess", FirstPlugin.Properties.Resources.QuickAccess);
imgList.Images.Add("TextPane", FirstPlugin.Properties.Resources.TextPane);
imgList.ImageSize = new Size(22,22);
treeView1.ImageList = imgList;
@ -74,6 +75,7 @@ namespace LayoutBXLYT
treeView1.Nodes.Add(node);
TreeNode nullFolder = new TreeNode("Null Panes");
TreeNode textFolder = new TreeNode("Text Boxes");
TreeNode windowFolder = new TreeNode("Window Panes");
TreeNode pictureFolder = new TreeNode("Picture Panes");
TreeNode boundryFolder = new TreeNode("Boundry Panes");
@ -81,6 +83,7 @@ namespace LayoutBXLYT
TreeNode groupFolder = new TreeNode("Groups");
node.Nodes.Add(nullFolder);
node.Nodes.Add(textFolder);
node.Nodes.Add(windowFolder);
node.Nodes.Add(pictureFolder);
node.Nodes.Add(boundryFolder);
@ -102,6 +105,9 @@ namespace LayoutBXLYT
else if (panes[i] is BCLYT.PRT1) partsFolder.Nodes.Add(paneNode);
else if (panes[i] is BFLYT.PRT1) partsFolder.Nodes.Add(paneNode);
else if (panes[i] is BRLYT.PRT1) partsFolder.Nodes.Add(paneNode);
else if (panes[i] is BRLYT.TXT1) textFolder.Nodes.Add(paneNode);
else if (panes[i] is BCLYT.TXT1) textFolder.Nodes.Add(paneNode);
else if (panes[i] is BFLYT.TXT1) textFolder.Nodes.Add(paneNode);
else nullFolder.Nodes.Add(paneNode);
}
@ -143,6 +149,9 @@ namespace LayoutBXLYT
else if (pane is BFLYT.BND1) imageKey = "BoundryPane";
else if (pane is BCLYT.BND1) imageKey = "BoundryPane";
else if (pane is BRLYT.BND1) imageKey = "BoundryPane";
else if (pane is BFLYT.TXT1) imageKey = "TextPane";
else if (pane is BCLYT.TXT1) imageKey = "TextPane";
else if (pane is BRLYT.TXT1) imageKey = "TextPane";
else imageKey = "NullPane";
paneNode.ImageKey = imageKey;

View file

@ -29,25 +29,65 @@
private void InitializeComponent()
{
this.stPropertyGrid1 = new Toolbox.Library.Forms.STPropertyGrid();
this.stTabControl1 = new Toolbox.Library.Forms.STTabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.stTabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// stPropertyGrid1
//
this.stPropertyGrid1.AutoScroll = true;
this.stPropertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPropertyGrid1.Location = new System.Drawing.Point(0, 0);
this.stPropertyGrid1.Location = new System.Drawing.Point(3, 3);
this.stPropertyGrid1.Name = "stPropertyGrid1";
this.stPropertyGrid1.ShowHintDisplay = true;
this.stPropertyGrid1.Size = new System.Drawing.Size(352, 299);
this.stPropertyGrid1.Size = new System.Drawing.Size(338, 264);
this.stPropertyGrid1.TabIndex = 0;
//
// stTabControl1
//
this.stTabControl1.Controls.Add(this.tabPage1);
this.stTabControl1.Controls.Add(this.tabPage2);
this.stTabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stTabControl1.Location = new System.Drawing.Point(0, 0);
this.stTabControl1.myBackColor = System.Drawing.Color.Empty;
this.stTabControl1.Name = "stTabControl1";
this.stTabControl1.SelectedIndex = 0;
this.stTabControl1.Size = new System.Drawing.Size(352, 299);
this.stTabControl1.TabIndex = 1;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.stPropertyGrid1);
this.tabPage1.Location = new System.Drawing.Point(4, 25);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(344, 270);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Properties";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 25);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(344, 270);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "User Data";
this.tabPage2.UseVisualStyleBackColor = true;
//
// LayoutProperties
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(352, 299);
this.Controls.Add(this.stPropertyGrid1);
this.Controls.Add(this.stTabControl1);
this.Name = "LayoutProperties";
this.stTabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -55,5 +95,8 @@
#endregion
private Toolbox.Library.Forms.STPropertyGrid stPropertyGrid1;
private Toolbox.Library.Forms.STTabControl stTabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
}
}

View file

@ -13,9 +13,16 @@ namespace LayoutBXLYT
{
public partial class LayoutProperties : LayoutDocked
{
private UserDataEditor userDataEditor;
public LayoutProperties()
{
InitializeComponent();
stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor;
userDataEditor = new UserDataEditor();
userDataEditor.Dock = DockStyle.Fill;
tabPage2.Controls.Add(userDataEditor);
}
public void Reset()
@ -35,12 +42,22 @@ namespace LayoutBXLYT
private void LoadPropertyTab(string text, object prop, Action propChanged)
{
userDataEditor.Reset();
if (prop is IUserDataContainer)
LoadUserData((IUserDataContainer)prop);
DoubleBufferedTabPage page = new DoubleBufferedTabPage();
page.Enabled = false;
page.Text = text;
stPropertyGrid1.LoadProperty(prop, propChanged);
}
private void LoadUserData(IUserDataContainer container)
{
if (container.UserData != null && container.UserData.Entries != null)
userDataEditor.LoadUserData(container.UserData.Entries);
}
class DoubleBufferedTabPage : System.Windows.Forms.TabPage
{
public DoubleBufferedTabPage()

View file

@ -48,7 +48,7 @@
this.toolStripButton2});
this.stToolStrip1.Location = new System.Drawing.Point(0, 0);
this.stToolStrip1.Name = "stToolStrip1";
this.stToolStrip1.Size = new System.Drawing.Size(549, 25);
this.stToolStrip1.Size = new System.Drawing.Size(533, 25);
this.stToolStrip1.TabIndex = 11;
this.stToolStrip1.Text = "stToolStrip1";
//
@ -97,11 +97,12 @@
this.listViewCustom1.Location = new System.Drawing.Point(0, 25);
this.listViewCustom1.Name = "listViewCustom1";
this.listViewCustom1.OwnerDraw = true;
this.listViewCustom1.Size = new System.Drawing.Size(549, 373);
this.listViewCustom1.Size = new System.Drawing.Size(533, 334);
this.listViewCustom1.TabIndex = 13;
this.listViewCustom1.UseCompatibleStateImageBehavior = false;
this.listViewCustom1.View = System.Windows.Forms.View.Details;
this.listViewCustom1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listViewCustom1_DragEnter);
this.listViewCustom1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listViewCustom1_MouseClick);
//
// columnHeader1
//
@ -124,17 +125,17 @@
// columnHeader5
//
this.columnHeader5.Text = "Size";
this.columnHeader5.Width = 210;
this.columnHeader5.Width = 194;
//
// LayoutTextureList
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(533, 359);
this.Controls.Add(this.listViewCustom1);
this.Controls.Add(this.listViewTpyeCB);
this.Controls.Add(this.stToolStrip1);
this.Name = "LayoutTextureList";
this.Size = new System.Drawing.Size(549, 398);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LayoutTextureList_DragDrop);
this.stToolStrip1.ResumeLayout(false);
this.stToolStrip1.PerformLayout();

View file

@ -116,7 +116,7 @@ namespace LayoutBXLYT
item.SubItems.Add(texture.Width.ToString());
item.SubItems.Add(texture.Height.ToString());
item.SubItems.Add(texture.DataSize);
// Running on the UI thread
imgList.Images.Add(temp);
var dummy = imgList.Handle;
@ -152,5 +152,17 @@ namespace LayoutBXLYT
e.Effect = DragDropEffects.None;
}
}
private void listViewCustom1_MouseClick(object sender, MouseEventArgs e)
{
if (listViewCustom1.SelectedItems.Count == 0)
return;
var item = listViewCustom1.SelectedItems[0];
if (e.Button == MouseButtons.Right)
{
}
}
}
}

View file

@ -388,6 +388,16 @@ namespace LayoutBXLYT
}
}
enum TextureSwizzle
{
Zero = All.Zero,
One = All.One,
Red = All.Red,
Green = All.Green,
Blue = All.Blue,
Alpha = All.Alpha,
}
private static void BindGLTexture(TextureRef tex, STGenericTexture texture)
{
if (texture.RenderableTex == null || !texture.RenderableTex.GLInitialized)
@ -398,13 +408,31 @@ namespace LayoutBXLYT
return;
GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, ConvertChannel(texture.RedChannel));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, ConvertChannel(texture.GreenChannel));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, ConvertChannel(texture.BlueChannel));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, ConvertChannel(texture.AlphaChannel));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode));
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode));
}
private static int ConvertTextureWrap(TextureRef.WrapMode wrapMode)
private static int ConvertChannel(STChannelType type)
{
switch (type)
{
case STChannelType.Red: return (int)TextureSwizzle.Red;
case STChannelType.Green: return (int)TextureSwizzle.Green;
case STChannelType.Blue: return (int)TextureSwizzle.Blue;
case STChannelType.Alpha: return (int)TextureSwizzle.Alpha;
case STChannelType.Zero: return (int)TextureSwizzle.Zero;
case STChannelType.One: return (int)TextureSwizzle.One;
default: return 0;
}
}
private static int ConvertTextureWrap(TextureRef.WrapMode wrapMode)
{
switch (wrapMode)
{
@ -569,10 +597,13 @@ namespace LayoutBXLYT
private Point originMouse;
private void glControl1_MouseDown(object sender, MouseEventArgs e)
{
SelectedPanes.Clear();
//Pick an object for moving
if (Control.ModifierKeys == Keys.Alt && e.Button == MouseButtons.Left)
{
var hitPane = SearchHit(LayoutFile.RootPane, e.X, e.Y);
BasePane hitPane = null;
SearchHit(LayoutFile.RootPane, e.X, e.Y, ref hitPane);
if (hitPane != null)
{
SelectedPanes.Add(hitPane);
@ -586,7 +617,9 @@ namespace LayoutBXLYT
mouseHeldDown = true;
originMouse = e.Location;
var hitPane = SearchHit(LayoutFile.RootPane, e.X, e.Y);
BasePane hitPane = null;
foreach (var child in LayoutFile.RootPane.Childern)
SearchHit(child, e.X, e.Y, ref hitPane);
Console.WriteLine($"Has Hit " + hitPane != null);
if (hitPane != null)
{
@ -596,17 +629,19 @@ namespace LayoutBXLYT
glControl1.Invalidate();
}
Console.WriteLine("SelectedPanes " + SelectedPanes.Count);
}
private BasePane SearchHit(BasePane pane, int X, int Y)
private void SearchHit(BasePane pane, int X, int Y, ref BasePane SelectedPane)
{
if (pane.IsHit(X, Y))
return pane;
if (pane.IsHit(X, Y)){
SelectedPane = pane;
return;
}
foreach (var childPane in pane.Childern)
return SearchHit(childPane, X, Y);
return null;
SearchHit(childPane, X, Y, ref SelectedPane);
}
private void glControl1_MouseUp(object sender, MouseEventArgs e)

View file

@ -0,0 +1,165 @@
namespace LayoutBXLYT
{
partial class UserDataEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnEdit = new Toolbox.Library.Forms.STButton();
this.btnRemove = new Toolbox.Library.Forms.STButton();
this.btnAdd = new Toolbox.Library.Forms.STButton();
this.listViewCustom1 = new Toolbox.Library.Forms.ListViewCustom();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.btnScrolDown = new Toolbox.Library.Forms.STButton();
this.btnScrollUp = new Toolbox.Library.Forms.STButton();
this.SuspendLayout();
//
// btnEdit
//
this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnEdit.Enabled = false;
this.btnEdit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnEdit.Location = new System.Drawing.Point(299, 3);
this.btnEdit.Name = "btnEdit";
this.btnEdit.Size = new System.Drawing.Size(75, 23);
this.btnEdit.TabIndex = 5;
this.btnEdit.Text = "Edit";
this.btnEdit.UseVisualStyleBackColor = false;
this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
//
// btnRemove
//
this.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRemove.Location = new System.Drawing.Point(84, 3);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(75, 23);
this.btnRemove.TabIndex = 4;
this.btnRemove.Text = "Remove";
this.btnRemove.UseVisualStyleBackColor = false;
this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
//
// btnAdd
//
this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAdd.Location = new System.Drawing.Point(3, 3);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 3;
this.btnAdd.Text = "Add";
this.btnAdd.UseVisualStyleBackColor = false;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// listViewCustom1
//
this.listViewCustom1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listViewCustom1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.listViewCustom1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listViewCustom1.FullRowSelect = true;
this.listViewCustom1.Location = new System.Drawing.Point(3, 32);
this.listViewCustom1.Name = "listViewCustom1";
this.listViewCustom1.OwnerDraw = true;
this.listViewCustom1.Size = new System.Drawing.Size(371, 391);
this.listViewCustom1.TabIndex = 2;
this.listViewCustom1.UseCompatibleStateImageBehavior = false;
this.listViewCustom1.View = System.Windows.Forms.View.Details;
this.listViewCustom1.SelectedIndexChanged += new System.EventHandler(this.listViewCustom1_SelectedIndexChanged);
this.listViewCustom1.DoubleClick += new System.EventHandler(this.listViewCustom1_DoubleClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
this.columnHeader1.Width = 79;
//
// columnHeader2
//
this.columnHeader2.Text = "Type";
this.columnHeader2.Width = 87;
//
// columnHeader3
//
this.columnHeader3.Text = "Value";
this.columnHeader3.Width = 195;
//
// btnScrolDown
//
this.btnScrolDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnScrolDown.Enabled = false;
this.btnScrolDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnScrolDown.Location = new System.Drawing.Point(381, 61);
this.btnScrolDown.Name = "btnScrolDown";
this.btnScrolDown.Size = new System.Drawing.Size(32, 24);
this.btnScrolDown.TabIndex = 1;
this.btnScrolDown.Text = "▼";
this.btnScrolDown.UseVisualStyleBackColor = true;
//
// btnScrollUp
//
this.btnScrollUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnScrollUp.Enabled = false;
this.btnScrollUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnScrollUp.Location = new System.Drawing.Point(381, 32);
this.btnScrollUp.Name = "btnScrollUp";
this.btnScrollUp.Size = new System.Drawing.Size(32, 24);
this.btnScrollUp.TabIndex = 0;
this.btnScrollUp.Text = "▲";
this.btnScrollUp.UseVisualStyleBackColor = true;
//
// UserDataEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.btnEdit);
this.Controls.Add(this.btnRemove);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.listViewCustom1);
this.Controls.Add(this.btnScrolDown);
this.Controls.Add(this.btnScrollUp);
this.Name = "UserDataEditor";
this.Size = new System.Drawing.Size(416, 426);
this.ResumeLayout(false);
}
#endregion
private Toolbox.Library.Forms.STButton btnScrollUp;
private Toolbox.Library.Forms.ListViewCustom listViewCustom1;
private Toolbox.Library.Forms.STButton btnAdd;
private Toolbox.Library.Forms.STButton btnRemove;
private Toolbox.Library.Forms.STButton btnEdit;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private Toolbox.Library.Forms.STButton btnScrolDown;
}
}

View file

@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Syroot.NintenTools.Bfres;
namespace LayoutBXLYT
{
public partial class UserDataEditor : UserControl
{
public UserDataEditor()
{
InitializeComponent();
listViewCustom1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
}
List<UserDataEntry> ActiveUserData;
UserDataEntry SelectedEntry;
public void Reset()
{
ActiveUserData = new List<UserDataEntry>();
SelectedEntry = null;
listViewCustom1.Items.Clear();
}
bool IsWiiU = false;
public void LoadUserData(List<UserDataEntry> UserDataList)
{
listViewCustom1.Items.Clear();
ActiveUserData = UserDataList;
foreach (var item in ActiveUserData)
LoadUserData(item);
}
private void LoadUserData(UserDataEntry item)
{
ListViewItem listItem = new ListViewItem();
listItem.Text = item.Name;
listItem.SubItems.Add(item.Type.ToString());
string value = "";
switch (item.Type)
{
case UserDataType.String:
if (item.GetString() != null)
{
value += $" {item.GetString()}";
}
break;
case UserDataType.Float:
if (item.GetFloats() != null)
{
foreach (var val in item.GetFloats())
value += $" {val}";
}
break;
case UserDataType.Int:
if (item.GetInts() != null)
{
foreach (var val in item.GetInts())
value += $" {val}";
}
break;
}
listItem.SubItems.Add(value);
listViewCustom1.Items.Add(listItem);
}
private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listViewCustom1.SelectedItems.Count > 0)
{
btnScrolDown.Enabled = true;
btnScrollUp.Enabled = true;
btnEdit.Enabled = true;
btnRemove.Enabled = true;
if (IsWiiU)
SelectedEntry = ActiveUserData[listViewCustom1.SelectedIndices[0]];
}
else
{
SelectedEntry = null;
btnScrolDown.Enabled = false;
btnScrollUp.Enabled = false;
btnEdit.Enabled = false;
btnRemove.Enabled = false;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
EditData();
}
private void btnAdd_Click(object sender, EventArgs e)
{
UserDataEntry userDataNew = new UserDataEntry();
userDataNew.SetValue(new int[0]);
SelectedEntry = userDataNew;
bool IsEdited = EditData();
if (IsEdited)
{
ActiveUserData.Add(userDataNew);
LoadUserData(userDataNew);
}
}
private bool EditData()
{
if (SelectedEntry != null)
{
UserDataParser parser = new UserDataParser();
parser.UserDataName = SelectedEntry.Name;
parser.Type = SelectedEntry.Type.ToString();
switch (SelectedEntry.Type)
{
case UserDataType.String:
if (SelectedEntry.GetString() != null)
parser.LoadValues(SelectedEntry.GetString());
break;
case UserDataType.Float:
if (SelectedEntry.GetString() != null)
parser.LoadValues(SelectedEntry.GetFloats());
break;
case UserDataType.Int:
if (SelectedEntry.GetInts() != null)
parser.LoadValues(SelectedEntry.GetInts());
break;
}
if (parser.ShowDialog() == DialogResult.OK)
{
SelectedEntry.Name = parser.UserDataName;
if (parser.Type == "Single")
SelectedEntry.SetValue(parser.GetFloats());
if (parser.Type == "Int32")
SelectedEntry.SetValue(parser.GetInts());
if (parser.Type == "String")
SelectedEntry.SetValue(parser.GetStringASCII());
LoadUserData(ActiveUserData);
return true;
}
}
return false;
}
private void btnRemove_Click(object sender, EventArgs e)
{
if (listViewCustom1.SelectedIndices.Count > 0)
{
int index = listViewCustom1.SelectedIndices[0];
listViewCustom1.Items.RemoveAt(index);
if (ActiveUserData != null)
ActiveUserData.RemoveAt(index);
}
}
private void listViewCustom1_DoubleClick(object sender, EventArgs e)
{
EditData();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,170 @@
namespace LayoutBXLYT
{
partial class UserDataParser
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTB = new Toolbox.Library.Forms.STTextBox();
this.stLabel1 = new Toolbox.Library.Forms.STLabel();
this.typeCB = new Toolbox.Library.Forms.STComboBox();
this.stLabel2 = new Toolbox.Library.Forms.STLabel();
this.valueTB = new System.Windows.Forms.RichTextBox();
this.stLabel3 = new Toolbox.Library.Forms.STLabel();
this.btnCancel = new Toolbox.Library.Forms.STButton();
this.btnOk = new Toolbox.Library.Forms.STButton();
this.contentContainer.SuspendLayout();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.btnOk);
this.contentContainer.Controls.Add(this.btnCancel);
this.contentContainer.Controls.Add(this.stLabel3);
this.contentContainer.Controls.Add(this.valueTB);
this.contentContainer.Controls.Add(this.stLabel2);
this.contentContainer.Controls.Add(this.typeCB);
this.contentContainer.Controls.Add(this.stLabel1);
this.contentContainer.Controls.Add(this.nameTB);
this.contentContainer.Size = new System.Drawing.Size(314, 411);
this.contentContainer.Paint += new System.Windows.Forms.PaintEventHandler(this.contentContainer_Paint);
this.contentContainer.Controls.SetChildIndex(this.nameTB, 0);
this.contentContainer.Controls.SetChildIndex(this.stLabel1, 0);
this.contentContainer.Controls.SetChildIndex(this.typeCB, 0);
this.contentContainer.Controls.SetChildIndex(this.stLabel2, 0);
this.contentContainer.Controls.SetChildIndex(this.valueTB, 0);
this.contentContainer.Controls.SetChildIndex(this.stLabel3, 0);
this.contentContainer.Controls.SetChildIndex(this.btnCancel, 0);
this.contentContainer.Controls.SetChildIndex(this.btnOk, 0);
//
// nameTB
//
this.nameTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.nameTB.Location = new System.Drawing.Point(62, 36);
this.nameTB.Name = "nameTB";
this.nameTB.Size = new System.Drawing.Size(243, 20);
this.nameTB.TabIndex = 11;
//
// stLabel1
//
this.stLabel1.AutoSize = true;
this.stLabel1.Location = new System.Drawing.Point(9, 39);
this.stLabel1.Name = "stLabel1";
this.stLabel1.Size = new System.Drawing.Size(38, 13);
this.stLabel1.TabIndex = 12;
this.stLabel1.Text = "Name:";
//
// typeCB
//
this.typeCB.DropDownStyle = Toolbox.Library.Forms.STComboBox.STDropDownStyle;
this.typeCB.FormattingEnabled = true;
this.typeCB.Location = new System.Drawing.Point(62, 78);
this.typeCB.Name = "typeCB";
this.typeCB.Size = new System.Drawing.Size(136, 21);
this.typeCB.TabIndex = 13;
//
// stLabel2
//
this.stLabel2.AutoSize = true;
this.stLabel2.Location = new System.Drawing.Point(9, 81);
this.stLabel2.Name = "stLabel2";
this.stLabel2.Size = new System.Drawing.Size(34, 13);
this.stLabel2.TabIndex = 14;
this.stLabel2.Text = "Type:";
//
// valueTB
//
this.valueTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.valueTB.BackColor = System.Drawing.Color.White;
this.valueTB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.valueTB.Location = new System.Drawing.Point(12, 118);
this.valueTB.Name = "valueTB";
this.valueTB.Size = new System.Drawing.Size(293, 255);
this.valueTB.TabIndex = 15;
this.valueTB.Text = "";
this.valueTB.TextChanged += new System.EventHandler(this.valueTB_TextChanged);
//
// stLabel3
//
this.stLabel3.AutoSize = true;
this.stLabel3.Location = new System.Drawing.Point(9, 102);
this.stLabel3.Name = "stLabel3";
this.stLabel3.Size = new System.Drawing.Size(134, 13);
this.stLabel3.TabIndex = 16;
this.stLabel3.Text = "Values: (Enter one per line)";
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Location = new System.Drawing.Point(229, 379);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 17;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = false;
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOk.Location = new System.Drawing.Point(148, 379);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 18;
this.btnOk.Text = "Ok";
this.btnOk.UseVisualStyleBackColor = false;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// UserDataParser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(320, 416);
this.Name = "UserDataParser";
this.Text = "User Data";
this.contentContainer.ResumeLayout(false);
this.contentContainer.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private Toolbox.Library.Forms.STTextBox nameTB;
private Toolbox.Library.Forms.STLabel stLabel3;
private System.Windows.Forms.RichTextBox valueTB;
private Toolbox.Library.Forms.STLabel stLabel2;
private Toolbox.Library.Forms.STComboBox typeCB;
private Toolbox.Library.Forms.STLabel stLabel1;
private Toolbox.Library.Forms.STButton btnOk;
private Toolbox.Library.Forms.STButton btnCancel;
}
}

View file

@ -0,0 +1,268 @@
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.Windows.Forms;
using Toolbox.Library.Forms;
namespace LayoutBXLYT
{
public partial class UserDataParser : STForm
{
public UserDataParser()
{
InitializeComponent();
valueTB.BackColor = FormThemes.BaseTheme.FormBackColor;
valueTB.ForeColor = FormThemes.BaseTheme.FormForeColor;
typeCB.Items.Add("WString");
typeCB.Items.Add("String");
typeCB.Items.Add("Single");
typeCB.Items.Add("Int32");
typeCB.Items.Add("Byte");
}
public string UserDataName
{
set {
nameTB.Text = value;
}
get {
return nameTB.Text;
}
}
public string Type
{
set
{
typeCB.SelectedItem = value;
}
get
{
return typeCB.GetItemText(typeCB.SelectedItem);
}
}
public void LoadValues(string strings)
{
valueTB.Text += $"{strings}";
}
public void LoadValues(float[] floats)
{
foreach (var str in floats)
valueTB.Text += $"{str}\n";
}
public void LoadValues(int[] ints)
{
foreach (var str in ints)
valueTB.Text += $"{str}\n";
}
public void LoadValues(byte[] bytes)
{
foreach (var str in bytes)
valueTB.Text += $"{str}\n";
}
public float[] GetFloats()
{
List<float> values = new List<float>();
int curLine = 0;
foreach (string line in valueTB.Lines)
{
if (line == string.Empty)
continue;
float valResult;
bool sucess = float.TryParse(line, out valResult);
if (!sucess)
throw new Exception($"Failed to parse float at line {curLine}");
values.Add(valResult);
curLine++;
}
if (values.Count == 0)
values.Add(0);
return values.ToArray();
}
public byte[] GetBytes()
{
List<byte> values = new List<byte>();
int curLine = 0;
foreach (string line in valueTB.Lines)
{
if (line == string.Empty)
continue;
byte valResult;
bool sucess = byte.TryParse(line, out valResult);
if (!sucess)
throw new Exception($"Failed to parse byte at line {curLine}");
values.Add(valResult);
curLine++;
}
if (values.Count == 0)
values.Add(0);
return values.ToArray();
}
public int[] GetInts()
{
List<int> values = new List<int>();
int curLine = 0;
foreach (string line in valueTB.Lines)
{
if (line == string.Empty)
continue;
int valResult;
bool sucess = int.TryParse(line, out valResult);
if (!sucess)
throw new Exception($"Failed to parse int at line {curLine}");
values.Add(valResult);
curLine++;
}
if (values.Count == 0)
values.Add(0);
return values.ToArray();
}
public string[] GetStringUnicode()
{
List<string> values = new List<string>();
int curLine = 0;
foreach (string line in valueTB.Lines)
{
if (line == string.Empty)
continue;
values.Add(line);
curLine++;
}
if (values.Count == 0)
values.Add("");
return values.ToArray();
}
public string[] GetStringASCII()
{
List<string> values = new List<string>();
int curLine = 0;
foreach (string line in valueTB.Lines)
{
if (line == string.Empty)
continue;
values.Add(line);
curLine++;
}
if (values.Count == 0)
values.Add("");
return values.ToArray();
}
private void btnOk_Click(object sender, EventArgs e)
{
if (!CheckParser())
return;
if (UserDataName == string.Empty)
{
MessageBox.Show("Name parameter not set!", Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.None;
}
else
{
DialogResult = DialogResult.OK;
}
}
private bool CheckParser()
{
bool CanParse = true;
float valSingle;
int valInt;
byte valByte;
string Error = "";
int curLine = 0;
foreach (var line in valueTB.Lines)
{
bool Success = true;
if (Type == "WString")
{
}
else if (Type == "String")
{
}
else if (line == string.Empty) //Don't parse empty lines, instead we'll skip those
{
}
else if (Type == "Single")
Success = float.TryParse(line, out valSingle);
else if (Type == "Int32")
Success = int.TryParse(line, out valInt);
else if (Type == "Byte")
Success = byte.TryParse(line, out valByte);
if (!Success)
{
CanParse = false;
Error += $"Invalid data type at line {curLine}.\n";
}
curLine++;
}
if (CanParse == false)
{
STErrorDialog.Show($"Data must be type of {Type}","User Data", Error);
}
return CanParse;
}
private void valueTB_TextChanged(object sender, EventArgs e)
{
}
private void contentContainer_Paint(object sender, PaintEventArgs e)
{
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -57,7 +57,7 @@ namespace Toolbox.Library
byte[] compSel = new byte[4] {0,1,2,3 };
if (format == TEX_FORMAT.L8 || format == TEX_FORMAT.LA8)
compSel = new byte[4] { 0, 0, 0, 1 };
compSel = new byte[4] { 1, 1, 1, 3 };
for (int Y = 0; Y < height; Y++)
@ -74,9 +74,9 @@ namespace Toolbox.Library
byte[] comp = GetComponentsFromPixel(format, pixel);
output[outPos + 3] = comp[compSel[3]];
output[outPos + 2] = comp[compSel[2]];
output[outPos + 2] = comp[compSel[0]];
output[outPos + 1] = comp[compSel[1]];
output[outPos + 0] = comp[compSel[0]];
output[outPos + 0] = comp[compSel[2]];
}
}