Add BCLYT support. Some ram usage optmization for bflyt editor

This commit is contained in:
KillzXGaming 2019-08-30 18:53:45 -04:00
parent 0f587d2624
commit e4cb00c237
23 changed files with 1605 additions and 98 deletions

View file

@ -148,6 +148,8 @@ namespace FirstPlugin
//For saving
public List<SectionBase> Sections = new List<SectionBase>();
private string UnknownString;
public void Read(FileReader reader, PTCL ptcl)
{
uint Position = (uint)reader.Position; //Offsets are relative to this
@ -174,6 +176,7 @@ namespace FirstPlugin
BlockOffset = reader.ReadUInt16();
uint padding2 = reader.ReadUInt32();
uint FileSize = reader.ReadUInt32();
reader.Seek(Position + BlockOffset, SeekOrigin.Begin);
}
else

View file

@ -85,6 +85,8 @@ namespace LayoutBXLYT
serializerSettings.ComparerForKeySorting = null;
serializerSettings.RegisterTagMapping("Header", typeof(Header));
return FLYT.ToXml(header);
var serializer = new Serializer(serializerSettings);
string yaml = serializer.Serialize(header, typeof(Header));
return yaml;
@ -100,18 +102,18 @@ namespace LayoutBXLYT
{
LayoutEditor editor = new LayoutEditor();
editor.Dock = DockStyle.Fill;
editor.LoadBflyt(header, FileName);
editor.LoadBxlyt(header, FileName);
return editor;
}
public void FillEditor(Form control) {
((LayoutEditor)control).LoadBflyt(header, FileName);
((LayoutEditor)control).LoadBxlyt(header, FileName);
}
public Header header;
public void Load(System.IO.Stream stream)
{
CanSave = false;
CanSave = true;
header = new Header();
header.Read(new FileReader(stream), this);
@ -195,12 +197,14 @@ namespace LayoutBXLYT
if (Utils.GetExtension(file.FileName) == ".bntx")
{
BNTX bntx = (BNTX)file.OpenFile();
file.FileFormat = bntx;
foreach (var tex in bntx.Textures)
textures.Add(tex.Key, tex.Value);
}
else if (Utils.GetExtension(file.FileName) == ".bflim")
{
BFLIM bflim = (BFLIM)file.OpenFile();
file.FileFormat = bflim;
textures.Add(bflim.FileName, bflim);
}
}
@ -222,11 +226,6 @@ namespace LayoutBXLYT
//https://github.com/FuryBaguette/SwitchLayoutEditor/tree/master/SwitchThemesCommon
public class Header : BxlytHeader, IDisposable
{
public string FileName
{
get { return FileInfo.FileName; }
}
private const string Magic = "FLYT";
private ushort ByteOrderMark;
@ -239,6 +238,13 @@ namespace LayoutBXLYT
// private List<SectionCommon> Sections;
// public List<PAN1> Panes = new List<PAN1>();
public int TotalPaneCount()
{
int panes = GetPanes().Count;
int grpPanes = GetGroupPanes().Count;
return panes + grpPanes;
}
public override List<string> Textures
{
get { return TextureList.Textures; }
@ -249,6 +255,34 @@ namespace LayoutBXLYT
get { return ((BFLYT)FileInfo).GetTextures(); }
}
public List<PAN1> GetPanes()
{
List<PAN1> panes = new List<PAN1>();
GetPaneChildren(panes, (PAN1)RootPane);
return panes;
}
public List<GRP1> GetGroupPanes()
{
List<GRP1> panes = new List<GRP1>();
GetGroupChildren(panes, (GRP1)RootGroup);
return panes;
}
private void GetPaneChildren(List<PAN1> panes, PAN1 root)
{
panes.Add(root);
foreach (var pane in root.Childern)
GetPaneChildren(panes, (PAN1)pane);
}
private void GetGroupChildren(List<GRP1> panes, GRP1 root)
{
panes.Add(root);
foreach (var pane in root.Childern)
GetGroupChildren(panes, (GRP1)pane);
}
public void Read(FileReader reader, BFLYT bflyt)
{
LayoutInfo = new LYT1();
@ -276,6 +310,9 @@ namespace LayoutBXLYT
BasePane currentPane = null;
BasePane parentPane = null;
BasePane currentGroupPane = null;
BasePane parentGroupPane = null;
reader.SeekBegin(HeaderSize);
for (int i = 0; i < sectionCount; i++)
{
@ -358,10 +395,16 @@ namespace LayoutBXLYT
setGroupRoot = true;
}
SetPane(groupPanel, parentGroupPane);
currentGroupPane = groupPanel;
break;
case "grs1":
if (currentGroupPane != null)
parentGroupPane = currentGroupPane;
break;
case "gre1":
currentGroupPane = parentGroupPane;
parentGroupPane = currentGroupPane.Parent;
break;
case "usd1":
break;
@ -430,6 +473,8 @@ namespace LayoutBXLYT
}
public string Text { get; set; }
public OriginX HorizontalAlignment
{
get { return (OriginX)((TextAlignment >> 2) & 0x3); }
@ -515,10 +560,17 @@ namespace LayoutBXLYT
ShadowForeColor = STColor8.FromBytes(reader.ReadBytes(4));
ShadowBackColor = STColor8.FromBytes(reader.ReadBytes(4));
ShadowItalic = reader.ReadSingle();
if (RestrictedTextLengthEnabled)
Text = reader.ReadString(MaxTextLength);
else
Text = reader.ReadString(TextLength);
}
public override void Write(FileWriter writer, BxlytHeader header)
{
long pos = writer.Position;
base.Write(writer, header);
writer.Write(TextLength);
writer.Write(MaxTextLength);
@ -529,6 +581,7 @@ namespace LayoutBXLYT
writer.Write(_flags);
writer.Seek(1);
writer.Write(ItalicTilt);
long _ofsTextPos = writer.Position;
writer.Write(0); //text offset
writer.Write(FontForeColor.ToBytes());
writer.Write(FontBackColor.ToBytes());
@ -540,6 +593,12 @@ namespace LayoutBXLYT
writer.Write(ShadowForeColor.ToBytes());
writer.Write(ShadowBackColor.ToBytes());
writer.Write(ShadowItalic);
writer.WriteUint32Offset(_ofsTextPos, pos);
if (RestrictedTextLengthEnabled)
writer.WriteString(Text, MaxTextLength);
else
writer.WriteString(Text, TextLength);
}
public enum BorderType : byte
@ -565,14 +624,60 @@ namespace LayoutBXLYT
}
public ushort StretchLeft;
public ushort StretchRight;
public ushort StretchTop;
public ushort StretchBottm;
public ushort FrameElementLeft;
public ushort FrameElementRight;
public ushort FrameElementTop;
public ushort FrameElementBottm;
public byte FrameCount;
private byte _flag;
public WND1(FileReader reader) : base(reader)
{
long pos = reader.Position;
StretchLeft = reader.ReadUInt16();
StretchRight = reader.ReadUInt16();
StretchTop = reader.ReadUInt16();
StretchBottm = reader.ReadUInt16();
FrameElementLeft = reader.ReadUInt16();
FrameElementRight = reader.ReadUInt16();
FrameElementTop = reader.ReadUInt16();
FrameElementBottm = reader.ReadUInt16();
FrameCount = reader.ReadByte();
_flag = reader.ReadByte();
reader.ReadUInt16();//padding
uint contentOffset = reader.ReadUInt32();
uint frameOffsetTbl = reader.ReadUInt32();
}
public override void Write(FileWriter writer, BxlytHeader header)
{
long pos = writer.Position;
base.Write(writer, header);
writer.Write(StretchLeft);
writer.Write(StretchRight);
writer.Write(StretchTop);
writer.Write(StretchBottm);
writer.Write(FrameElementLeft);
writer.Write(FrameElementRight);
writer.Write(FrameElementTop);
writer.Write(FrameElementBottm);
writer.Write(FrameCount);
writer.Write(_flag);
writer.Seek(2);
long _ofsContentPos = writer.Position;
writer.Write(0);
writer.Write(0);
writer.WriteUint32Offset(_ofsContentPos, pos);
}
}
@ -799,7 +904,7 @@ namespace LayoutBXLYT
}
public byte Alpha { get; set; }
public byte Unknown { get; set; }
public byte PaneMagFlags { get; set; }
public string UserDataInfo { get; set; }
@ -813,7 +918,7 @@ namespace LayoutBXLYT
_flags1 = reader.ReadByte();
_flags2 = reader.ReadByte();
Alpha = reader.ReadByte();
Unknown = reader.ReadByte();
PaneMagFlags = reader.ReadByte();
Name = reader.ReadString(0x18).Replace("\0", string.Empty);
UserDataInfo = reader.ReadString(0x8).Replace("\0", string.Empty);
Translate = reader.ReadVec3SY();
@ -828,7 +933,7 @@ namespace LayoutBXLYT
writer.Write(_flags1);
writer.Write(_flags2);
writer.Write(Alpha);
writer.Write(Unknown);
writer.Write(PaneMagFlags);
writer.WriteString(Name, 0x18);
writer.WriteString(UserDataInfo, 0x8);
writer.Write(Translate);

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
namespace LayoutBXLYT
{
public class FLYT
{
public static string ToXml(BFLYT.Header header)
{
return "";
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -10,11 +10,6 @@ using WeifenLuo.WinFormsUI.Docking;
namespace LayoutBXLYT
{
public class LayoutDocked : DockContent
{
}
public class BasePane : SectionCommon
{
public bool DisplayInEditor { get; set; } = true;
@ -41,6 +36,13 @@ namespace LayoutBXLYT
get { return Childern.Count > 0; }
}
public BasePane()
{
originX = OriginX.Center;
originY = OriginY.Center;
ParentOriginX = OriginX.Center;
ParentOriginY = OriginY.Center;
}
public CustomRectangle CreateRectangle()
{
@ -117,6 +119,11 @@ namespace LayoutBXLYT
public class BxlytHeader : IDisposable
{
public string FileName
{
get { return FileInfo.FileName; }
}
internal IFileFormat FileInfo;
public BasePane RootPane { get; set; }
@ -200,4 +207,9 @@ namespace LayoutBXLYT
BottomPoint = bottom;
}
}
public class LayoutDocked : DockContent
{
}
}

View file

@ -277,7 +277,7 @@ namespace FirstPlugin
{
get
{
if (Textures.Any(item => item.Value.RenderableTex.GLInitialized == false))
if (Textures.Any(item => item.Value.RenderableTex == null || item.Value.RenderableTex.GLInitialized == false))
return false;
else
return true;

View file

@ -293,6 +293,8 @@
<Compile Include="FileFormats\Font\BFTTF.cs" />
<Compile Include="FileFormats\HyruleWarriors\G1M\G1M.cs" />
<Compile Include="FileFormats\HyruleWarriors\LINKDATA.cs" />
<Compile Include="FileFormats\Layout\CTR\BCLYT.cs" />
<Compile Include="FileFormats\Layout\CAFE\FLYT.cs" />
<Compile Include="FileFormats\Layout\PaneTreeWrapper.cs" />
<Compile Include="FileFormats\Layout\Common.cs" />
<Compile Include="FileFormats\Message\MSBP.cs" />
@ -322,25 +324,31 @@
<DependentUpon>FileSelector.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\LayoutHierarchy.cs">
<SubType>UserControl</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\LayoutHierarchy.Designer.cs">
<DependentUpon>LayoutHierarchy.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\LayoutProperties.cs">
<SubType>UserControl</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\LayoutProperties.Designer.cs">
<DependentUpon>LayoutProperties.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\LayoutTextDocked.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\LayoutTextDocked.Designer.cs">
<DependentUpon>LayoutTextDocked.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\LayoutTextureList.cs">
<SubType>UserControl</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\LayoutTextureList.Designer.cs">
<DependentUpon>LayoutTextureList.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BFLYT\LayoutViewer.cs">
<SubType>UserControl</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\BFLYT\LayoutViewer.Designer.cs">
<DependentUpon>LayoutViewer.cs</DependentUpon>
@ -388,8 +396,8 @@
<Compile Include="FileFormats\Shader\SHARCFBNX.cs" />
<Compile Include="FileFormats\Texture\BCLIM.cs" />
<Compile Include="FileFormats\Texture\BFLIM.cs" />
<Compile Include="FileFormats\Layout\BFLAN.cs" />
<Compile Include="FileFormats\Layout\BFLYT.cs" />
<Compile Include="FileFormats\Layout\CAFE\BFLAN.cs" />
<Compile Include="FileFormats\Layout\CAFE\BFLYT.cs" />
<Compile Include="FileFormats\BFRES\Bfres Structs\CurveHelper.cs" />
<Compile Include="FileFormats\BFRES\BFRES.cs" />
<Compile Include="FileFormats\Texture\NUT.cs" />

View file

@ -24,18 +24,18 @@ namespace LayoutBXLYT
listViewCustom1.MultiSelect = true;
}
public List<BFLYT> SelectedLayouts()
public List<IFileFormat> SelectedLayouts()
{
List<BFLYT> layouts = new List<BFLYT>();
List<IFileFormat> layouts = new List<IFileFormat>();
foreach (ListViewItem item in listViewCustom1.SelectedItems)
layouts.Add((BFLYT)item.Tag);
layouts.Add((IFileFormat)item.Tag);
listViewCustom1.Items.Clear();
return layouts;
}
public void LoadLayoutFiles(List<BFLYT> layoutFiles)
public void LoadLayoutFiles(List<IFileFormat> layoutFiles)
{
listViewCustom1.BeginUpdate();
foreach (var file in layoutFiles)

View file

@ -36,11 +36,12 @@
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clearWorkspaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textureListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textConverterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.backColorDisplay)).BeginInit();
this.stToolStrip1.SuspendLayout();
this.stMenuStrip1.SuspendLayout();
@ -118,10 +119,17 @@
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(127, 22);
this.openToolStripMenuItem.Text = "Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// clearWorkspaceToolStripMenuItem
//
this.clearWorkspaceToolStripMenuItem.Name = "clearWorkspaceToolStripMenuItem";
this.clearWorkspaceToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.clearWorkspaceToolStripMenuItem.Size = new System.Drawing.Size(127, 22);
this.clearWorkspaceToolStripMenuItem.Text = "Clear Files";
this.clearWorkspaceToolStripMenuItem.Click += new System.EventHandler(this.clearWorkspaceToolStripMenuItem_Click);
//
@ -134,7 +142,8 @@
// viewToolStripMenuItem
//
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.textureListToolStripMenuItem});
this.textureListToolStripMenuItem,
this.textConverterToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View";
@ -142,16 +151,16 @@
// textureListToolStripMenuItem
//
this.textureListToolStripMenuItem.Name = "textureListToolStripMenuItem";
this.textureListToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.textureListToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textureListToolStripMenuItem.Text = "Texture List";
this.textureListToolStripMenuItem.Click += new System.EventHandler(this.textureListToolStripMenuItem_Click);
//
// openToolStripMenuItem
// textConverterToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.openToolStripMenuItem.Text = "Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
this.textConverterToolStripMenuItem.Name = "textConverterToolStripMenuItem";
this.textConverterToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textConverterToolStripMenuItem.Text = "Text Converter";
this.textConverterToolStripMenuItem.Click += new System.EventHandler(this.textConverterToolStripMenuItem_Click);
//
// LayoutEditor
//
@ -193,5 +202,6 @@
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem clearWorkspaceToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textConverterToolStripMenuItem;
}
}

View file

@ -18,6 +18,8 @@ namespace LayoutBXLYT
{
public partial class LayoutEditor : Form
{
private Dictionary<string, STGenericTexture> Textures;
public List<BxlytHeader> LayoutFiles = new List<BxlytHeader>();
private BxlytHeader ActiveLayout;
@ -35,6 +37,8 @@ namespace LayoutBXLYT
{
InitializeComponent();
Textures = new Dictionary<string, STGenericTexture>();
var theme = new VS2015DarkTheme();
this.dockPanel1.Theme = theme;
this.dockPanel1.BackColor = FormThemes.BaseTheme.FormBackColor;
@ -53,14 +57,15 @@ namespace LayoutBXLYT
private LayoutHierarchy LayoutHierarchy;
private LayoutTextureList LayoutTextureList;
private LayoutProperties LayoutProperties;
private LayoutTextDocked TextConverter;
private bool isLoaded = false;
public void LoadBflyt(BFLYT.Header header, string fileName)
public void LoadBxlyt(BxlytHeader header, string fileName)
{
LayoutFiles.Add(header);
ActiveLayout = header;
LayoutViewer Viewport = new LayoutViewer(header);
LayoutViewer Viewport = new LayoutViewer(header, Textures);
Viewport.Dock = DockStyle.Fill;
Viewport.Show(dockPanel1, DockState.Document);
Viewport.DockHandler.AllowEndUserDocking = false;
@ -89,6 +94,8 @@ namespace LayoutBXLYT
LayoutTextureList.Reset();
if (LayoutProperties != null)
LayoutProperties.Reset();
if (TextConverter != null)
TextConverter.Reset();
}
private void ReloadEditors(BxlytHeader activeLayout)
@ -101,6 +108,11 @@ namespace LayoutBXLYT
LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected);
if (LayoutTextureList != null)
LayoutTextureList.LoadTextures(activeLayout);
if (TextConverter != null)
{
if (ActiveLayout.FileInfo is BFLYT)
TextConverter.LoadLayout((BFLYT)ActiveLayout.FileInfo);
}
}
private void OnObjectChanged(object sender, EventArgs e)
@ -277,7 +289,9 @@ namespace LayoutBXLYT
if (file == null) return;
if (file is BFLYT)
LoadBflyt(((BFLYT)file).header, file.FileName);
LoadBxlyt(((BFLYT)file).header, file.FileName);
else if (file is BCLYT)
LoadBxlyt(((BCLYT)file).header, file.FileName);
else if (file is IArchiveFile)
{
var layouts = SearchLayoutFiles((IArchiveFile)file);
@ -289,13 +303,19 @@ namespace LayoutBXLYT
{
foreach (var layout in form.SelectedLayouts())
{
LoadBflyt(layout.header, file.FileName);
if (layout is BFLYT)
LoadBxlyt(((BFLYT)layout).header, file.FileName);
if (layout is BCLYT)
LoadBxlyt(((BCLYT)layout).header, file.FileName);
}
}
}
else if (layouts.Count > 0)
{
LoadBflyt(layouts[0].header, file.FileName);
if (layouts[0] is BFLYT)
LoadBxlyt(((BFLYT)layouts[0]).header, file.FileName);
if (layouts[0] is BCLYT)
LoadBxlyt(((BCLYT)layouts[0]).header, file.FileName);
}
}
else if (file is BFLAN)
@ -308,19 +328,24 @@ namespace LayoutBXLYT
}
}
private List<BFLYT> SearchLayoutFiles(IArchiveFile archiveFile)
private List<IFileFormat> SearchLayoutFiles(IArchiveFile archiveFile)
{
List<BFLYT> layouts = new List<BFLYT>();
List<IFileFormat> layouts = new List<IFileFormat>();
foreach (var file in archiveFile.Files)
{
var fileFormat = STFileLoader.OpenFileFormat(file.FileName,
new Type[] { typeof(BFLYT), typeof(SARC) }, file.FileData);
new Type[] { typeof(BFLYT), typeof(BCLYT), typeof(SARC) }, file.FileData);
if (fileFormat is BFLYT)
{
fileFormat.IFileInfo.ArchiveParent = archiveFile;
layouts.Add((BFLYT)fileFormat);
layouts.Add(fileFormat);
}
else if (fileFormat is BCLYT)
{
fileFormat.IFileInfo.ArchiveParent = archiveFile;
layouts.Add(fileFormat);
}
else if (Utils.GetExtension(file.FileName) == ".bntx")
{
@ -374,5 +399,15 @@ namespace LayoutBXLYT
OpenFile(filename);
}
}
private void textConverterToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ActiveLayout.FileInfo is BFLYT)
{
TextConverter = new LayoutTextDocked();
TextConverter.LoadLayout((BFLYT)ActiveLayout.FileInfo);
TextConverter.Show(dockPanel1, DockState.DockLeft);
}
}
}
}

View file

@ -34,15 +34,15 @@ namespace LayoutBXLYT
private bool isLoaded = false;
private EventHandler OnProperySelected;
public void LoadLayout(BxlytHeader bflyt, EventHandler onPropertySelected)
public void LoadLayout(BxlytHeader bxlyt, EventHandler onPropertySelected)
{
isLoaded = false;
OnProperySelected = onPropertySelected;
treeView1.Nodes.Clear();
LoadPane(bflyt.RootGroup);
LoadPane(bflyt.RootPane);
LoadPane(bxlyt.RootGroup);
LoadPane(bxlyt.RootPane);
isLoaded = true;
}
@ -64,6 +64,9 @@ namespace LayoutBXLYT
if (pane is BFLYT.WND1) imageKey = "WindowPane";
else if (pane is BFLYT.PIC1) imageKey = "PicturePane";
else if (pane is BFLYT.BND1) imageKey = "BoundryPane";
else if (pane is BCLYT.WND1) imageKey = "WindowPane";
else if (pane is BCLYT.BND1) imageKey = "BoundryPane";
else if (pane is BCLYT.PIC1) imageKey = "PicturePane";
else imageKey = "NullPane";
paneNode.ImageKey = imageKey;

View file

@ -28,32 +28,32 @@
/// </summary>
private void InitializeComponent()
{
this.stTabControl1 = new FlatTabControl.FlatTabControl();
this.stPropertyGrid1 = new Toolbox.Library.Forms.STPropertyGrid();
this.SuspendLayout();
//
// stTabControl1
// stPropertyGrid1
//
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(368, 338);
this.stTabControl1.TabIndex = 0;
this.stPropertyGrid1.AutoScroll = true;
this.stPropertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPropertyGrid1.Location = new System.Drawing.Point(0, 0);
this.stPropertyGrid1.Name = "stPropertyGrid1";
this.stPropertyGrid1.ShowHintDisplay = true;
this.stPropertyGrid1.Size = new System.Drawing.Size(352, 299);
this.stPropertyGrid1.TabIndex = 0;
//
// LayoutProperties
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.stTabControl1);
this.ClientSize = new System.Drawing.Size(352, 299);
this.Controls.Add(this.stPropertyGrid1);
this.Name = "LayoutProperties";
this.Size = new System.Drawing.Size(368, 338);
this.ResumeLayout(false);
}
#endregion
private FlatTabControl.FlatTabControl stTabControl1;
private Toolbox.Library.Forms.STPropertyGrid stPropertyGrid1;
}
}

