diff --git a/File_Format_Library/FileFormats/Layout/BFLYT.cs b/File_Format_Library/FileFormats/Layout/BFLYT.cs index cc46e277..c67f29e1 100644 --- a/File_Format_Library/FileFormats/Layout/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/BFLYT.cs @@ -7,10 +7,13 @@ using Toolbox; using System.Windows.Forms; using Toolbox.Library; using Toolbox.Library.IO; +using FirstPlugin.Forms; +using Syroot.Maths; +using SharpYaml.Serialization; namespace FirstPlugin { - public class BFLYT : IFileFormat + public class BFLYT : IFileFormat, IEditor, IConvertableTextFormat { public FileType FileType { get; set; } = FileType.Layout; @@ -38,29 +41,106 @@ namespace FirstPlugin } } - public void Load(System.IO.Stream stream) + #region Text Converter Interface + public TextFileType TextFileType => TextFileType.Xml; + public bool CanConvertBack => true; + + public string ConvertToString() + { + var serializerSettings = new SerializerSettings() + { + // EmitTags = false + }; + + serializerSettings.DefaultStyle = SharpYaml.YamlStyle.Any; + serializerSettings.ComparerForKeySorting = null; + serializerSettings.RegisterTagMapping("Header", typeof(Header)); + + var serializer = new Serializer(serializerSettings); + string yaml = serializer.Serialize(header, typeof(Header)); + return yaml; + } + + public void ConvertFromString(string text) { } + + #endregion + + public LayoutEditor OpenForm() + { + LayoutEditor editor = new LayoutEditor(); + editor.Dock = DockStyle.Fill; + editor.LoadBflyt(header, FileName); + return editor; + } + + public void FillEditor(UserControl control) { + ((LayoutEditor)control).LoadBflyt(header, FileName); + } + + private Header header; + public void Load(System.IO.Stream stream) + { + CanSave = true; + + header = new Header(); + header.Read(new FileReader(stream), FileName); + } + public void Unload() { } - public void Save(System.IO.Stream stream) - { + public void Save(System.IO.Stream stream) { + header.Write(new FileWriter(stream)); } + //Thanks to SwitchThemes for flags, and enums + //https://github.com/FuryBaguette/SwitchLayoutEditor/tree/master/SwitchThemesCommon public class Header { + public string FileName { get; set; } + private const string Magic = "FLYT"; private ushort ByteOrderMark; private ushort HeaderSize; - public uint Version; + internal uint Version; - public void Read(FileReader reader) + 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 LYT1 LayoutInfo { get; set; } + public TXL1 TextureList { get; set; } + public MAT1 MaterialList { get; set; } + public FNL1 FontList { get; set; } + + // private List Sections; + + public PAN1 RootPane { get; set; } + public GRP1 RootGroup { get; set; } + + // public List Panes = new List(); + + public void Read(FileReader reader, string fileName) + { + FileName = fileName; + + reader.SetByteOrder(true); reader.ReadSignature(4, Magic); ByteOrderMark = reader.ReadUInt16(); reader.CheckByteOrderMark(ByteOrderMark); @@ -70,6 +150,12 @@ namespace FirstPlugin ushort sectionCount = reader.ReadUInt16(); reader.ReadUInt16(); //Padding + bool setRoot = false; + bool setGroupRoot = false; + + BasePane currentPane = null; + BasePane parentPane = null; + reader.SeekBegin(HeaderSize); for (int i = 0; i < sectionCount; i++) { @@ -78,10 +164,91 @@ namespace FirstPlugin string Signature = reader.ReadString(4, Encoding.ASCII); uint SectionSize = reader.ReadUInt32(); + Console.WriteLine($"{Signature} {SectionSize}"); + SectionCommon section = new SectionCommon(); switch (Signature) { + case "lyt1": + LayoutInfo = new LYT1(reader); + break; + case "txl1": + TextureList = new TXL1(reader); + break; + case "fnl1": + FontList = new FNL1(reader); + break; + case "mat1": + MaterialList = new MAT1(reader, this); + break; + case "pan1": + var panel = new PAN1(reader); + if (!setRoot) + { + RootPane = panel; + setRoot = true; + } + + SetPane(panel, parentPane); + currentPane = panel; + break; + case "pic1": + var picturePanel = new PIC1(reader); + + SetPane(picturePanel, parentPane); + currentPane = picturePanel; + break; + case "txt1": + var textPanel = new TXT1(reader); + + SetPane(textPanel, parentPane); + currentPane = textPanel; + break; + case "bnd1": + var boundsPanel = new BND1(reader); + + SetPane(boundsPanel, parentPane); + currentPane = boundsPanel; + break; + case "prt1": + var partsPanel = new PRT1(reader); + + SetPane(partsPanel, parentPane); + currentPane = partsPanel; + break; + case "wnd1": + var windowPanel = new PRT1(reader); + + SetPane(windowPanel, parentPane); + currentPane = windowPanel; + break; + case "cnt1": + break; + case "pas1": + if (currentPane != null) + parentPane = currentPane; + break; + case "pae1": + currentPane = parentPane; + parentPane = currentPane.Parent; + break; + case "grp1": + var groupPanel = new GRP1(reader, this); + + if (!setGroupRoot) + { + RootGroup = groupPanel; + setGroupRoot = true; + } + + break; + case "grs1": + break; + case "gre1": + break; + case "usd1": + break; //If the section is not supported store the raw bytes default: section.Data = reader.ReadBytes((int)SectionSize); @@ -91,8 +258,16 @@ namespace FirstPlugin section.Signature = Signature; section.SectionSize = SectionSize; - reader.SeekBegin(pos + SectionSize + 0x10); - reader.Align(16); + reader.SeekBegin(pos + SectionSize); + } + } + + private void SetPane(BasePane pane, BasePane parentPane) + { + if (parentPane != null) + { + parentPane.Childern.Add(pane); + pane.Parent = parentPane; } } @@ -106,9 +281,6 @@ namespace FirstPlugin writer.Write(ushort.MaxValue); //Reserve space for section count later writer.Seek(2); //padding - - - //Write the total file size using (writer.TemporarySeek(0x0C, System.IO.SeekOrigin.Begin)) { @@ -117,8 +289,719 @@ namespace FirstPlugin } } + public class BasePane : SectionCommon + { + public BasePane Parent { get; set; } + + public List Childern { get; set; } = new List(); + } + + public class TexCoord + { + public Vector2F TopLeft { get; set; } + public Vector2F TopRight { get; set; } + public Vector2F BottomLeft { get; set; } + public Vector2F BottomRight { get; set; } + + public TexCoord() + { + TopLeft = new Vector2F(0, 0); + TopRight = new Vector2F(1, 0); + BottomLeft = new Vector2F(0, 1); + BottomRight = new Vector2F(1, 1); + } + } + + public class TXT1 : PAN1 + { + public TXT1() : base() + { + + } + + public OriginX HorizontalAlignment + { + get => (OriginX)((TextAlignment >> 2) & 0x3); + set + { + TextAlignment &= unchecked((byte)(~0xC)); + TextAlignment |= (byte)((byte)(value) << 2); + } + } + + public OriginX VerticalAlignment + { + get => (OriginX)((TextAlignment) & 0x3); + set + { + TextAlignment &= unchecked((byte)(~0x3)); + TextAlignment |= (byte)(value); + } + } + + public ushort TextLength; + public ushort MaxTextLength; + public ushort MaterialIndex; + public ushort FontIndex; + + public byte TextAlignment { get; set; } + public LineAlign LineAlignment { get; set; } + + public float ItalicTilt { get; set; } + + public STColor8 FontForeColor { get; set; } + public STColor8 FontBackColor { get; set; } + public Vector2F FontSize { get; set; } + + public float CharacterSpace { get; set; } + public float LineSpace { get; set; } + + public Vector2F ShadowXY { get; set; } + public Vector2F ShadowXYSize { get; set; } + + public STColor8 ShadowForeColor { get; set; } + public STColor8 ShadowBackColor { get; set; } + + public float ShadowItalic { get; set; } + + public bool PerCharTransform + { + get { return (_flags & 0x10) != 0; } + set { _flags = value ? (byte)(_flags | 0x10) : unchecked((byte)(_flags & (~0x10))); } + } + public bool RestrictedTextLengthEnabled + { + get { return (_flags & 0x2) != 0; } + set { _flags = value ? (byte)(_flags | 0x2) : unchecked((byte)(_flags & (~0x2))); } + } + public bool ShadowEnabled + { + get { return (_flags & 1) != 0; } + set { _flags = value ? (byte)(_flags | 1) : unchecked((byte)(_flags & (~1))); } + } + + private byte _flags; + + public TXT1(FileReader reader) : base(reader) + { + TextLength = reader.ReadUInt16(); + MaxTextLength = reader.ReadUInt16(); + MaterialIndex = reader.ReadUInt16(); + FontIndex = reader.ReadUInt16(); + TextAlignment = reader.ReadByte(); + LineAlignment = (LineAlign)reader.ReadByte(); + _flags = reader.ReadByte(); + reader.Seek(1); //padding + ItalicTilt = reader.ReadSingle(); + uint textOffset = reader.ReadUInt32(); + FontForeColor = STColor8.FromBytes(reader.ReadBytes(4)); + FontBackColor = STColor8.FromBytes(reader.ReadBytes(4)); + FontSize = reader.ReadVec2SY(); + CharacterSpace = reader.ReadSingle(); + LineSpace = reader.ReadSingle(); + ShadowXY = reader.ReadVec2SY(); + ShadowXYSize = reader.ReadVec2SY(); + ShadowForeColor = STColor8.FromBytes(reader.ReadBytes(4)); + ShadowBackColor = STColor8.FromBytes(reader.ReadBytes(4)); + ShadowItalic = reader.ReadSingle(); + } + + public override void Write(FileWriter writer, Header header) + { + base.Write(writer, header); + writer.Write(TextLength); + writer.Write(MaxTextLength); + writer.Write(MaterialIndex); + writer.Write(FontIndex); + writer.Write(TextAlignment); + writer.Write(LineAlignment, false); + writer.Write(_flags); + writer.Seek(1); + writer.Write(ItalicTilt); + writer.Write(0); //text offset + writer.Write(FontForeColor.ToBytes()); + writer.Write(FontBackColor.ToBytes()); + writer.Write(FontSize); + writer.Write(CharacterSpace); + writer.Write(LineSpace); + writer.Write(ShadowXY); + writer.Write(ShadowXYSize); + writer.Write(ShadowForeColor.ToBytes()); + writer.Write(ShadowBackColor.ToBytes()); + writer.Write(ShadowItalic); + } + + public enum BorderType : byte + { + Standard = 0, + DeleteBorder = 1, + RenderTwoCycles = 2, + }; + + public enum LineAlign : byte + { + Unspecified = 0, + Left = 1, + Center = 2, + Right = 3, + }; + } + + public class WND1 : PAN1 + { + public WND1() : base() + { + + } + + public WND1(FileReader reader) : base(reader) + { + + } + + public override void Write(FileWriter writer, Header header) + { + base.Write(writer, header); + } + } + + public class BND1 : PAN1 + { + public BND1() : base() + { + + } + + public BND1(FileReader reader) : base(reader) + { + + } + + public override void Write(FileWriter writer, Header header) + { + base.Write(writer, header); + } + } + + public class GRP1 : BasePane + { + public string Name { get; set; } + + public List Panes { get; set; } = new List(); + + public GRP1() : base() + { + + } + + public GRP1(FileReader reader, Header header) + { + ushort numNodes = 0; + if (header.Version >= 0x05020000) + { + Name = reader.ReadString(34).Replace("\0", string.Empty); + numNodes = reader.ReadUInt16(); + } + else + { + Name = reader.ReadString(24).Replace("\0", string.Empty); + numNodes = reader.ReadUInt16(); + reader.Seek(2); //padding + } + + for (int i = 0; i < numNodes; i++) + Panes.Add(reader.ReadString(24)); + } + + public override void Write(FileWriter writer, Header header) + { + if (header.Version >= 0x05020000) + { + writer.WriteString(Name, 34); + writer.Write((ushort)Panes.Count); + } + else + { + writer.WriteString(Name, 24); + writer.Write((ushort)Panes.Count); + writer.Seek(2); + } + + for (int i = 0; i < Panes.Count; i++) + writer.WriteString(Panes[i], 24); + } + } + + public class PRT1 : PAN1 + { + public PRT1() : base() + { + + } + + public PRT1(FileReader reader) : base(reader) + { + + } + + public override void Write(FileWriter writer, Header header) + { + base.Write(writer, header); + } + } + + public class PIC1 : PAN1 + { + public TexCoord[] TexCoords { get; set; } + + public STColor8 ColorTopLeft { get; set; } + public STColor8 ColorTopRight { get; set; } + public STColor8 ColorBottomLeft { get; set; } + public STColor8 ColorBottomRight { get; set; } + + public ushort MaterialIndex { get; set; } + + public PIC1() : base() { + ColorTopLeft = STColor8.White; + ColorTopRight = STColor8.White; + ColorBottomLeft = STColor8.White; + ColorBottomRight = STColor8.White; + MaterialIndex = 0; + TexCoords = new TexCoord[1]; + TexCoords[0] = new TexCoord(); + } + + public PIC1(FileReader reader) : base(reader) + { + ColorTopLeft = STColor8.FromBytes(reader.ReadBytes(4)); + ColorTopRight = STColor8.FromBytes(reader.ReadBytes(4)); + ColorBottomLeft = STColor8.FromBytes(reader.ReadBytes(4)); + ColorBottomRight = STColor8.FromBytes(reader.ReadBytes(4)); + MaterialIndex = reader.ReadUInt16(); + byte numUVs = reader.ReadByte(); + reader.Seek(1); //padding + } + + public override void Write(FileWriter writer, Header header) + { + base.Write(writer, header); + writer.Write(ColorTopLeft.ToBytes()); + writer.Write(ColorTopRight.ToBytes()); + writer.Write(ColorBottomLeft.ToBytes()); + writer.Write(ColorBottomRight.ToBytes()); + writer.Write(MaterialIndex); + writer.Write(TexCoords != null ? TexCoords.Length : 0); + } + } + + public class PAN1 : BasePane + { + private byte _flags1; + private byte _flags2; + + public bool Visible + { + get { return (_flags1 & 0x1) == 0x1; } + set { + if (value) + _flags1 |= 0x1; + else + _flags1 &= 0xFE; + } + } + + public bool InfluenceAlpha + { + get { return (_flags1 & 0x2) == 0x2; } + set + { + if (value) + _flags1 |= 0x2; + else + _flags1 &= 0xFD; + } + } + + public OriginX originX + { + get => (OriginX)((_flags2 & 0xC0) >> 6); + set + { + _flags2 &= unchecked((byte)(~0xC0)); + _flags2 |= (byte)((byte)value << 6); + } + } + + public OriginY originY + { + get => (OriginY)((_flags2 & 0x30) >> 4); + set + { + _flags2 &= unchecked((byte)(~0x30)); + _flags2 |= (byte)((byte)value << 4); + } + } + + public OriginX ParentOriginX + { + get => (OriginX)((_flags2 & 0xC) >> 2); + set + { + _flags2 &= unchecked((byte)(~0xC)); + _flags2 |= (byte)((byte)value << 2); + } + } + + public OriginY ParentOriginY + { + get => (OriginY)((_flags2 & 0x3)); + set + { + _flags2 &= unchecked((byte)(~0x3)); + _flags2 |= (byte)value; + } + } + + public byte Alpha { get; set; } + public byte Unknown { get; set; } + + public string Name { get; set; } + public string UserDataInfo { get; set; } + + public Vector3F Translate; + public Vector3F Rotate; + public Vector2F Scale; + public float Width; + public float Height; + + public PAN1() : base() + { + + } + + public PAN1(FileReader reader) : base() + { + _flags1 = reader.ReadByte(); + _flags2 = reader.ReadByte(); + Alpha = reader.ReadByte(); + Unknown = reader.ReadByte(); + Name = reader.ReadString(0x18).Replace("\0", string.Empty); + UserDataInfo = reader.ReadString(0x18).Replace("\0", string.Empty); + Translate = reader.ReadVec3SY(); + Rotate = reader.ReadVec3SY(); + Scale = reader.ReadVec2SY(); + Width = reader.ReadSingle(); + Height = reader.ReadSingle(); + } + + public override void Write(FileWriter writer, Header header) + { + writer.Write(_flags1); + writer.Write(_flags2); + writer.Write(Alpha); + writer.Write(Unknown); + writer.WriteString(Name, 0x18); + writer.WriteString(UserDataInfo, 0x18); + writer.Write(Translate); + writer.Write(Rotate); + writer.Write(Scale); + writer.Write(Width); + writer.Write(Height); + } + + public enum OriginX : byte + { + Center = 0, + Left = 1, + Right = 2 + }; + + public enum OriginY : byte + { + Center = 0, + Top = 1, + Bottom = 2 + }; + } + + public class MAT1 : SectionCommon + { + public List Materials { get; set; } + + public MAT1() { + Materials = new List(); + } + + public MAT1(FileReader reader, Header header) : base() + { + Materials = new List(); + + long pos = reader.Position; + + ushort numMats = reader.ReadUInt16(); + reader.Seek(2); //padding + + uint[] offsets = reader.ReadUInt32s(numMats); + for (int i = 0; i < numMats; i++) + { + reader.SeekBegin(pos + offsets[i] - 8); + Materials.Add(new Material(reader, header)); + } + } + + public override void Write(FileWriter writer, Header header) + { + writer.Write((ushort)Materials.Count); + writer.Seek(2); + } + } + + public class Material + { + public string Name { get; set; } + + public STColor8 ForeColor { get; set; } + public STColor8 BackColor { get; set; } + + public List TextureMaps { get; set; } + public List TextureTransforms { get; set; } + + private int flags; + private int unknown; + + public Material() + { + TextureMaps = new List(); + TextureTransforms = new List(); + } + + public Material(FileReader reader, Header header) : base() + { + TextureMaps = new List(); + TextureTransforms = new List(); + + Name = reader.ReadString(0x1C).Replace("\0", string.Empty); + if (header.Version == 0x8030000) + { + flags = reader.ReadInt32(); + unknown = reader.ReadInt32(); + ForeColor = STColor8.FromBytes(reader.ReadBytes(4)); + BackColor = STColor8.FromBytes(reader.ReadBytes(4)); + } + else + { + ForeColor = STColor8.FromBytes(reader.ReadBytes(4)); + BackColor = STColor8.FromBytes(reader.ReadBytes(4)); + flags = reader.ReadInt32(); + } + + int texCount = flags & 3; + int mtxCount = (flags & 0xC) >> 2; + for (int i = 0; i < texCount; i++) + TextureMaps.Add(new TextureRef(reader)); + + for (int i = 0; i < mtxCount; i++) + TextureTransforms.Add(new TextureTransform(reader)); + } + + public void Write(FileWriter writer, Header header) + { + writer.WriteString(Name, 0x1C); + if (header.Version == 0x8030000) + { + writer.Write(flags); + writer.Write(unknown); + writer.Write(ForeColor); + writer.Write(BackColor); + } + else + { + writer.Write(ForeColor); + writer.Write(BackColor); + writer.Write(flags); + } + + for (int i = 0; i < TextureMaps.Count; i++) + TextureMaps[i].Write(writer); + + for (int i = 0; i < TextureTransforms.Count; i++) + TextureTransforms[i].Write(writer); + } + } + + public class TextureTransform + { + public Vector2F Translate; + public float Rotate; + public Vector2F Scale; + + public TextureTransform() { } + + public TextureTransform(FileReader reader) + { + Translate = reader.ReadVec2SY(); + Rotate = reader.ReadSingle(); + Scale = reader.ReadVec2SY(); + } + + public void Write(FileWriter writer) + { + writer.Write(Translate); + writer.Write(Rotate); + writer.Write(Scale); + } + } + + public class TextureRef + { + public ushort ID; + public byte WrapS; + public byte WrapT; + + public TextureRef() {} + + public TextureRef(FileReader reader) { + ID = reader.ReadUInt16(); + WrapS = reader.ReadByte(); + WrapT = reader.ReadByte(); + } + + public void Write(FileWriter writer) + { + writer.Write(ID); + writer.Write(WrapS); + writer.Write(WrapT); + } + } + + public class FNL1 : SectionCommon + { + public List Fonts { get; set; } + + public FNL1() + { + Fonts = new List(); + } + + public FNL1(FileReader reader) : base() + { + Fonts = new List(); + + ushort numFonts = reader.ReadUInt16(); + reader.Seek(2); //padding + + long pos = reader.Position; + + uint[] offsets = reader.ReadUInt32s(numFonts); + for (int i = 0; i < offsets.Length; i++) + { + reader.SeekBegin(offsets[i] + pos); + } + } + + public override void Write(FileWriter writer, Header header) + { + writer.Write((ushort)Fonts.Count); + writer.Seek(2); + + //Fill empty spaces for offsets later + long pos = writer.Position; + writer.Write(new uint[Fonts.Count]); + + //Save offsets and strings + for (int i = 0; i < Fonts.Count; i++) + { + writer.WriteUint32Offset(pos + (i * 4), pos); + writer.WriteString(Fonts[i]); + } + } + } + + public class TXL1 : SectionCommon + { + public List Textures { get; set; } + + public TXL1() + { + Textures = new List(); + } + + public TXL1(FileReader reader) : base() + { + Textures = new List(); + + ushort numTextures = reader.ReadUInt16(); + reader.Seek(2); //padding + + long pos = reader.Position; + + uint[] offsets = reader.ReadUInt32s(numTextures); + for (int i = 0; i < offsets.Length; i++) + { + reader.SeekBegin(offsets[i] + pos); + } + } + + public override void Write(FileWriter writer, Header header) + { + writer.Write((ushort)Textures.Count); + writer.Seek(2); + + //Fill empty spaces for offsets later + long pos = writer.Position; + writer.Write(new uint[Textures.Count]); + + //Save offsets and strings + for (int i = 0; i < Textures.Count; i++) + { + writer.WriteUint32Offset(pos + (i * 4), pos); + writer.WriteString(Textures[i]); + } + } + } + public class LYT1 : SectionCommon { + public bool DrawFromCenter { get; set; } + + public float Width { get; set; } + public float Height { get; set; } + + public float MaxPartsWidth { get; set; } + public float MaxPartsHeight { get; set; } + public string Name { get; set; } + + public LYT1() + { + DrawFromCenter = false; + Width = 0; + Height = 0; + MaxPartsWidth = 0; + MaxPartsHeight = 0; + Name = ""; + } + + public LYT1(FileReader reader) + { + DrawFromCenter = reader.ReadBoolean(); + reader.Seek(3); //padding + Width = reader.ReadSingle(); + Height = reader.ReadSingle(); + MaxPartsWidth = reader.ReadSingle(); + MaxPartsHeight = reader.ReadSingle(); + Name = reader.ReadZeroTerminatedString(); + } + + public override void Write(FileWriter writer, Header header) + { + writer.Write(DrawFromCenter); + writer.Seek(3); + writer.Write(Width); + writer.Write(Height); + writer.Write(MaxPartsWidth); + writer.Write(MaxPartsHeight); + writer.Write(Name); + } } public class SectionCommon @@ -128,7 +1011,7 @@ namespace FirstPlugin internal byte[] Data { get; set; } - public void Write(FileWriter writer) + public virtual void Write(FileWriter writer, Header header) { writer.WriteSignature(Signature); if (Data != null) diff --git a/File_Format_Library/File_Format_Library.csproj b/File_Format_Library/File_Format_Library.csproj index ff0c39a2..0b44602f 100644 --- a/File_Format_Library/File_Format_Library.csproj +++ b/File_Format_Library/File_Format_Library.csproj @@ -307,6 +307,12 @@ + + UserControl + + + LayoutViewer.cs + UserControl @@ -1069,6 +1075,9 @@ LayoutEditor.cs + + LayoutViewer.cs + BatchEditBaseAnimDataForm.cs diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs b/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs index eb0a6e16..c396a15b 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs @@ -1,4 +1,4 @@ -namespace FirstPlugin.LayoutEditor +namespace FirstPlugin.Forms { partial class LayoutEditor { @@ -28,9 +28,13 @@ /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LayoutEditor)); this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip(); this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.stToolStrip1 = new Toolbox.Library.Forms.STToolStrip(); + this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.stMenuStrip1.SuspendLayout(); + this.stToolStrip1.SuspendLayout(); this.SuspendLayout(); // // stMenuStrip1 @@ -49,15 +53,37 @@ this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20); this.editToolStripMenuItem.Text = "Edit"; // + // stToolStrip1 + // + this.stToolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripButton1}); + this.stToolStrip1.Location = new System.Drawing.Point(0, 24); + this.stToolStrip1.Name = "stToolStrip1"; + this.stToolStrip1.Size = new System.Drawing.Size(836, 25); + this.stToolStrip1.TabIndex = 3; + this.stToolStrip1.Text = "stToolStrip1"; + // + // toolStripButton1 + // + this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); + this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButton1.Name = "toolStripButton1"; + this.toolStripButton1.Size = new System.Drawing.Size(23, 22); + this.toolStripButton1.Text = "toolStripButton1"; + // // LayoutEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.stToolStrip1); this.Controls.Add(this.stMenuStrip1); this.Name = "LayoutEditor"; this.Size = new System.Drawing.Size(836, 518); this.stMenuStrip1.ResumeLayout(false); this.stMenuStrip1.PerformLayout(); + this.stToolStrip1.ResumeLayout(false); + this.stToolStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -67,5 +93,7 @@ private Toolbox.Library.Forms.STMenuStrip stMenuStrip1; private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; + private Toolbox.Library.Forms.STToolStrip stToolStrip1; + private System.Windows.Forms.ToolStripButton toolStripButton1; } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs index a26d340a..8bef51d6 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs @@ -8,13 +8,37 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace FirstPlugin.LayoutEditor +namespace FirstPlugin.Forms { public partial class LayoutEditor : UserControl { + public List LayoutFiles = new List(); + + public enum DockLayout + { + Default, + Animation, + } + public LayoutEditor() { InitializeComponent(); } + + public void LoadBflyt(BFLYT.Header header, string fileName) + { + LayoutViewer viewer = new LayoutViewer(); + this.Controls.Add(viewer); + } + + public void LoadBflan() + { + + } + + public void InitalizeEditors() + { + + } } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.resx b/File_Format_Library/GUI/BFLYT/LayoutEditor.resx index 3db3609f..0f133bd9 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.resx +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.resx @@ -120,4 +120,23 @@ 17, 17 + + 141, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + \ No newline at end of file diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.Designer.cs b/File_Format_Library/GUI/BFLYT/LayoutViewer.Designer.cs new file mode 100644 index 00000000..814a5489 --- /dev/null +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.Designer.cs @@ -0,0 +1,45 @@ +namespace FirstPlugin.Forms +{ + partial class LayoutViewer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // LayoutViewer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "LayoutViewer"; + this.Size = new System.Drawing.Size(625, 414); + this.ResumeLayout(false); + + } + + #endregion + } +} diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs new file mode 100644 index 00000000..d62d3f47 --- /dev/null +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs @@ -0,0 +1,20 @@ +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; + +namespace FirstPlugin.Forms +{ + public partial class LayoutViewer : UserControl + { + public LayoutViewer() + { + InitializeComponent(); + } + } +} diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.resx b/File_Format_Library/GUI/BFLYT/LayoutViewer.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/File_Format_Library/Main.cs b/File_Format_Library/Main.cs index 0f39b3fd..5103ff26 100644 --- a/File_Format_Library/Main.cs +++ b/File_Format_Library/Main.cs @@ -378,8 +378,9 @@ namespace FirstPlugin Formats.Add(typeof(CTR.NCCH.RomFS)); Formats.Add(typeof(DKCTF.MSBT)); Formats.Add(typeof(DKCTF.PAK)); - // Formats.Add(typeof(MSBP)); - // Formats.Add(typeof(BFGRP)); + + // Formats.Add(typeof(MSBP)); + // Formats.Add(typeof(BFGRP)); //Unfinished wip formats not ready for use if (Runtime.DEVELOPER_DEBUG_MODE) diff --git a/Switch_Toolbox_Library/IO/FileWriter.cs b/Switch_Toolbox_Library/IO/FileWriter.cs index b897f60d..ee5cd0a3 100644 --- a/Switch_Toolbox_Library/IO/FileWriter.cs +++ b/Switch_Toolbox_Library/IO/FileWriter.cs @@ -50,6 +50,14 @@ namespace Toolbox.Library.IO Write(v.W); } + public void Write(STColor color) { + Write(color.ToBytes()); + } + + public void Write(STColor8 color) { + Write(color.ToBytes()); + } + public void WriteStruct(T item) => Write(item.StructToBytes(ByteOrder == ByteOrder.BigEndian)); public void WriteSignature(string value) diff --git a/Switch_Toolbox_Library/IO/STColor.cs b/Switch_Toolbox_Library/IO/STColor.cs index f9d0367a..ee7a5a4c 100644 --- a/Switch_Toolbox_Library/IO/STColor.cs +++ b/Switch_Toolbox_Library/IO/STColor.cs @@ -57,6 +57,25 @@ namespace Toolbox.Library A = 1; } + public STColor(float r, float g, float b, float a) + { + R = r; + G = g; + B = b; + A = a; + } + + public byte[] ToBytes() + { + return new byte[] + { + (byte)Utils.FloatToIntClamp(R), + (byte)Utils.FloatToIntClamp(G), + (byte)Utils.FloatToIntClamp(B), + (byte)Utils.FloatToIntClamp(A), + }; + } + public override string ToString() { return String.Format("R:{0} G:{1} B:{2} A:{3}", R, G, B, A); @@ -66,5 +85,10 @@ namespace Toolbox.Library { return String.Format("R:{0:X2} G:{1:X2} B:{2:X2} A:{3:X2}", R, G, B, A); } + + public static STColor White + { + get { return new STColor(1, 1, 1, 1); } + } } } diff --git a/Switch_Toolbox_Library/IO/STColor8.cs b/Switch_Toolbox_Library/IO/STColor8.cs new file mode 100644 index 00000000..e4fbe102 --- /dev/null +++ b/Switch_Toolbox_Library/IO/STColor8.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Toolbox.Library +{ + //Class that contains colors and useful color related methods + public class STColor8 + { + public byte R { get; set; } + public byte G { get; set; } + public byte B { get; set; } + public byte A { get; set; } + + public Color Color + { + get + { + return Color.FromArgb(A, R, G, B); + } + set + { + var color = value; + R = color.R; + G = color.G; + B = color.B; + A = color.A; + } + } + + public static STColor8 FromBytes(byte[] color) + { + STColor8 col = new STColor8(); + col.R = color[0]; + col.G = color[1]; + col.B = color[2]; + col.A = color[3]; + return col; + } + + public STColor8() + { + R = 255; + G = 255; + B = 255; + A = 255; + } + + public STColor8(byte r, byte g, byte b, byte a) + { + R = r; + G = g; + B = b; + A = a; + } + + public byte[] ToBytes() + { + return new byte[] { R, G, B, A, }; + } + + public override string ToString() + { + return String.Format("R:{0} G:{1} B:{2} A:{3}", R, G, B, A); + } + + public string ToHexString() + { + return String.Format("R:{0:X2} G:{1:X2} B:{2:X2} A:{3:X2}", R, G, B, A); + } + + public static STColor8 White + { + get { return new STColor8(255, 255, 255, 255); } + } + } +} diff --git a/Switch_Toolbox_Library/Interfaces/Forms/IEditorForm.cs b/Switch_Toolbox_Library/Interfaces/Forms/IEditorForm.cs new file mode 100644 index 00000000..bf7070cb --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/Forms/IEditorForm.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Toolbox.Library.Forms; +using System.Windows.Forms; + +namespace Toolbox.Library +{ + /// + /// Represets a form to load from a for an . + /// + public interface IEditorForm where T : Form + { + T OpenForm(); + void FillEditor(Form Editor); + } +} diff --git a/Switch_Toolbox_Library/Interfaces/IMdiContainer.cs b/Switch_Toolbox_Library/Interfaces/IMdiContainer.cs new file mode 100644 index 00000000..e00e56a9 --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/IMdiContainer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Toolbox.Library +{ + public interface IEnableMdiContainer + { + + } +} diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index e06b3de0..7a06e7d0 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -292,7 +292,9 @@ + + @@ -305,6 +307,7 @@ + diff --git a/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.dll b/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.dll index ae31c9e6..387395ac 100644 Binary files a/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.dll and b/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.dll differ diff --git a/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.pdb b/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.pdb index 23489d71..50f5c060 100644 Binary files a/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.pdb and b/Toolbox/Lib/Syroot.NintenTools.NSW.Bfres.pdb differ diff --git a/Toolbox/Lib/WeifenLuo.WinFormsUI.Docking.dll b/Toolbox/Lib/WeifenLuo.WinFormsUI.Docking.dll new file mode 100644 index 00000000..4da5cdd4 Binary files /dev/null and b/Toolbox/Lib/WeifenLuo.WinFormsUI.Docking.dll differ diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index 98e84bf1..ff7f5e4a 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -300,6 +300,17 @@ namespace Toolbox form.MdiParent = this; form.Show(); + HasEditorActive = true; + } + else if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditorForm<>)) + { + MethodInfo method = objectType.GetMethod("OpenForm"); + var form = (Form)method.Invoke(file, new object[0]); + TabDupeIndex = 0; + form.Text = CheckTabDupes(((IFileFormat)file).FileName); + form.MdiParent = this; + form.Show(); + HasEditorActive = true; } } diff --git a/Toolbox/Toolbox.csproj b/Toolbox/Toolbox.csproj index 992be9ba..3591a8d2 100644 --- a/Toolbox/Toolbox.csproj +++ b/Toolbox/Toolbox.csproj @@ -500,6 +500,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest