1
0
mirror of synced 2024-12-04 20:08:00 +01:00
Switch-Toolbox/Switch_FileFormatsMain/GUI/Texture Selector.cs

193 lines
6.4 KiB
C#
Raw Normal View History

2018-11-12 02:51:12 +01:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace FirstPlugin
{
public partial class Texture_Selector : Form
{
private Thread Thread;
public Texture_Selector()
{
InitializeComponent();
}
public void LoadTexture()
{
2018-11-17 23:33:00 +01:00
if (BFRES.IsWiiU)
2018-11-12 02:51:12 +01:00
{
2018-11-17 23:33:00 +01:00
foreach (FTEXContainer ftexcont in PluginRuntime.ftexContainers)
{
foreach (FTEX tex in ftexcont.Textures.Values)
listView1.Items.Add(tex.Text);
}
}
else
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
{
foreach (TextureData tex in bntx.Textures.Values)
listView1.Items.Add(tex.Text);
}
2018-11-12 02:51:12 +01:00
}
2018-11-17 23:33:00 +01:00
2018-11-12 02:51:12 +01:00
if (listView1.Items.Count > 0)
{
listView1.Items[0].Selected = true;
listView1.Select();
}
}
public string GetSelectedTexture()
{
return listView1.SelectedItems[0].Text;
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
string TexName = listView1.SelectedItems[0].Text;
2018-11-17 23:33:00 +01:00
if (BFRES.IsWiiU)
2018-11-12 02:51:12 +01:00
{
2018-11-17 23:33:00 +01:00
foreach (FTEXContainer ftexcont in PluginRuntime.ftexContainers)
{
if (ftexcont.Textures.ContainsKey(TexName))
DisplayTexture(ftexcont.Textures[TexName]);
}
2018-11-12 02:51:12 +01:00
}
2018-11-17 23:33:00 +01:00
else
{
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(TexName))
DisplayTexture(bntx.Textures[TexName]);
}
}
2018-11-12 02:51:12 +01:00
}
}
2018-11-17 23:33:00 +01:00
private void DisplayTexture(FTEX texData)
{
if (Thread != null && Thread.IsAlive)
Thread.Abort();
Thread = new Thread((ThreadStart)(() =>
{
pictureBoxCustom1.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
pictureBoxCustom1.Image = texData.DisplayTexture();
// texSizeMipsLabel.Text = $"Width = {pictureBoxCustom1.Image.Width} Height = {pictureBoxCustom1.Image.Height}";
}));
Thread.Start();
}
2018-11-12 02:51:12 +01:00
private void DisplayTexture(TextureData texData)
{
if (Thread != null && Thread.IsAlive)
Thread.Abort();
Thread = new Thread((ThreadStart)(() =>
{
pictureBoxCustom1.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
pictureBoxCustom1.Image = texData.DisplayTexture();
// texSizeMipsLabel.Text = $"Width = {pictureBoxCustom1.Image.Width} Height = {pictureBoxCustom1.Image.Height}";
}));
Thread.Start();
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void addTextureBtn_Click(object sender, EventArgs e)
{
if (PluginRuntime.bntxContainers.Count > 1)
{
BntxSelector bntxSelector = new BntxSelector();
if (bntxSelector.ShowDialog() == DialogResult.OK)
{
AddTexture((bntxSelector.GetBNTX()));
}
}
else
{
AddTexture((PluginRuntime.bntxContainers[0]));
}
}
private void AddTexture(BinaryTextureContainer bntx)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Supported Formats|*.bftex;*.dds; *.png;*.tga;*.jpg;*.tiff|" +
"Binary Texture |*.bftex|" +
"Microsoft DDS |*.dds|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
"Bitmap Image |*.bmp|" +
"Tagged Image File Format |*.tiff|" +
"All files(*.*)|*.*";
ofd.DefaultExt = "bftex";
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
foreach (string name in ofd.FileNames)
{
bntx.AddTexture(name);
listView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(name));
}
}
}
private void RemoveTextureBtn_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
string TexName = listView1.SelectedItems[0].Text;
foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(TexName))
{
bntx.Textures.Remove(TexName);
listView1.Items.RemoveByKey(TexName);
}
}
}
}
private void Texture_Selector_Load(object sender, EventArgs e)
{
}
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawDefault = true;
if ((e.ItemIndex % 2) == 1)
{
e.Item.BackColor = Color.FromArgb(50, 50, 50);
e.Item.UseItemStyleForSubItems = true;
}
}
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
using (SolidBrush backBrush = new SolidBrush(Color.FromArgb(50, 50, 50)))
{
e.Graphics.FillRectangle(backBrush, e.Bounds);
}
using (SolidBrush foreBrush = new SolidBrush(Color.FromArgb(255,255,255)))
{
e.Graphics.DrawString(e.Header.Text, e.Font, foreBrush, e.Bounds);
}
// e.DrawText();
}
}
}