1
0
mirror of synced 2025-02-25 22:38:07 +01:00

Adjust the editor a bit to later add bclyt

This commit is contained in:
KillzXGaming 2019-08-29 16:33:23 -04:00
parent 47fc8b39cb
commit 668265dd13
17 changed files with 251 additions and 217 deletions

View File

@ -7,7 +7,7 @@ using Toolbox;
using System.Windows.Forms;
using Toolbox.Library;
namespace FirstPlugin
namespace LayoutBXLYT
{
public class BFLAN : IFileFormat
{

View File

@ -10,8 +10,9 @@ using Toolbox.Library.IO;
using FirstPlugin.Forms;
using Syroot.Maths;
using SharpYaml.Serialization;
using FirstPlugin;
namespace FirstPlugin
namespace LayoutBXLYT
{
public class BFLYT : IFileFormat, IEditorForm<LayoutEditor>, IConvertableTextFormat
{
@ -193,7 +194,7 @@ namespace FirstPlugin
//Thanks to SwitchThemes for flags, and enums
//https://github.com/FuryBaguette/SwitchLayoutEditor/tree/master/SwitchThemesCommon
public class Header
public class Header : BxlytHeader
{
internal BFLYT FileInfo;
@ -207,40 +208,6 @@ namespace FirstPlugin
private ushort ByteOrderMark;
private ushort HeaderSize;
internal uint Version;
public string VersionFull
{
get
{
var major = Version >> 24;
var minor = Version >> 16 & 0xFF;
var micro = Version >> 8 & 0xFF;
var micro2 = Version & 0xFF;
return $"{major} {minor} {micro} {micro2}";
}
}
public uint VersionMajor
{
get { return Version >> 24; }
}
public uint VersionMinor
{
get { return Version >> 16 & 0xFF; }
}
public uint VersionMicro
{
get { return Version >> 8 & 0xFF; }
}
public uint VersionMicro2
{
get { return Version & 0xFF; }
}
public LYT1 LayoutInfo { get; set; }
public TXL1 TextureList { get; set; }
public MAT1 MaterialList { get; set; }
@ -248,7 +215,6 @@ namespace FirstPlugin
// private List<SectionCommon> Sections;
public PAN1 RootPane { get; set; }
public GRP1 RootGroup { get; set; }
// public List<PAN1> Panes = new List<PAN1>();
@ -411,28 +377,6 @@ namespace FirstPlugin
}
}
public class BasePane : SectionCommon
{
public bool DisplayInEditor { get; set; } = true;
public string Name { get; set; }
public Vector3F Translate { get; set; }
public Vector3F Rotate { get; set; }
public Vector2F Scale { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public BasePane Parent { get; set; }
public List<BasePane> Childern { get; set; } = new List<BasePane>();
public bool HasChildern
{
get { return Childern.Count > 0; }
}
}
public class TexCoord
{
public Vector2F TopLeft { get; set; }
@ -543,7 +487,7 @@ namespace FirstPlugin
ShadowItalic = reader.ReadSingle();
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
base.Write(writer, header);
writer.Write(TextLength);
@ -596,7 +540,7 @@ namespace FirstPlugin
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
base.Write(writer, header);
}
@ -614,28 +558,12 @@ namespace FirstPlugin
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
base.Write(writer, header);
}
}
public class CustomRectangle
{
public int LeftPoint;
public int RightPoint;
public int TopPoint;
public int BottomPoint;
public CustomRectangle(int left, int right, int top, int bottom)
{
LeftPoint = left;
RightPoint = right;
TopPoint = top;
BottomPoint = bottom;
}
}
public class GRP1 : BasePane
{
public List<string> Panes { get; set; } = new List<string>();
@ -664,7 +592,7 @@ namespace FirstPlugin
Panes.Add(reader.ReadString(24));
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
if (header.Version >= 0x05020000)
{
@ -695,7 +623,7 @@ namespace FirstPlugin
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
base.Write(writer, header);
}
@ -717,6 +645,12 @@ namespace FirstPlugin
return ParentLayout.MaterialList.Materials[MaterialIndex];
}
public string GetTexture(int index)
{
var mat = GetMaterial();
return ParentLayout.TextureList.Textures[mat.TextureMaps[index].ID];
}
private BFLYT.Header ParentLayout;
public PIC1() : base() {
@ -754,7 +688,7 @@ namespace FirstPlugin
}
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
base.Write(writer, header);
writer.Write(ColorTopLeft.ToBytes());
@ -859,7 +793,7 @@ namespace FirstPlugin
Height = reader.ReadSingle();
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
writer.Write(_flags1);
writer.Write(_flags2);
@ -874,80 +808,6 @@ namespace FirstPlugin
writer.Write(Height);
}
public enum OriginX : byte
{
Center = 0,
Left = 1,
Right = 2
};
public enum OriginY : byte
{
Center = 0,
Top = 1,
Bottom = 2
};
public BFLYT.CustomRectangle CreateRectangle()
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
//Do origin transforms
var transformed = TransformOrientation((int)Width, (int)Height);
//Now do parent transforms
Vector2 ParentWH = new Vector2(0,0);
if (Parent != null && Parent is BasePane)
ParentWH = new Vector2((int)Parent.Width, (int)Parent.Height);
var transformedParent = TransformOrientation(ParentWH.X, ParentWH.Y);
// if (Parent != null)
// transformed -= transformedParent;
return new CustomRectangle(
transformed.X,
transformed.Y,
transformed.Z,
transformed.W);
}
private Vector4 TransformOrientation(int Width, int Height)
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
if (originX == OriginX.Left)
right = Width;
else if (originX == OriginX.Right)
left = -Width;
else //To center
{
left = -Width / 2;
right = Width / 2;
}
if (originY == OriginY.Top)
bottom = Height;
else if (originY == OriginY.Bottom)
top = -Height;
else //To center
{
top = -Height / 2;
bottom = Height / 2;
}
return new Vector4(left, right, top, bottom);
}
public bool ParentVisibility
{
get
@ -990,7 +850,7 @@ namespace FirstPlugin
}
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
writer.Write((ushort)Materials.Count);
writer.Seek(2);
@ -1010,6 +870,12 @@ namespace FirstPlugin
private uint flags;
private int unknown;
private BFLYT.Header ParentLayout;
public string GetTexture(int index)
{
return ParentLayout.TextureList.Textures[TextureMaps[index].ID];
}
public Material()
{
TextureMaps = new List<TextureRef>();
@ -1018,6 +884,8 @@ namespace FirstPlugin
public Material(FileReader reader, Header header) : base()
{
ParentLayout = header;
TextureMaps = new List<TextureRef>();
TextureTransforms = new List<TextureTransform>();
@ -1173,7 +1041,7 @@ namespace FirstPlugin
}
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
writer.Write((ushort)Fonts.Count);
writer.Seek(2);
@ -1217,7 +1085,7 @@ namespace FirstPlugin
}
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
writer.Write((ushort)Textures.Count);
writer.Seek(2);
@ -1267,7 +1135,7 @@ namespace FirstPlugin
Name = reader.ReadZeroTerminatedString();
}
public override void Write(FileWriter writer, Header header)
public override void Write(FileWriter writer, BxlytHeader header)
{
writer.Write(DrawFromCenter);
writer.Seek(3);
@ -1278,23 +1146,5 @@ namespace FirstPlugin
writer.Write(Name);
}
}
public class SectionCommon
{
internal string Signature { get; set; }
internal uint SectionSize { get; set; }
internal byte[] Data { get; set; }
public virtual void Write(FileWriter writer, Header header)
{
writer.WriteSignature(Signature);
if (Data != null)
{
writer.Write(Data.Length);
writer.Write(Data);
}
}
}
}
}

