1
0
mirror of synced 2024-12-01 10:37:25 +01:00

Add drag drop support for layout editor. Load textures per layout file

This commit is contained in:
KillzXGaming 2019-08-29 18:05:44 -04:00
parent cb5be622b8
commit 1e4b18844f
4 changed files with 97 additions and 17 deletions

View File

@ -80,7 +80,7 @@ namespace LayoutBXLYT
((LayoutEditor)control).LoadBflyt(header, FileName); ((LayoutEditor)control).LoadBflyt(header, FileName);
} }
private Header header; public Header header;
public void Load(System.IO.Stream stream) public void Load(System.IO.Stream stream)
{ {
CanSave = false; CanSave = false;

View File

@ -136,6 +136,7 @@
// //
// LayoutEditor // LayoutEditor
// //
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(549, 398); this.ClientSize = new System.Drawing.Size(549, 398);
@ -146,6 +147,8 @@
this.Controls.Add(this.stMenuStrip1); this.Controls.Add(this.stMenuStrip1);
this.IsMdiContainer = true; this.IsMdiContainer = true;
this.Name = "LayoutEditor"; this.Name = "LayoutEditor";
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.LayoutEditor_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.LayoutEditor_DragEnter);
this.ParentChanged += new System.EventHandler(this.LayoutEditor_ParentChanged); this.ParentChanged += new System.EventHandler(this.LayoutEditor_ParentChanged);
((System.ComponentModel.ISupportInitialize)(this.backColorDisplay)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.backColorDisplay)).EndInit();
this.stToolStrip1.ResumeLayout(false); this.stToolStrip1.ResumeLayout(false);

View File

@ -12,6 +12,7 @@ using WeifenLuo.WinFormsUI.Docking;
using WeifenLuo.WinFormsUI.ThemeVS2015; using WeifenLuo.WinFormsUI.ThemeVS2015;
using Toolbox.Library.IO; using Toolbox.Library.IO;
using Toolbox.Library; using Toolbox.Library;
using FirstPlugin;
namespace LayoutBXLYT namespace LayoutBXLYT
{ {
@ -55,6 +56,7 @@ namespace LayoutBXLYT
private List<LayoutViewer> Viewports = new List<LayoutViewer>(); private List<LayoutViewer> Viewports = new List<LayoutViewer>();
private LayoutViewer ActiveViewport; private LayoutViewer ActiveViewport;
private LayoutHierarchy LayoutHierarchy; private LayoutHierarchy LayoutHierarchy;
private LayoutTextureList LayoutTextureList;
private bool isLoaded = false; private bool isLoaded = false;
public void LoadBflyt(BFLYT.Header header, string fileName) public void LoadBflyt(BFLYT.Header header, string fileName)
@ -87,8 +89,8 @@ namespace LayoutBXLYT
{ {
if (LayoutHierarchy != null) if (LayoutHierarchy != null)
LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected); LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected);
if (LayoutHierarchy != null) if (LayoutTextureList != null)
LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected); LayoutTextureList.LoadTextures(activeLayout);
} }
private void OnObjectChanged(object sender, EventArgs e) private void OnObjectChanged(object sender, EventArgs e)
@ -200,9 +202,9 @@ namespace LayoutBXLYT
private void ShowTextureList() private void ShowTextureList()
{ {
LayoutTextureList textureListForm = new LayoutTextureList(); LayoutTextureList = new LayoutTextureList();
textureListForm.LoadTextures(ActiveLayout); LayoutTextureList.LoadTextures(ActiveLayout);
TextureListDock = DockShow(textureListForm, "Texture List", DockState.DockRight); TextureListDock = DockShow(LayoutTextureList, "Texture List", DockState.DockRight);
} }
private void stComboBox1_MouseDoubleClick(object sender, MouseEventArgs e) private void stComboBox1_MouseDoubleClick(object sender, MouseEventArgs e)
@ -269,5 +271,79 @@ namespace LayoutBXLYT
} }
} }
} }
private void LayoutEditor_DragDrop(object sender, DragEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string filename in files)
OpenFile(filename);
Cursor.Current = Cursors.Default;
}
private void OpenFile(string fileName)
{
//Todo if an image is dropped, we should make a picture pane if a viewer is active
var file = STFileLoader.OpenFileFormat(fileName);
if (file == null) return;
if (file is BFLYT)
LoadBflyt(((BFLYT)file).header, file.FileName);
else if (file is IArchiveFile)
SearchLayoutFiles((IArchiveFile)file);
else if (file is BFLAN)
{
}
else if (file is BNTX)
{
}
}
private void SearchLayoutFiles(IArchiveFile archiveFile)
{
foreach (var file in archiveFile.Files)
{
if (Utils.GetExtension(file.FileName) == ".bflyt")
{
var fileFormat = file.OpenFile();
fileFormat.IFileInfo.ArchiveParent = archiveFile;
if (fileFormat is BFLYT)
LoadBflyt(((BFLYT)fileFormat).header, file.FileName);
}
else if (Utils.GetExtension(file.FileName) == ".bntx")
{
}
else if (Utils.GetExtension(file.FileName) == ".bflim")
{
}
else if (Utils.GetExtension(file.FileName) == ".lyarc")
{
var fileFormat = file.OpenFile();
fileFormat.IFileInfo.ArchiveParent = archiveFile;
if (fileFormat is IArchiveFile)
SearchLayoutFiles((IArchiveFile)fileFormat);
}
}
}
private void LayoutEditor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
{
String[] strGetFormats = e.Data.GetFormats();
e.Effect = DragDropEffects.None;
}
}
} }
} }

