Update KTK, rework some things

This commit is contained in:
Zeffuro
2026-01-14 04:24:34 +01:00
parent 2172ff0a51
commit 652d583747
16 changed files with 85 additions and 63 deletions
@@ -14,7 +14,7 @@ namespace AetherBags.Addons;
public class AddonCategoryConfigurationWindow : NativeAddon
{
private ModifyListNode<CategoryWrapper>? _selectionListNode;
private ModifyListNode<CategoryWrapper, CategoryListItemNode>? _selectionListNode;
private VerticalLineNode? _separatorLine;
private CategoryConfigurationNode? _configNode;
private TextNode? _nothingSelectedTextNode;
@@ -28,21 +28,24 @@ public class AddonCategoryConfigurationWindow : NativeAddon
{
_categoryWrappers = CreateCategoryWrappers();
_selectionListNode = new ModifyListNode<CategoryWrapper>
_selectionListNode = new ModifyListNode<CategoryWrapper, CategoryListItemNode>
{
Position = ContentStartPosition,
Size = new Vector2(250.0f, ContentSize.Y),
SelectionOptions = _categoryWrappers,
OnOptionChanged = OnOptionChanged,
Size = ContentSize with { X = 250.0f },
Options = _categoryWrappers,
SelectionChanged = OnOptionChanged,
AddNewEntry = OnAddNewCategory,
RemoveEntry = OnRemoveCategory,
SortOptions = [ "Order" ],
ItemComparer = (left, right, mode) => left.Compare(right, mode),
IsSearchMatch = (data, search) => data.GetLabel().Contains(search, global::System.StringComparison.OrdinalIgnoreCase)
};
_selectionListNode.AttachNode(this);
_separatorLine = new VerticalLineNode
{
Position = ContentStartPosition + new Vector2(250.0f + 8.0f, 0.0f),
Size = new Vector2(4.0f, ContentSize.Y),
Size = ContentSize with { X = 4.0f },
};
_separatorLine.AttachNode(this);
@@ -78,6 +81,24 @@ public class AddonCategoryConfigurationWindow : NativeAddon
.ToList();
}
private void OnAddNewCategory()
{
var newCategory = new UserCategoryDefinition
{
Name = $"New Category {System.Config.Categories.UserCategories.Count + 1}",
Order = System.Config.Categories.UserCategories.Count,
};
System.Config.Categories.UserCategories.Add(newCategory);
var newWrapper = new CategoryWrapper(newCategory);
_categoryWrappers.Add(newWrapper);
RefreshSelectionList();
_selectionListNode?.RefreshList();
InventoryOrchestrator.RefreshAll(updateMaps: true);
}
private void OnOptionChanged(CategoryWrapper? newOption)
{
if (_configNode is null) return;
@@ -99,29 +120,11 @@ public class AddonCategoryConfigurationWindow : NativeAddon
if (_pendingSelectionListRefresh)
{
_pendingSelectionListRefresh = false;
_selectionListNode?.UpdateList();
_selectionListNode?.RefreshList();
}
}
}
private void OnAddNewCategory(ModifyListNode<CategoryWrapper> listNode)
{
var newCategory = new UserCategoryDefinition
{
Name = $"New Category {System.Config.Categories.UserCategories.Count + 1}",
Order = System.Config.Categories.UserCategories.Count,
};
System.Config.Categories.UserCategories.Add(newCategory);
var newWrapper = new CategoryWrapper(newCategory);
_categoryWrappers.Add(newWrapper);
listNode.AddOption(newWrapper);
RefreshSelectionList();
InventoryOrchestrator.RefreshAll(updateMaps: true);
}
private void OnRemoveCategory(CategoryWrapper categoryWrapper)
{
if (categoryWrapper.CategoryDefinition is null) return;
@@ -146,6 +149,16 @@ public class AddonCategoryConfigurationWindow : NativeAddon
return;
}
_selectionListNode?.UpdateList();
_selectionListNode?.RefreshList();
}
protected override unsafe void OnFinalize(AtkUnitBase* addon)
{
_selectionListNode?.Dispose();
_selectionListNode = null;
_configNode?.Dispose();
_configNode = null;
base.OnFinalize(addon);
}
}
+14
View File
@@ -0,0 +1,14 @@
using KamiToolKit.Premade.GenericSearchListItemNodes;
namespace AetherBags.Addons;
public class CategoryListItemNode : GenericListItemNode<CategoryWrapper>
{
protected override uint GetIconId(CategoryWrapper data) => data.GetIconId() ?? 0;
protected override string GetLabelText(CategoryWrapper data) => data.GetLabel();
protected override string GetSubLabelText(CategoryWrapper data) => data.GetSubLabel();
protected override uint? GetId(CategoryWrapper data) => data.GetId();
}
+6 -16
View File
@@ -1,17 +1,14 @@
using AetherBags.Configuration;
using AetherBags.Inventory.Categories;
using KamiToolKit.Premade;
namespace AetherBags.Addons;
public class CategoryWrapper(UserCategoryDefinition categoryDefinition) : IInfoNodeData
// Removed IInfoNodeData implementation
public class CategoryWrapper(UserCategoryDefinition categoryDefinition)
{
public UserCategoryDefinition? CategoryDefinition { get; } = categoryDefinition;
public string GetLabel() {
return CategoryDefinition!.Name;
}
public string GetLabel() => CategoryDefinition!.Name;
public string GetSubLabel() {
if(UserCategoryMatcher.IsCatchAll(CategoryDefinition!)) return " No valid rules!";
@@ -20,16 +17,9 @@ public class CategoryWrapper(UserCategoryDefinition categoryDefinition) : IInfoN
public uint? GetId() => null;
public uint? GetIconId() {
return 0;
}
public uint? GetIconId() => 0;
public string? GetTexturePath()
=> null;
public int Compare(IInfoNodeData other, string sortingMode) {
if (other is not CategoryWrapper otherWrapper) return 0;
return CategoryDefinition!.Order.CompareTo(otherWrapper.CategoryDefinition!.Order);
public int Compare(CategoryWrapper other, string sortingMode) {
return CategoryDefinition!.Order.CompareTo(other.CategoryDefinition!.Order);
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Component.GUI;
using KamiToolKit;
using KamiToolKit.Classes;
using KamiToolKit.Classes.ContextMenu;
using KamiToolKit.ContextMenu;
using KamiToolKit.Nodes;
namespace AetherBags.Addons;
@@ -2,7 +2,7 @@ using AetherBags.Configuration;
using AetherBags.Inventory;
using AetherBags.Inventory.Context;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using KamiToolKit.Classes.ContextMenu;
using KamiToolKit.ContextMenu;
namespace AetherBags.Addons;