Switch-Toolbox/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs
KillzXGaming d1f03b161f Add files for the new one.
Rework UI from scratch with proper themes and custom controls. MDI windows are now used for workspaces, comparing docs, and multiple usages. Tabs organise multiple workspaces and you can keep mdi windows maximized if you want to only use tabs. Themes currently include dark and white theme but plan to have XML files with list of color and styles
Alot of things optimized. UI is very fast and snappy now
Dae rigging fixed.
Dae bones can be imported.
Dae with textures can be imported and exported to a folder
Custom sampler editor for sampler data.
Texture refs, shader options, params, render info, and basically all material data can be added/removed and edited
User data editor
Update opengl framework by JuPaHe64 to the newest. Includes an origintation cube, multiple models in a scene, and many improvements
Skeleton can be viewed
GFPAK with some fixes in saving
NUTEXB has proper mip map viewing
PTCL Editor (Wii U and Switch). Can edit colors ( Wii U) and view textures. Also EFFN files in smash ultimate can be previewed
Files can be associated with the program and opened with on clicking them
ASTC textures can be viewed
UVs can be viewed. Includes wrap modes and also translating and scaling for some basic edits
Textures use a new editor. It includes channel viewing and some new editing options
Fixed black textures on some wii u bfres
Fixed saving sarcs in sarcs
Shortcut keys have been added in. CTRL + S can save the active file in the currently used window
Fix more issues with bfres crashing
File - New includes BNTX for creating new bntx files from scatch
Raw shader binaries can be extracted from bnsh and bfsha. Yuzu and Ryujinx can decompile these
Sharc files can have source data previewed and shader programs in XML
Aamp v1 and v2 data can be previewed. v1 can be edited and saved atm, v2 will be at a later update
Byaml uses it's own editor instead of a seperate window for easy saving within sarcs
Archives have a hex viewer
Dae exporting greatly improved and can export rigged meshes
Scene, shader param, srt, color, and texture pattern animations can all be previewed (in a list)
Memory usage is greatly improved
Narc (Nitro Archives) can be viewed and extracted.
Fixed importing TGA images
Support importing ASTC textures for bntx
Added in PBR lighting for bfres from my implimentaion in forge
Added gradient background for viewport. This can be edited in the settings
Added skybox background option for viewport. Can load cubemaps
Added grid with customizable cells for viewport.
DDS decompression no longer requires Direct X tex.
Zlib decompression has been improved for opening files that use it
Rigid bones are properly ordered on importing a mesh. May fix some exploding issues.
Endianness for KCL can be toggled for saving. Will be set to what it was using orignally
Tangents can be filled with a constant value. Will allow them to not cause seams nor flat lighting however normal maps may not work as good
Vertex buffers can be added and removed. Also re encoded
Parameters now use drop down panels with values for easier editing
Reworked the bone editor. Everything for a bone can be fully edited now besides the index, billboard index and parent index  which get set automatically
Fixed animation scaling for skeletal animations finally!
Textures can be loaded in a tab now with thumbnail displaying for easy real time edits while previewing in the viewport

Fixed support for audio files to be big endian in BARS
Textures for switch now use their own folder. You can easily add textures to this and add textures to bfres that have no bntx. If there are no textures then the bfres will automatically not have one on save.
Animations are split into multiple sub sections for switch's material animation for easier access
Bfres for wii u has better binary exporting and is fully compatiable with Wexos Toolbox (to and from)
Every section can be added in as new for both wii u and switch.
Every section can be renamed properly and mostly everything can be edited. (Key frame editing and a more in depth curve editor later)
Added option to copy UV channel
Bone weights can be previewed
Tons of fixes for the switch bfres library with more games working. Splatoon 2 (more work now), BOTW, Kirby Star Allies, and more!
Fixed 3.3 Wii U bfres from not opening
Wii U Sharcfb files can have shader program data previewed (XML)

And possibly alot more things i missed! All this is still experimental but will improve over the next few weeks
2019-03-23 12:55:09 -04:00