View file

@ -16,37 +16,36 @@ namespace LayoutBXLYT
public LayoutProperties()
{
InitializeComponent();
stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor;
}
public void Reset()
{
stTabControl1.Controls.Clear();
stPropertyGrid1.LoadProperty(null);
}
public void LoadProperties(BasePane prop, Action propChanged)
{
stTabControl1.Controls.Clear();
if (prop is BFLYT.PIC1)
{
LoadPropertyTab("Pane", prop, propChanged);
LoadPropertyTab("Materials", ((BFLYT.PIC1)prop).GetMaterial(), propChanged);
}
else
LoadPropertyTab("Pane", prop, propChanged);
LoadPropertyTab("Pane", prop, propChanged);
}
private void LoadPropertyTab(string text, object prop, Action propChanged)
{
TabPage page = new TabPage();
DoubleBufferedTabPage page = new DoubleBufferedTabPage();
page.Enabled = false;
page.Text = text;
var propGrid = new STPropertyGrid();
propGrid.Dock = DockStyle.Fill;
propGrid.LoadProperty(prop, propChanged);
page.Controls.Add(propGrid);
stTabControl1.Controls.Add(page);
stPropertyGrid1.LoadProperty(prop, propChanged);
}
class DoubleBufferedTabPage : System.Windows.Forms.TabPage
{
public DoubleBufferedTabPage()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
}
}
private void stTabControl1_TabIndexChanged(object sender, EventArgs e)
{
}
}
}