View File

@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Syroot.Maths;
using Toolbox.Library.IO;
namespace LayoutBXLYT
{
public class BasePane : SectionCommon
{
public bool DisplayInEditor { get; set; } = true;
public string Name { get; set; }
public Vector3F Translate { get; set; }
public Vector3F Rotate { get; set; }
public Vector2F Scale { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public virtual OriginX originX { get; set; }
public virtual OriginY originY { get; set; }
public virtual OriginX ParentOriginX { get; set; }
public virtual OriginY ParentOriginY { get; set; }
public BasePane Parent { get; set; }
public List<BasePane> Childern { get; set; } = new List<BasePane>();
public bool HasChildern
{
get { return Childern.Count > 0; }
}
public CustomRectangle CreateRectangle()
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
//Do origin transforms
var transformed = TransformOrientation((int)Width, (int)Height);
//Now do parent transforms
Vector2 ParentWH = new Vector2(0, 0);
if (Parent != null && Parent is BasePane)
ParentWH = new Vector2((int)Parent.Width, (int)Parent.Height);
var transformedParent = TransformOrientation(ParentWH.X, ParentWH.Y);
// if (Parent != null)
// transformed -= transformedParent;
return new CustomRectangle(
transformed.X,
transformed.Y,
transformed.Z,
transformed.W);
}
private Vector4 TransformOrientation(int Width, int Height)
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
if (originX == OriginX.Left)
right = Width;
else if (originX == OriginX.Right)
left = -Width;
else //To center
{
left = -Width / 2;
right = Width / 2;
}
if (originY == OriginY.Top)
bottom = Height;
else if (originY == OriginY.Bottom)
top = -Height;
else //To center
{
top = -Height / 2;
bottom = Height / 2;
}
return new Vector4(left, right, top, bottom);
}
}
public enum OriginX : byte
{
Center = 0,
Left = 1,
Right = 2
};
public enum OriginY : byte
{
Center = 0,
Top = 1,
Bottom = 2
};
public class BxlytHeader
{
public BasePane RootPane { get; set; }
internal uint Version;
public string VersionFull
{
get
{
var major = Version >> 24;
var minor = Version >> 16 & 0xFF;
var micro = Version >> 8 & 0xFF;
var micro2 = Version & 0xFF;
return $"{major} {minor} {micro} {micro2}";
}
}
public uint VersionMajor
{
get { return Version >> 24; }
}
public uint VersionMinor
{
get { return Version >> 16 & 0xFF; }
}
public uint VersionMicro
{
get { return Version >> 8 & 0xFF; }
}
public uint VersionMicro2
{
get { return Version & 0xFF; }
}
}
public class SectionCommon
{
internal string Signature { get; set; }
internal uint SectionSize { get; set; }
internal byte[] Data { get; set; }
public virtual void Write(FileWriter writer, BxlytHeader header)
{
writer.WriteSignature(Signature);
if (Data != null)
{
writer.Write(Data.Length);
writer.Write(Data);
}
}
}
public class CustomRectangle
{
public int LeftPoint;
public int RightPoint;
public int TopPoint;
public int BottomPoint;
public CustomRectangle(int left, int right, int top, int bottom)
{
LeftPoint = left;
RightPoint = right;
TopPoint = top;
BottomPoint = bottom;
}
}
}

