2019-08-04 15:15:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Toolbox.Library;
|
|
|
|
|
using Toolbox.Library.Forms;
|
|
|
|
|
using Toolbox.Library.IO;
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
namespace FirstPlugin
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
2019-08-04 16:27:00 +02:00
|
|
|
|
class TXE : STGenericTexture, IFileFormat, ISingleTextureIconLoader
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
2019-08-04 16:27:00 +02:00
|
|
|
|
public STGenericTexture IconTexture { get { return this; } }
|
|
|
|
|
|
2019-08-04 15:15:34 +02:00
|
|
|
|
public FileType FileType { get; set; } = FileType.Image;
|
|
|
|
|
|
|
|
|
|
public bool CanSave { get; set; }
|
|
|
|
|
|
|
|
|
|
public string[] Description { get; set; } = new string[] { "Pikmin 1 Proprietary Texture" };
|
|
|
|
|
public string[] Extension { get; set; } = new string[] { "*.txe" };
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
|
|
|
|
|
//Stores compression info from being opened (done automaitcally)
|
|
|
|
|
public IFileInfo IFileInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
//Check how the file wil be opened
|
|
|
|
|
public bool Identify(System.IO.Stream stream)
|
|
|
|
|
{
|
|
|
|
|
return Utils.HasExtension(FileName, ".txe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//A Type list for custom types
|
|
|
|
|
//With this you can add in classes with IFileMenuExtension to add menus for this format
|
|
|
|
|
public Type[] Types
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Type> types = new List<Type>();
|
|
|
|
|
return types.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
public static Dictionary<ushort, TEX_FORMAT> FormatsTXE = new Dictionary<ushort, TEX_FORMAT>()
|
|
|
|
|
{
|
|
|
|
|
[0] = TEX_FORMAT.RGB5A3,
|
|
|
|
|
[1] = TEX_FORMAT.CMPR,
|
|
|
|
|
[2] = TEX_FORMAT.RGB565,
|
|
|
|
|
[3] = TEX_FORMAT.I4,
|
|
|
|
|
[4] = TEX_FORMAT.I8,
|
|
|
|
|
[5] = TEX_FORMAT.IA4,
|
|
|
|
|
[6] = TEX_FORMAT.IA8,
|
|
|
|
|
[7] = TEX_FORMAT.RGBA32,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public void Load(System.IO.Stream stream)
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
2019-08-04 16:27:00 +02:00
|
|
|
|
Text = FileName;
|
|
|
|
|
//Set this if you want to save the file format
|
|
|
|
|
CanSave = false;
|
|
|
|
|
|
|
|
|
|
ImageKey = "Texture";
|
|
|
|
|
SelectedImageKey = "Texture";
|
|
|
|
|
|
2019-08-04 15:15:34 +02:00
|
|
|
|
//You can add a FileReader with Toolbox.Library.IO namespace
|
|
|
|
|
using (var reader = new FileReader(stream))
|
|
|
|
|
{
|
|
|
|
|
reader.SetByteOrder(true);
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
Width = reader.ReadUInt16();
|
|
|
|
|
Height = reader.ReadUInt16();
|
2019-08-04 17:50:04 +02:00
|
|
|
|
reader.ReadInt16();
|
2019-08-04 15:15:34 +02:00
|
|
|
|
//Turn this format into a common format used by this tool
|
2019-08-04 16:27:00 +02:00
|
|
|
|
ushort texFormat = reader.ReadUInt16();
|
|
|
|
|
Format = FormatsTXE[texFormat];
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
|
|
|
|
//Lets set our method of decoding
|
2019-08-04 16:27:00 +02:00
|
|
|
|
PlatformSwizzle = PlatformSwizzle.Platform_Gamecube;
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
|
|
|
|
int imageDataSize = reader.ReadInt32();
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
reader.SeekBegin(32);
|
2019-08-04 15:44:05 +02:00
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
ImageData = reader.ReadBytes(imageDataSize);
|
2019-08-04 15:44:05 +02:00
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
Text = FileName;
|
|
|
|
|
}
|
2019-08-04 15:44:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 23:35:18 +02:00
|
|
|
|
public void Save(System.IO.Stream stream)
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
public byte[] ImageData { get; set; }
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
//A list of supported formats
|
|
|
|
|
//This gets used in the re encode option
|
|
|
|
|
public override TEX_FORMAT[] SupportedFormats
|
|
|
|
|
{
|
|
|
|
|
get
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
2019-08-04 16:27:00 +02:00
|
|
|
|
return new TEX_FORMAT[]
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
|
|
|
|
TEX_FORMAT.I4,
|
|
|
|
|
TEX_FORMAT.I8,
|
2019-08-04 15:44:05 +02:00
|
|
|
|
TEX_FORMAT.IA4,
|
|
|
|
|
TEX_FORMAT.IA8,
|
2019-08-04 15:15:34 +02:00
|
|
|
|
TEX_FORMAT.RGB565,
|
|
|
|
|
TEX_FORMAT.RGB5A3,
|
|
|
|
|
TEX_FORMAT.RGBA32,
|
|
|
|
|
TEX_FORMAT.C4,
|
|
|
|
|
TEX_FORMAT.C8,
|
|
|
|
|
TEX_FORMAT.C14X2,
|
|
|
|
|
TEX_FORMAT.CMPR,
|
2019-08-04 16:27:00 +02:00
|
|
|
|
};
|
2019-08-04 15:15:34 +02:00
|
|
|
|
}
|
2019-08-04 16:27:00 +02:00
|
|
|
|
}
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
public override bool CanEdit { get; set; } = false;
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
//This gets used in the image editor if the image gets edited
|
|
|
|
|
//This wll not be ran if "CanEdit" is set to false!
|
|
|
|
|
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
|
|
|
|
{
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Gets the raw image data in bytes
|
|
|
|
|
//Gets decoded automatically
|
|
|
|
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
|
|
|
|
{
|
|
|
|
|
return ImageData;
|
|
|
|
|
}
|
2019-08-04 15:15:34 +02:00
|
|
|
|
|
|
|
|
|
|
2019-08-04 16:27:00 +02:00
|
|
|
|
//This is an event for when the tree is clicked on
|
|
|
|
|
//Load our editor
|
|
|
|
|
public override void OnClick(TreeView treeView)
|
|
|
|
|
{
|
|
|
|
|
//Here we check for an active editor and load a new one if not found
|
|
|
|
|
//This is used when a tree/object editor is used
|
|
|
|
|
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
|
|
|
|
if (editor == null)
|
2019-08-04 15:15:34 +02:00
|
|
|
|
{
|
2019-08-04 16:27:00 +02:00
|
|
|
|
editor = new ImageEditorBase();
|
|
|
|
|
editor.Dock = DockStyle.Fill;
|
|
|
|
|
LibraryGUI.LoadEditor(editor);
|
2019-08-04 15:15:34 +02:00
|
|
|
|
}
|
2019-08-04 16:27:00 +02:00
|
|
|
|
|
|
|
|
|
//Load our image and any properties
|
|
|
|
|
//If you don't make a class for properties you can use a generic class provided in STGenericTexture
|
|
|
|
|
editor.LoadProperties(GenericProperties);
|
|
|
|
|
editor.LoadImage(this);
|
2019-08-04 15:15:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|