View file

@ -0,0 +1,37 @@
namespace LayoutBXLYT
{
partial class LayoutTextDocked
{
/// <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()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}

View file

@ -0,0 +1,36 @@
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 Toolbox.Library.Forms;
namespace LayoutBXLYT
{
public partial class LayoutTextDocked : LayoutDocked
{
TextEditor editor;
public LayoutTextDocked()
{
InitializeComponent();
editor = new TextEditor();
editor.Dock = DockStyle.Fill;
Controls.Add(editor);
}
public void Reset()
{
editor.FillEditor("");
}
public void LoadLayout(BFLYT bflyt)
{
editor.FillEditor(bflyt.ConvertToString());
}
}
}

View file

@ -31,17 +31,22 @@ namespace LayoutBXLYT
public BxlytHeader LayoutFile;
private static Dictionary<string, STGenericTexture> Textures;
private Dictionary<string, STGenericTexture> Textures;
public LayoutViewer(BFLYT.Header bflyt)
public LayoutViewer(BxlytHeader bxlyt, Dictionary<string, STGenericTexture> textures)
{
InitializeComponent();
LayoutFile = bflyt;
Text = bflyt.FileName;
LayoutFile = bxlyt;
Text = bxlyt.FileName;
Textures = new Dictionary<string, STGenericTexture>();
if (bflyt.TextureList.Textures.Count > 0)
Textures = ((BFLYT)bflyt.FileInfo).GetTextures();
Textures = textures;
if (bxlyt.Textures.Count > 0)
{
if (bxlyt.FileInfo is BFLYT)
Textures = ((BFLYT)bxlyt.FileInfo).GetTextures();
else if (bxlyt.FileInfo is BCLYT)
Textures = ((BCLYT)bxlyt.FileInfo).GetTextures();
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
@ -115,8 +120,12 @@ namespace LayoutBXLYT
{
if (pane is BFLYT.PIC1)
DrawPicturePane((BFLYT.PIC1)pane);
else if (pane is BCLYT.PIC1)
DrawDefaultPane((BCLYT.PIC1)pane);
else if (pane is BFLYT.PAN1)
DrawDefaultPane((BFLYT.PAN1)pane);
else if (pane is BCLYT.PAN1)
DrawDefaultPane((BCLYT.PAN1)pane);
}
else
isRoot = false;
@ -164,7 +173,7 @@ namespace LayoutBXLYT
GL.PopMatrix();
}
private void DrawDefaultPane(BFLYT.PAN1 pane)
private void DrawDefaultPane(BasePane pane)
{
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
@ -187,6 +196,47 @@ namespace LayoutBXLYT
DrawRectangle(pane.CreateRectangle(), TexCoords, Colors);
}
private void DrawPicturePane(BCLYT.PIC1 pane)
{
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,0)
};
Color[] Colors = new Color[] {
pane.ColorTopLeft.Color,
pane.ColorTopRight.Color,
pane.ColorBottomRight.Color,
pane.ColorBottomLeft.Color,
};
GL.Enable(EnableCap.Texture2D);
if (pane.TexCoords.Length > 0)
{
var mat = pane.GetMaterial();
string textureMap0 = "";
if (mat.TextureMaps.Count > 0)
textureMap0 = mat.GetTexture(0);
// if (Textures.ContainsKey(textureMap0))
// BindGLTexture(mat.TextureMaps[0], Textures[textureMap0]);
TexCoords = new Vector2[] {
pane.TexCoords[0].TopLeft.ToTKVector2(),
pane.TexCoords[0].TopRight.ToTKVector2(),
pane.TexCoords[0].BottomRight.ToTKVector2(),
pane.TexCoords[0].BottomLeft.ToTKVector2(),
};
}
DrawRectangle(pane.CreateRectangle(), TexCoords, Colors, false);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
private void DrawPicturePane(BFLYT.PIC1 pane)
{
Vector2[] TexCoords = new Vector2[] {
@ -473,6 +523,18 @@ namespace LayoutBXLYT
}
}
protected override void OnClosed(EventArgs e)
{
foreach (var tex in LayoutFile.Textures)
{
if (Textures.ContainsKey(tex))
{
Textures[tex].DisposeRenderable();
Textures.Remove(tex);
}
}
}
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);

View file

@ -367,6 +367,7 @@ namespace FirstPlugin
Formats.Add(typeof(CMB));
Formats.Add(typeof(G1T));
Formats.Add(typeof(LayoutBXLYT.BFLYT));
Formats.Add(typeof(LayoutBXLYT.BCLYT));
Formats.Add(typeof(ZSI));
Formats.Add(typeof(IGZ_TEX));
Formats.Add(typeof(MOD));

View file

@ -399,18 +399,6 @@ namespace FlatTabControl
private void FlatTabControl_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (TabPage tpCheck in TabPages)
{
tpCheck.BackColor = FormThemes.BaseTheme.TabPageInactive;
tpCheck.ForeColor = FormThemes.BaseTheme.DisabledItemColor;
}
if (SelectedTab != null)
{
SelectedTab.BackColor = FormThemes.BaseTheme.TabPageActive;
SelectedTab.ForeColor = FormThemes.BaseTheme.TextForeColor;
}
UpdateUpDown();
Invalidate(); // we need to update border and background colors
}