216 lines
7.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using Switch_Toolbox.Library.Forms;
namespace Switch_Toolbox.Library
{
public abstract class TreeNodeCustom : TreeNode
{
public virtual void OnClick(TreeView treeview) { }
public virtual void OnMouseLeftClick(TreeView treeview) { }
public virtual void OnMouseRightClick(TreeView treeview) { }
public virtual void OnDoubleMouseClick(TreeView treeview) { }
public TreeNodeCustom()
{
}
}
public class TreeNodeFile : TreeNodeCustom
{
public TreeNodeFile()
{
}
public TreeNodeFile(string text)
{
Text = text;
}
public virtual void OnAfterAdded() //After added to treeview
{
}
}
public class TreeViewCustom : TreeView
{
private readonly Dictionary<int, TreeNode> _treeNodes = new Dictionary<int, TreeNode>();
public TreeViewCustom()
{
ReloadImages();
BackColor = FormThemes.BaseTheme.FormBackColor;
ForeColor = FormThemes.BaseTheme.FormForeColor;
}
ImageList imgList = new ImageList();
public void AddImage(Image image)
{
imgList.Images.Add(image);
}
public int ImageWidth = 21;
public int ImageHeight = 21;
public void ReloadImages()
{
imgList = new ImageList();
imgList.ColorDepth = ColorDepth.Depth32Bit;
imgList.ImageSize = new Size(ImageWidth, ImageHeight);
imgList.Images.Add("folder", Properties.Resources.Folder);
imgList.Images.Add("resource", Properties.Resources.Folder);
imgList.Images.Add("Texture", Properties.Resources.Texture);
imgList.Images.Add("fileBlank", Properties.Resources.FileBlank);
imgList.Images.Add("bfres", Properties.Resources.Bfres);
imgList.Images.Add("byaml", Properties.Resources.Byaml);
imgList.Images.Add("aamp", Properties.Resources.Aamp);
imgList.Images.Add("bntx", Properties.Resources.Bntx);
imgList.Images.Add("bfsha", Properties.Resources.Bfsha);
imgList.Images.Add("bnsh", Properties.Resources.Bnsh);
imgList.Images.Add("mesh", Properties.Resources.mesh);
imgList.Images.Add("skeletonAnimation", Properties.Resources.skeletonAnimation);
imgList.Images.Add("bone", Properties.Resources.Bone);
imgList.Images.Add("bfwav", Properties.Resources.Music1);
imgList.Images.Add("bfstp", Properties.Resources.Music2);
imgList.Images.Add("material", Properties.Resources.materialSphere);
imgList.Images.Add("model", Properties.Resources.model);
imgList.Images.Add("folder", Properties.Resources.skeleton);
//Data types
imgList.Images.Add("bool", Properties.Resources.IconBool);
imgList.Images.Add("buffer", Properties.Resources.IconBuffer);
imgList.Images.Add("curve", Properties.Resources.IconCurve);
imgList.Images.Add("float", Properties.Resources.IconFloat);
imgList.Images.Add("int", Properties.Resources.IconInt);
imgList.Images.Add("list", Properties.Resources.IconList);
imgList.Images.Add("object", Properties.Resources.IconObject);
imgList.Images.Add("vec2", Properties.Resources.IconVec2);
imgList.Images.Add("vec3", Properties.Resources.IconVec3);
imgList.Images.Add("vec4", Properties.Resources.IconVec4);
Bitmap bmp = new Bitmap(32, 32);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Transparent);
imgList.Images.Add("empty", bmp);
this.ImageList = imgList;
}
/// <summary>
/// Load the TreeView with items.
/// </summary>
/// <typeparam name="T">Item type</typeparam>
/// <param name="items">Collection of items</param>
/// <param name="getId">Function to parse Id value from item object</param>
/// <param name="getParentId">Function to parse parentId value from item object</param>
/// <param name="getDisplayName">Function to parse display name
/// value from item object. This is used as node text.</param>
public void LoadItems<T>(IEnumerable<T> items, Func<T, int> getId,
Func<T, int?> getParentId, Func<T, string> getDisplayName)
{
// Clear view and internal dictionary
Nodes.Clear();
_treeNodes.Clear();
// Load internal dictionary with nodes
foreach (var item in items)
{
var id = getId(item);
var displayName = getDisplayName(item);
var node = new TreeNode
{
Name = id.ToString(),
Text = displayName,
Tag = item
};
_treeNodes.Add(getId(item), node);
}
// Create hierarchy and load into view
foreach (var id in _treeNodes.Keys)
{
var node = GetNode(id);
var obj = (T)node.Tag;
var parentId = getParentId(obj);
if (parentId.HasValue)
{
var parentNode = GetNode(parentId.Value);
parentNode.Nodes.Add(node);
}
else
{
Nodes.Add(node);
}
}
}
/// <summary>
/// Retrieve TreeNode by Id.
/// Useful when you want to select a specific node.
/// </summary>
/// <param name="id">Item id</param>
public TreeNode GetNode(int id)
{
return _treeNodes[id];
}
}
public static class TreeViewExtensions
{
public static IEnumerable<TreeNode> Collect(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
yield return node;
foreach (var child in Collect(node.Nodes))
yield return child;
}
}
private const int TVIF_STATE = 0x8;
private const int TVIS_STATEIMAGEMASK = 0xF000;
private const int TV_FIRST = 0x1100;
private const int TVM_SETITEM = TV_FIRST + 63;
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
private struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,
ref TVITEM lParam);
/// <summary>
/// Hides the checkbox for the specified node on a TreeView control.
/// </summary>
public static void HideCheckBox(this TreeNode node)
{
TVITEM tvi = new TVITEM();
tvi.hItem = node.Handle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
}
}
}