mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-11 22:31:54 +00:00
PckNodeSorter - Updated node sorting
This commit is contained in:
@@ -1,42 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OMI.Formats.Pck;
|
||||
|
||||
namespace PckStudio
|
||||
{
|
||||
public class PckNodeSorter : System.Collections.IComparer, IComparer<TreeNode>
|
||||
public class PckNodeSorter : IComparer, IComparer<TreeNode>
|
||||
{
|
||||
private bool CheckForSkinAndCapeFiles(TreeNode node)
|
||||
{
|
||||
if (node.Tag is PckFile.FileData file)
|
||||
if (IsPckFile(node, out PckFile.FileData file))
|
||||
return file.Filetype == PckFile.FileData.FileType.SkinFile || file.Filetype == PckFile.FileData.FileType.CapeFile;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsPckFile(TreeNode node) => IsPckFile(node, out _);
|
||||
private bool IsPckFile(TreeNode node, out PckFile.FileData file)
|
||||
{
|
||||
if (node.Tag is PckFile.FileData _file)
|
||||
{
|
||||
return file.Filetype == PckFile.FileData.FileType.SkinFile ||
|
||||
file.Filetype == PckFile.FileData.FileType.CapeFile;
|
||||
file = _file;
|
||||
return true;
|
||||
}
|
||||
file = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int Compare(TreeNode first, TreeNode second)
|
||||
{
|
||||
// ignore these files in order to preserve skin(and cape) files
|
||||
if (CheckForSkinAndCapeFiles(first))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (CheckForSkinAndCapeFiles(second))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (IsPckFile(first) && !IsPckFile(second))
|
||||
return -1;
|
||||
if (!IsPckFile(first) && IsPckFile(second))
|
||||
return 1;
|
||||
|
||||
int result = first.Text.CompareTo(second.Text);
|
||||
if (result != 0) return result;
|
||||
return first.ImageIndex.CompareTo(second.ImageIndex);
|
||||
if (CheckForSkinAndCapeFiles(first))
|
||||
return -1;
|
||||
if (CheckForSkinAndCapeFiles(second))
|
||||
return 1;
|
||||
|
||||
return first.Text.CompareTo(second.Text);
|
||||
// weird fail save
|
||||
//return first.ImageIndex.CompareTo(second.ImageIndex);
|
||||
}
|
||||
|
||||
int System.Collections.IComparer.Compare(object x, object y)
|
||||
int IComparer.Compare(object x, object y)
|
||||
{
|
||||
return x is TreeNode NodeX && y is TreeNode NodeY ? Compare(NodeX, NodeY) : 0;
|
||||
if (x is not TreeNode NodeX)
|
||||
return -1;
|
||||
if (y is not TreeNode NodeY)
|
||||
return 1;
|
||||
return Compare(NodeX, NodeY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user