View file

@ -281,6 +281,35 @@ namespace Toolbox.Library.IO
return ReadString(BinaryStringFormat.ZeroTerminated, encoding);
}
}
public STColor8[] ReadColor8sRGBA(int count)
{
STColor8[] colors = new STColor8[count];
for (int i = 0; i < count; i++)
colors[i] = STColor8.FromBytes(ReadBytes(4));
return colors;
}
public STColor8 ReadColor8RGBA()
{
return STColor8.FromBytes(ReadBytes(4));
}
public STColor[] ReadColorsRGBA(int count)
{
STColor[] colors = new STColor[count];
for (int i = 0; i < count; i++)
colors[i] = STColor.FromFloats(ReadSingles(4));
return colors;
}
public STColor ReadColorRGBA()
{
return STColor.FromFloats(ReadSingles(4));
}
public static byte[] DeflateZLIB(byte[] i)
{
MemoryStream output = new MemoryStream();

View file

@ -58,6 +58,12 @@ namespace Toolbox.Library.IO
Write(color.ToBytes());
}
public void Write(STColor8[] colors)
{
foreach (var color in colors)
Write(color.ToBytes());
}
public void WriteStruct<T>(T item) => Write(item.StructToBytes(ByteOrder == ByteOrder.BigEndian));
public void WriteSignature(string value)