View File

@ -38,6 +38,7 @@ namespace LayoutBXLYT
} }
private bool isLoaded = false; private bool isLoaded = false;
private Thread Thread;
public void LoadTextures(BxlytHeader header) public void LoadTextures(BxlytHeader header)
{ {
listViewCustom1.Items.Clear(); listViewCustom1.Items.Clear();
@ -60,24 +61,23 @@ namespace LayoutBXLYT
//Load textures after on a seperate thread //Load textures after on a seperate thread
Thread Thread = new Thread((ThreadStart)(() => if (Thread != null && Thread.IsAlive)
Thread.Abort();
Thread = new Thread((ThreadStart)(() =>
{ {
foreach (ListViewItem item in listViewCustom1.Items) int index = 0;
foreach (var texture in header.Textures)
{ {
if (textureList.ContainsKey(item.Text)) if (textureList.ContainsKey(texture))
{ {
LoadTextureIcon(item, textureList[item.Text]); LoadTextureIcon(index, textureList[texture]);
} }
index++;
} }
})); }));
Thread.Start(); Thread.Start();
foreach (ListViewItem item in listViewCustom1.Items)
{
if (textureList.ContainsKey(item.Text))
LoadTextureIcon(item, textureList[item.Text]);
}
listViewCustom1.EndUpdate(); listViewCustom1.EndUpdate();
isLoaded = true; isLoaded = true;
@ -88,7 +88,7 @@ namespace LayoutBXLYT
listViewCustom1.View = (View)listViewTpyeCB.SelectedItem; listViewCustom1.View = (View)listViewTpyeCB.SelectedItem;
} }
private void LoadTextureIcon(ListViewItem item, STGenericTexture texture) private void LoadTextureIcon(int index, STGenericTexture texture)
{ {
Bitmap temp = texture.GetBitmap(); Bitmap temp = texture.GetBitmap();
temp = texture.GetComponentBitmap(temp, true); temp = texture.GetComponentBitmap(temp, true);
@ -96,6 +96,7 @@ namespace LayoutBXLYT
if (listViewCustom1.InvokeRequired) if (listViewCustom1.InvokeRequired)
{ {
listViewCustom1.Invoke((MethodInvoker)delegate { listViewCustom1.Invoke((MethodInvoker)delegate {
var item = listViewCustom1.Items[index];
item.ImageIndex = imgList.Images.Count; item.ImageIndex = imgList.Images.Count;
item.SubItems.Add(texture.Format.ToString()); item.SubItems.Add(texture.Format.ToString());
item.SubItems.Add(texture.Width.ToString()); item.SubItems.Add(texture.Width.ToString());