View File

@ -3,10 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbox.Library;
namespace FirstPlugin
namespace LayoutBXLYT
{
public class PaneTreeWrapper : TreeNodeCustom
{

View File

@ -294,6 +294,7 @@
<Compile Include="FileFormats\HyruleWarriors\G1M\G1M.cs" />
<Compile Include="FileFormats\HyruleWarriors\LINKDATA.cs" />
<Compile Include="FileFormats\Layout\PaneTreeWrapper.cs" />
<Compile Include="FileFormats\Layout\Common.cs" />
<Compile Include="FileFormats\Message\MSBP.cs" />
<Compile Include="FileFormats\CrashBandicoot\IGZ_TEX.cs" />
<Compile Include="FileFormats\MOD.cs" />

View File

@ -1,4 +1,4 @@
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
partial class LayoutEditor
{

View File

@ -13,7 +13,7 @@ using WeifenLuo.WinFormsUI.ThemeVS2015;
using Toolbox.Library.IO;
using Toolbox.Library;
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
public partial class LayoutEditor : Form
{
@ -107,7 +107,7 @@ namespace FirstPlugin.Forms
{
if (e is TreeViewEventArgs) {
var node = ((TreeViewEventArgs)e).Node;
var pane = (BFLYT.BasePane)node.Tag;
var pane = (BasePane)node.Tag;
((LayoutProperties)PropertiesDock.Controls[0]).LoadProperties(pane, OnProperyChanged);
@ -129,8 +129,8 @@ namespace FirstPlugin.Forms
private void ToggleChildern(TreeNode node, bool isChecked)
{
if (node.Tag is BFLYT.BasePane)
((BFLYT.BasePane)node.Tag).DisplayInEditor = isChecked;
if (node.Tag is BasePane)
((BasePane)node.Tag).DisplayInEditor = isChecked;
node.Checked = isChecked;
foreach (TreeNode child in node.Nodes)

View File

@ -1,4 +1,4 @@
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
partial class LayoutHierarchy
{

View File

@ -10,7 +10,7 @@ using System.Windows.Forms;
using FirstPlugin;
using Toolbox.Library.Forms;
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
public partial class LayoutHierarchy : UserControl
{
@ -22,12 +22,12 @@ namespace FirstPlugin.Forms
treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;
var imgList = new ImageList();
imgList.Images.Add("AlignmentPane", Properties.Resources.AlignmentPane);
imgList.Images.Add("WindowPane", Properties.Resources.WindowPane);
imgList.Images.Add("ScissorPane", Properties.Resources.ScissorPane);
imgList.Images.Add("BoundryPane", Properties.Resources.BoundryPane);
imgList.Images.Add("NullPane", Properties.Resources.NullPane);
imgList.Images.Add("PicturePane", Properties.Resources.PicturePane);
imgList.Images.Add("AlignmentPane", FirstPlugin.Properties.Resources.AlignmentPane);
imgList.Images.Add("WindowPane", FirstPlugin.Properties.Resources.WindowPane);
imgList.Images.Add("ScissorPane", FirstPlugin.Properties.Resources.ScissorPane);
imgList.Images.Add("BoundryPane", FirstPlugin.Properties.Resources.BoundryPane);
imgList.Images.Add("NullPane", FirstPlugin.Properties.Resources.NullPane);
imgList.Images.Add("PicturePane", FirstPlugin.Properties.Resources.PicturePane);
imgList.ImageSize = new Size(22,22);
treeView1.ImageList = imgList;
}
@ -47,7 +47,7 @@ namespace FirstPlugin.Forms
isLoaded = true;
}
private void LoadPane(BFLYT.BasePane pane, TreeNode parent = null)
private void LoadPane(BasePane pane, TreeNode parent = null)
{
PaneTreeWrapper paneNode = new PaneTreeWrapper();
paneNode.Checked = true;

View File

@ -1,4 +1,4 @@
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
partial class LayoutProperties
{

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbox.Library.Forms;
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
public partial class LayoutProperties : UserControl
{
@ -20,7 +20,7 @@ namespace FirstPlugin.Forms
stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor;
}
public void LoadProperties(BFLYT.BasePane prop, Action propChanged)
public void LoadProperties(BasePane prop, Action propChanged)
{
stTabControl1.Controls.Clear();

View File

@ -1,4 +1,4 @@
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
partial class LayoutTextureList
{

View File

@ -13,7 +13,7 @@ using Toolbox.Library;
using System.Threading;
using WeifenLuo.WinFormsUI.Docking;
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
public partial class LayoutTextureList : UserControl
{
@ -93,6 +93,7 @@ namespace FirstPlugin.Forms
private void LoadTextureIcon(ListViewItem item, STGenericTexture texture)
{
Bitmap temp = texture.GetBitmap();
temp = texture.GetComponentBitmap(temp, true);
if (listViewCustom1.InvokeRequired)
{

View File

@ -1,4 +1,4 @@
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
partial class LayoutViewer
{

View File

@ -13,11 +13,11 @@ using Toolbox.Library;
using Toolbox.Library.Rendering;
using Toolbox.Library.IO;
namespace FirstPlugin.Forms
namespace LayoutBXLYT
{
public partial class LayoutViewer : UserControl
{
public List<BFLYT.BasePane> SelectedPanes = new List<BFLYT.BasePane>();
public List<BasePane> SelectedPanes = new List<BasePane>();
public Camera2D Camera = new Camera2D();
@ -29,7 +29,7 @@ namespace FirstPlugin.Forms
private RenderableTex backgroundTex;
private BFLYT.Header LayoutFile;
private BxlytHeader LayoutFile;
private static Dictionary<string, STGenericTexture> Textures;
@ -89,7 +89,7 @@ namespace FirstPlugin.Forms
glControl1.SwapBuffers();
}
private void RenderPanes(BFLYT.BasePane pane, bool isRoot)
private void RenderPanes(BasePane pane, bool isRoot)
{
if (!pane.DisplayInEditor)
return;
@ -102,9 +102,9 @@ namespace FirstPlugin.Forms
if (!isRoot)
{
if (pane is BFLYT.PIC1)
DrawPicturePane(LayoutFile, (BFLYT.PIC1)pane);
DrawPicturePane((BFLYT.PIC1)pane);
else if (pane is BFLYT.PAN1)
DrawDefaultPane(LayoutFile, (BFLYT.PAN1)pane);
DrawDefaultPane((BFLYT.PAN1)pane);
}
else
isRoot = false;
@ -115,7 +115,7 @@ namespace FirstPlugin.Forms
GL.PopMatrix();
}
private void DrawRootPane(BFLYT.PAN1 pane)
private void DrawRootPane(BasePane pane)
{
GL.LoadIdentity();
GL.PushMatrix();
@ -127,7 +127,7 @@ namespace FirstPlugin.Forms
if (SelectedPanes.Contains(pane))
color = Color.Red;
BFLYT.CustomRectangle rect = pane.CreateRectangle();
CustomRectangle rect = pane.CreateRectangle();
//Draw a quad which is the backcolor but lighter
GL.Begin(PrimitiveType.Quads);
@ -152,7 +152,7 @@ namespace FirstPlugin.Forms
GL.PopMatrix();
}
private void DrawDefaultPane(BFLYT.Header bflyt, BFLYT.PAN1 pane)
private void DrawDefaultPane(BFLYT.PAN1 pane)
{
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
@ -175,7 +175,7 @@ namespace FirstPlugin.Forms
DrawRectangle(pane.CreateRectangle(), TexCoords, Colors);
}
private void DrawPicturePane(BFLYT.Header bflyt, BFLYT.PIC1 pane)
private void DrawPicturePane(BFLYT.PIC1 pane)
{
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
@ -195,10 +195,10 @@ namespace FirstPlugin.Forms
if (pane.TexCoords.Length > 0)
{
var mat = bflyt.MaterialList.Materials[pane.MaterialIndex];
var mat = pane.GetMaterial();
string textureMap0 = "";
if (mat.TextureMaps.Count > 0)
textureMap0 = bflyt.TextureList.Textures[mat.TextureMaps[0].ID];
textureMap0 = mat.GetTexture(0);
if (Textures.ContainsKey(textureMap0))
BindGLTexture(mat.TextureMaps[0], Textures[textureMap0]);
@ -216,7 +216,7 @@ namespace FirstPlugin.Forms
GL.BindTexture(TextureTarget.Texture2D, 0);
}
public void DrawRectangle(BFLYT.CustomRectangle rect, Vector2[] texCoords, Color[] colors, bool useLines = true)
public void DrawRectangle(CustomRectangle rect, Vector2[] texCoords, Color[] colors, bool useLines = true)
{
if (useLines)
{

View File

@ -366,7 +366,7 @@ namespace FirstPlugin
Formats.Add(typeof(CSAB));
Formats.Add(typeof(CMB));
Formats.Add(typeof(G1T));
Formats.Add(typeof(BFLYT));
Formats.Add(typeof(LayoutBXLYT.BFLYT));
Formats.Add(typeof(ZSI));
Formats.Add(typeof(IGZ_TEX));
Formats.Add(typeof(MOD));
@ -386,7 +386,7 @@ namespace FirstPlugin
if (Runtime.DEVELOPER_DEBUG_MODE)
{
Formats.Add(typeof(XCI));
Formats.Add(typeof(BFLAN));
Formats.Add(typeof(LayoutBXLYT.BFLAN));
Formats.Add(typeof(XLINK));
Formats.Add(typeof(BFSAR));
Formats.Add(typeof(GFA));

View File

@ -921,7 +921,7 @@ namespace Toolbox.Library
private static Form activeForm;
public void OpenFormDialog(IFileFormat fileFormat)
{
if (activeForm != null)
if (activeForm != null && !activeForm.IsDisposed && !activeForm.Disposing)
{
activeForm.Text = (((IFileFormat)fileFormat).FileName);
System.Reflection.MethodInfo methodFill = fileFormat.GetType().GetMethod("FillEditor");