View file

@ -45,7 +45,16 @@ namespace Toolbox.Library
col.G = color[1] / 255f;
col.B = color[2] / 255f;
col.A = color[3] / 255f;
return col;
}
public static STColor FromFloats(float[] color)
{
STColor col = new STColor();
col.R = color[0];
col.G = color[1];
col.B = color[2];
col.A = color[3];
return col;
}

View file

@ -31,6 +31,31 @@ namespace Toolbox.Library.IO
return null;
}
public static Type CheckFileFormatType(string FileName, Type[] FileTypes, byte[] data = null)
{
//Todo. Create a compression list like IFileFormat to decompress via an Identiy method
data = CheckCompression(FileName, data);
Stream stream;
if (data != null)
stream = new MemoryStream(data);
else
stream = File.OpenRead(FileName);
foreach (IFileFormat fileFormat in FileManager.GetFileFormats())
{
fileFormat.FileName = Path.GetFileName(FileName);
foreach (Type type in FileTypes)
{
if (fileFormat.Identify(stream) && fileFormat.GetType() == type)
return type;
}
}
return typeof(IFileFormat);
}
public static IFileFormat OpenFileFormat(string FileName, Type[] FileTypes, byte[] data = null)
{
//Todo. Create a compression list like IFileFormat to decompress via an Identiy method