1
0
mirror of synced 2024-12-11 07:16:05 +01:00
Switch-Toolbox/File_Format_Library/FileFormats/Layout/TextureManager.cs
KillzXGaming 0882c488c9 Some more bug fixes
Fixed hit detection if the pane has custom scaling.
Improve multi selection for panes (uses one selection box)
Improve selecting (ctrl can be used properly to multi select, and mosue clicking already selected panes will allow dragging.
Fix hash only sarcs to auto generate if name changed or new files added.
Fixed texture folders for newly added textures for layouts
2019-10-15 17:48:52 -04:00

169 lines
6.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Toolbox.Library;
using FirstPlugin;
using System.Windows.Forms;
namespace LayoutBXLYT
{
public class TextureManager : IDisposable
{
public BxlytHeader LayoutFile;
public Dictionary<string, BNTX> BinaryContainers = new Dictionary<string, BNTX>();
//The archive to put textures in if necessary
public Dictionary<string, IArchiveFile> ArchiveFile = new Dictionary<string, IArchiveFile>();
public IArchiveFile ArchiveParent
{
get { return LayoutFile.FileInfo.IFileInfo.ArchiveParent; }
}
public PlatformType Platform = PlatformType.WiiU;
public enum PlatformType
{
WiiU, //bflim
ThreeDS, //bclim and bflim
DS, //
Gamecube, //bti
Switch, //bntx
Wii, //TPL
}
public STGenericTexture EditTexture(string name)
{
STGenericTexture texture = null;
switch (Platform)
{
case PlatformType.Switch:
{
foreach (var bntx in BinaryContainers.Values)
{
Console.WriteLine("bntx " + name + " " + bntx.Textures.ContainsKey(name));
if (bntx.Textures.ContainsKey(name))
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = bntx.Textures[name].ReplaceFilter;
if (ofd.ShowDialog() == DialogResult.OK)
{
bntx.Textures[name].Replace(ofd.FileName);
return bntx.Textures[name];
}
}
}
}
break;
case PlatformType.WiiU:
{
if (ArchiveParent == null) return null;
foreach (var file in ArchiveParent.Files)
{
if (file.FileName == name)
{
var fileFormat = file.FileFormat;
if (fileFormat == null)
fileFormat = file.OpenFile();
if (fileFormat is BFLIM)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = ((BFLIM)fileFormat).ReplaceFilter;
ofd.FileName = name;
if (ofd.ShowDialog() == DialogResult.OK)
{
((BFLIM)fileFormat).Replace(ofd.FileName);
((BFLIM)fileFormat).Text = name;
return (BFLIM)fileFormat;
}
}
}
}
}
break;
}
return texture;
}
public List<STGenericTexture> AddTextures()
{
List<STGenericTexture> textures = new List<STGenericTexture>();
switch (Platform)
{
case PlatformType.WiiU:
{
var archive = ArchiveParent;
if (archive == null) return null;
var matches = archive.Files.Where(p => p.FileName.Contains("bflim")).ToList();
string textureFolder = "timg";
if (matches.Count > 0)
textureFolder = System.IO.Path.GetDirectoryName(matches[0].FileName);
var bflim = BFLIM.CreateNewFromImage();
if (bflim == null)
return textures;
textures.Add(bflim);
var mem = new System.IO.MemoryStream();
bflim.Save(mem);
archive.AddFile(new ArchiveFileInfo()
{
FileData = mem.ToArray(),
FileName = System.IO.Path.Combine(textureFolder, bflim.Text).Replace('\\','/'),
});
}
break;
case PlatformType.Switch:
{
BNTX bntx = null;
if (BinaryContainers.Count == 0)
{
//Create a new one if none exist
//Method for saving these will come in the save dialog
bntx = new BNTX();
bntx.IFileInfo = new IFileInfo();
bntx.FileName = "textures";
bntx.Load(new System.IO.MemoryStream(BNTX.CreateNewBNTX("textures")));
BinaryContainers.Add("textures", bntx);
}
else
{
//Use first container for now as archives only use one
bntx = BinaryContainers.Values.FirstOrDefault();
}
int startIndex = bntx.Textures.Count;
bntx.ImportTexture();
//Load all the additional textues
for (int i = 0; i < bntx.Textures.Count; i++)
{
if (i > startIndex - 1)
textures.Add(bntx.Textures.Values.ElementAt(i));
}
}
break;
}
return textures;
}
public void Dispose()
{
BinaryContainers.Clear();
ArchiveFile.Clear();
}
}
}