From f8d8d0ea3068d414964cda8a665aa8456c8c1c98 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Wed, 11 Sep 2019 19:23:17 -0400 Subject: [PATCH] Bflyt loading fixes --- File_Format_Library/FileFormats/Font/BFTTF.cs | 25 ++++-- .../FileFormats/Layout/BxlytToGL.cs | 82 +++++++++++++++++-- .../FileFormats/Layout/CAFE/BFLYT.cs | 57 ++++++++++++- .../FileFormats/Layout/CAFE/BflytShader.cs | 4 +- .../STProgressBar.Designer.cs | 0 .../Custom/{ => ProgressBar}/STProgressBar.cs | 26 +++++- .../{ => ProgressBar}/STProgressBar.resx | 0 Switch_Toolbox_Library/Toolbox_Library.csproj | 6 +- 8 files changed, 174 insertions(+), 26 deletions(-) rename Switch_Toolbox_Library/Forms/Custom/{ => ProgressBar}/STProgressBar.Designer.cs (100%) rename Switch_Toolbox_Library/Forms/Custom/{ => ProgressBar}/STProgressBar.cs (71%) rename Switch_Toolbox_Library/Forms/Custom/{ => ProgressBar}/STProgressBar.resx (100%) diff --git a/File_Format_Library/FileFormats/Font/BFTTF.cs b/File_Format_Library/FileFormats/Font/BFTTF.cs index b59ec482..879ebd32 100644 --- a/File_Format_Library/FileFormats/Font/BFTTF.cs +++ b/File_Format_Library/FileFormats/Font/BFTTF.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; using Toolbox; using System.Windows.Forms; using Toolbox.Library; @@ -101,15 +101,24 @@ namespace FirstPlugin public override void OnClick(TreeView treeview) { - HexEditor editor = (HexEditor)LibraryGUI.GetActiveContent(typeof(HexEditor)); - if (editor == null) - { - editor = new HexEditor(); - LibraryGUI.LoadEditor(editor); - } + System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection(); + + var fontDataPtr = Marshal.AllocCoTaskMem(DecryptedFont.Length); + Marshal.Copy(DecryptedFont, 0, fontDataPtr, DecryptedFont.Length); + privateFonts.AddMemoryFont(fontDataPtr, DecryptedFont.Length); + + System.Drawing.Font font = new System.Drawing.Font(privateFonts.Families[0], 12); + + var texbox = new STTextBox() { Multiline = true, Dock = DockStyle.Fill }; + + UserControl editor = new UserControl(); + editor.Controls.Add(texbox); + LibraryGUI.LoadEditor(editor); + editor.Text = Text; editor.Dock = DockStyle.Fill; - editor.LoadData(DecryptedFont); + editor.Font = font; + texbox.Text = "Preview Text!"; } private static UInt32 GetUInt32(byte[] data, int pos) diff --git a/File_Format_Library/FileFormats/Layout/BxlytToGL.cs b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs index add6e16d..190784bc 100644 --- a/File_Format_Library/FileFormats/Layout/BxlytToGL.cs +++ b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs @@ -193,6 +193,57 @@ namespace LayoutBXLYT BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); } + + public static void DrawAlignmentPane(BasePane pane, byte effectiveAlpha, List SelectedPanes) + { + Vector2[] TexCoords = new Vector2[] { + new Vector2(1,1), + new Vector2(0,1), + new Vector2(0,0), + new Vector2(1,0) + }; + + Color color = Color.Orange; + if (SelectedPanes.Contains(pane)) + color = Color.Red; + + color = Color.FromArgb(70, color); + + Color[] Colors = new Color[] { + color, + color, + color, + color, + }; + + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + } + + public static void DrawScissorPane(BasePane pane, byte effectiveAlpha, List SelectedPanes) + { + Vector2[] TexCoords = new Vector2[] { + new Vector2(1,1), + new Vector2(0,1), + new Vector2(0,0), + new Vector2(1,0) + }; + + Color color = Color.Yellow; + if (SelectedPanes.Contains(pane)) + color = Color.Red; + + color = Color.FromArgb(70, color); + + Color[] Colors = new Color[] { + color, + color, + color, + color, + }; + + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + } + public static void DrawWindowPane(BasePane pane, byte effectiveAlpha, Dictionary Textures) { uint sizeX = (uint)pane.Width; @@ -332,9 +383,26 @@ namespace LayoutBXLYT GL.PopMatrix(); } } - else if (window.FrameCount == 4) + else if (window.FrameCount == 4) //4 corners with specific texture mapping { + // _________ + //|______| | + //| | | | + //| |___|__| + //|__|______| + var frame1 = window.WindowFrames[0]; + var frame2 = window.WindowFrames[0]; + var frame3 = window.WindowFrames[0]; + var frame4 = window.WindowFrames[0]; + + uint contentWidth = sizeX - (uint)window.FrameElementRight - (uint)window.FrameElementLeft; + uint contentHeight = sizeY - (uint)window.FrameElementTop - (uint)window.FrameElementBottm; + + RenderWindowContent(pane, + contentWidth, + contentHeight, + window.Content, effectiveAlpha, Textures); } break; case WindowKind.Horizontal: @@ -404,19 +472,19 @@ namespace LayoutBXLYT }; Color[] colors = new Color[] { - content.ColorTopLeft.Color, - content.ColorTopRight.Color, - content.ColorBottomRight.Color, content.ColorBottomLeft.Color, + content.ColorBottomRight.Color, + content.ColorTopRight.Color, + content.ColorTopLeft.Color, }; if (content.TexCoords.Count > 0) { texCoords = new Vector2[] { - content.TexCoords[0].TopLeft.ToTKVector2(), - content.TexCoords[0].TopRight.ToTKVector2(), - content.TexCoords[0].BottomRight.ToTKVector2(), content.TexCoords[0].BottomLeft.ToTKVector2(), + content.TexCoords[0].BottomRight.ToTKVector2(), + content.TexCoords[0].TopRight.ToTKVector2(), + content.TexCoords[0].TopLeft.ToTKVector2(), }; } diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index 08b2ab05..33269b39 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -196,7 +196,6 @@ namespace LayoutBXLYT.Cafe public Dictionary GetTextures() { - BFLIM test = new BFLIM(); Dictionary textures = new Dictionary(); if (File.Exists(FilePath)) @@ -225,7 +224,7 @@ namespace LayoutBXLYT.Cafe if (!textures.ContainsKey(tex.Key)) textures.Add(tex.Key, tex.Value); } - else if (test.Identify(new MemoryStream(file.FileData))) + if (Utils.GetExtension(file.FileName) == ".bflim") { BFLIM bflim = (BFLIM)file.OpenFile(); file.FileFormat = bflim; @@ -464,6 +463,20 @@ namespace LayoutBXLYT.Cafe SetPane(windowPanel, parentPane); currentPane = windowPanel; break; + case "scr1": + var scissorPane = new SCR1(reader, this); + AddPaneToTable(scissorPane); + + SetPane(scissorPane, parentPane); + currentPane = scissorPane; + break; + case "ali1": + var alignmentPane = new ALI1(reader, this); + AddPaneToTable(alignmentPane); + + SetPane(alignmentPane, parentPane); + currentPane = alignmentPane; + break; case "pas1": if (currentPane != null) parentPane = currentPane; @@ -1054,6 +1067,46 @@ namespace LayoutBXLYT.Cafe } } + public class ALI1 : PAN1 + { + public override string Signature { get; } = "ali1"; + + public ALI1() : base() + { + + } + + public ALI1(FileReader reader, Header header) : base(reader) + { + + } + + public override void Write(FileWriter writer, LayoutHeader header) + { + base.Write(writer, header); + } + } + + public class SCR1 : PAN1 + { + public override string Signature { get; } = "scr1"; + + public SCR1() : base() + { + + } + + public SCR1(FileReader reader, Header header) : base(reader) + { + + } + + public override void Write(FileWriter writer, LayoutHeader header) + { + base.Write(writer, header); + } + } + public class BND1 : PAN1 { public override string Signature { get; } = "bnd1"; diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs index 4eb4c666..e9a7a178 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs @@ -28,7 +28,7 @@ namespace LayoutBXLYT SetInt("hasTexture0", 0); SetInt("numTextureMaps", 0); SetInt("flipTexture", 0); - + SetVec2("uvScale0", new Vector2(1,1)); SetFloat("uvRotate0", 0); SetVec2("uvTranslate0", new Vector2(0, 0)); @@ -45,8 +45,6 @@ namespace LayoutBXLYT SetVec2("uvTranslate0", new Vector2(0, 0)); SetInt("flipTexture", 0); - Console.WriteLine("debugShading " + (int)Runtime.LayoutEditor.Shading); - BindTextureUniforms(); string textureMap0 = ""; diff --git a/Switch_Toolbox_Library/Forms/Custom/STProgressBar.Designer.cs b/Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.Designer.cs similarity index 100% rename from Switch_Toolbox_Library/Forms/Custom/STProgressBar.Designer.cs rename to Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.Designer.cs diff --git a/Switch_Toolbox_Library/Forms/Custom/STProgressBar.cs b/Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.cs similarity index 71% rename from Switch_Toolbox_Library/Forms/Custom/STProgressBar.cs rename to Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.cs index 0f296cd2..a375b84b 100644 --- a/Switch_Toolbox_Library/Forms/Custom/STProgressBar.cs +++ b/Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.cs @@ -5,13 +5,15 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; -using System.Threading.Tasks; +using System.Threading; using System.Windows.Forms; namespace Toolbox.Library { public partial class STProgressBar : Form { + private Thread Thread; + public STProgressBar() { InitializeComponent(); @@ -26,9 +28,10 @@ namespace Toolbox.Library else progressBar1.Value = value; + progressBar1.Refresh(); + if (value >= 100) Close(); - progressBar1.Refresh(); } } @@ -59,9 +62,26 @@ namespace Toolbox.Library } } - private void ProgressBar_FormClosed(object sender, FormClosedEventArgs e) + /// + /// Runs an action on another thread. Runs unless the user cancels it or finishes + /// + /// + public void RunAction(Action action) { + Thread = new Thread( + () => + { + try { action();} + finally + { + Value = 100; + } + }) { IsBackground = true }; + Thread.Start(); + } + private void ProgressBar_FormClosed(object sender, FormClosedEventArgs e) { + Thread?.Abort(); } private void ProgressBarWindow_Load(object sender, EventArgs e) diff --git a/Switch_Toolbox_Library/Forms/Custom/STProgressBar.resx b/Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.resx similarity index 100% rename from Switch_Toolbox_Library/Forms/Custom/STProgressBar.resx rename to Switch_Toolbox_Library/Forms/Custom/ProgressBar/STProgressBar.resx diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index 730a2a48..94dba090 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -768,10 +768,10 @@ AssimpMeshSelector.cs - + Form - + STProgressBar.cs @@ -989,7 +989,7 @@ ObjectList.cs - + STProgressBar.cs