From f87ec829b6c266eda87675c55f0307a9d906c3f6 Mon Sep 17 00:00:00 2001 From: Zeffuro Date: Fri, 2 Jan 2026 12:17:51 +0100 Subject: [PATCH] Add Import/Export/Reset to config and small additions --- .../Inventory/Categories/CategoryBucket.cs | 32 +++++++++ .../Categories/CategoryBucketManager.cs | 28 -------- AetherBags/Inventory/InventoryLocation.cs | 2 +- AetherBags/Inventory/InventoryOrchestrator.cs | 8 +++ .../Inventory/State/InventoryStateBase.cs | 1 + .../Nodes/Configuration/ConfigurationRoot.cs | 7 -- .../General/GeneralScrollingAreaNode.cs | 12 ++-- .../General/ImportExportResetNode.cs | 70 +++++++++++++++++++ 8 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 AetherBags/Inventory/Categories/CategoryBucket.cs delete mode 100644 AetherBags/Nodes/Configuration/ConfigurationRoot.cs create mode 100644 AetherBags/Nodes/Configuration/General/ImportExportResetNode.cs diff --git a/AetherBags/Inventory/Categories/CategoryBucket.cs b/AetherBags/Inventory/Categories/CategoryBucket.cs new file mode 100644 index 0000000..3dda341 --- /dev/null +++ b/AetherBags/Inventory/Categories/CategoryBucket.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using AetherBags.Inventory.Items; + +namespace AetherBags.Inventory.Categories; + +public sealed class CategoryBucket +{ + public uint Key; + public CategoryInfo Category = null!; + public List Items = null!; + public List FilteredItems = null!; + public bool Used; +} + +public sealed class ItemCountDescComparer : IComparer +{ + public static readonly ItemCountDescComparer Instance = new(); + + public int Compare(ItemInfo? left, ItemInfo? right) + { + if (ReferenceEquals(left, right)) return 0; + if (left is null) return 1; + if (right is null) return -1; + + int leftCount = left.ItemCount; + int rightCount = right.ItemCount; + + if (leftCount > rightCount) return -1; + if (leftCount < rightCount) return 1; + return 0; + } +} \ No newline at end of file diff --git a/AetherBags/Inventory/Categories/CategoryBucketManager.cs b/AetherBags/Inventory/Categories/CategoryBucketManager.cs index 8b60b31..774b17b 100644 --- a/AetherBags/Inventory/Categories/CategoryBucketManager.cs +++ b/AetherBags/Inventory/Categories/CategoryBucketManager.cs @@ -358,32 +358,4 @@ public static class CategoryBucketManager Name = name, }; } -} - -public sealed class CategoryBucket -{ - public uint Key; - public CategoryInfo Category = null!; - public List Items = null!; - public List FilteredItems = null!; - public bool Used; -} - -public sealed class ItemCountDescComparer : IComparer -{ - public static readonly ItemCountDescComparer Instance = new(); - - public int Compare(ItemInfo? left, ItemInfo? right) - { - if (ReferenceEquals(left, right)) return 0; - if (left is null) return 1; - if (right is null) return -1; - - int leftCount = left.ItemCount; - int rightCount = right.ItemCount; - - if (leftCount > rightCount) return -1; - if (leftCount < rightCount) return 1; - return 0; - } } \ No newline at end of file diff --git a/AetherBags/Inventory/InventoryLocation.cs b/AetherBags/Inventory/InventoryLocation.cs index 640eec8..7dd5265 100644 --- a/AetherBags/Inventory/InventoryLocation.cs +++ b/AetherBags/Inventory/InventoryLocation.cs @@ -17,7 +17,7 @@ public readonly record struct InventoryLocation(InventoryType Container, ushort public readonly record struct InventoryMappedLocation(int Container, int Slot) { - public static readonly InventoryMappedLocation Invalid = new(0, 0); + public static readonly InventoryMappedLocation Invalid = new(-1, -1); public bool IsValid => Container != 0; diff --git a/AetherBags/Inventory/InventoryOrchestrator.cs b/AetherBags/Inventory/InventoryOrchestrator.cs index a54dab6..a2f9b0b 100644 --- a/AetherBags/Inventory/InventoryOrchestrator.cs +++ b/AetherBags/Inventory/InventoryOrchestrator.cs @@ -34,6 +34,14 @@ public static unsafe class InventoryOrchestrator }); } + public static void CloseAll() + { + foreach (var window in GetAllWindows()) + { + window.Close(); + } + } + private static IEnumerable GetAllWindows() { yield return System.AddonInventoryWindow; diff --git a/AetherBags/Inventory/State/InventoryStateBase.cs b/AetherBags/Inventory/State/InventoryStateBase.cs index bca1822..7c57fe8 100644 --- a/AetherBags/Inventory/State/InventoryStateBase.cs +++ b/AetherBags/Inventory/State/InventoryStateBase.cs @@ -65,6 +65,7 @@ public abstract class InventoryStateBase bool userCategoriesEnabled = config.Categories.UserCategoriesEnabled && categoriesEnabled; bool gameCategoriesEnabled = config.Categories.GameCategoriesEnabled && categoriesEnabled; bool allaganCategoriesEnabled = config.Categories.AllaganToolsCategoriesEnabled && categoriesEnabled; + // TODO: Cache this when config changes var userCategories = config.Categories.UserCategories.Where(c => c.Enabled).ToList(); if (userCategoriesEnabled && userCategories.Count > 0) diff --git a/AetherBags/Nodes/Configuration/ConfigurationRoot.cs b/AetherBags/Nodes/Configuration/ConfigurationRoot.cs deleted file mode 100644 index 5d9b617..0000000 --- a/AetherBags/Nodes/Configuration/ConfigurationRoot.cs +++ /dev/null @@ -1,7 +0,0 @@ -using KamiToolKit.Nodes; - -namespace AetherBags.Nodes.Configuration; - -internal class ConfigurationRoot : TabbedVerticalListNode -{ -} \ No newline at end of file diff --git a/AetherBags/Nodes/Configuration/General/GeneralScrollingAreaNode.cs b/AetherBags/Nodes/Configuration/General/GeneralScrollingAreaNode.cs index ac01151..75378a1 100644 --- a/AetherBags/Nodes/Configuration/General/GeneralScrollingAreaNode.cs +++ b/AetherBags/Nodes/Configuration/General/GeneralScrollingAreaNode.cs @@ -13,20 +13,24 @@ public sealed class GeneralScrollingAreaNode : ScrollingListNode { GeneralSettings config = System.Config.General; + new ImportExportResetNode().AttachNode(this); + ItemSpacing = 32; AddNode(new FunctionalConfigurationNode()); AddNode(new LayoutConfigurationNode()); - _debugCheckboxNode = new CheckboxNode + AddNode(new CheckboxNode { Size = new Vector2(300, 20), IsVisible = true, String = "Debug Mode", IsChecked = config.DebugEnabled, - OnClick = isChecked => { config.DebugEnabled = isChecked; } - }; - AddNode(_debugCheckboxNode); + OnClick = isChecked => + { + config.DebugEnabled = isChecked; + } + }); } } \ No newline at end of file diff --git a/AetherBags/Nodes/Configuration/General/ImportExportResetNode.cs b/AetherBags/Nodes/Configuration/General/ImportExportResetNode.cs new file mode 100644 index 0000000..24ab533 --- /dev/null +++ b/AetherBags/Nodes/Configuration/General/ImportExportResetNode.cs @@ -0,0 +1,70 @@ +using System; +using System.IO; +using AetherBags.Helpers; +using AetherBags.Inventory; +using Dalamud.Game.ClientState.Keys; +using KamiToolKit.Classes; +using KamiToolKit.Nodes; + +namespace AetherBags.Nodes.Configuration.General; + +public sealed class ImportExportResetNode : HorizontalListNode +{ + public ImportExportResetNode() + { + Height = 0; + Width = 600; + Alignment = HorizontalListAnchor.Right; + FirstItemSpacing = 3; + ItemSpacing = 2; + IsVisible = true; + + AddNode(new ImGuiIconButtonNode { + Y = 3, + Height = 30, + Width = 30, + IsVisible = true, + TextTooltip = " Import Configuration\n(hold shift to confirm)", + TexturePath = Path.Combine(Services.PluginInterface.AssemblyLocation.Directory?.FullName!, @"Assets\Icons\download.png"), + OnClick = ImportConfig + }); + + AddNode(new ImGuiIconButtonNode { + Y = 3, + Height = 30, + Width = 30, + IsVisible = true, + TextTooltip = "Export Configuration", + TexturePath = Path.Combine(Services.PluginInterface.AssemblyLocation.Directory?.FullName!, @"Assets\Icons\upload.png"), + OnClick = ExportConfig + }); + + AddNode(new HoldButtonNode { + IsVisible = true, + Y = 0, + Height = 32, + Width = 100, + String = "Reset", + TextTooltip = " Reset configuration\n(hold button to confirm)", + OnClick = ResetConfig + }); + } + + private static void ResetConfig() + { + InventoryOrchestrator.CloseAll(); + ImportExportResetHelper.TryResetConfig(); + System.AddonConfigurationWindow.Close(); + } + + private static void ImportConfig() + { + if (!Services.KeyState[VirtualKey.SHIFT]) return; + + InventoryOrchestrator.CloseAll(); + ImportExportResetHelper.TryImportConfigFromClipboard(); + System.AddonConfigurationWindow.Close(); + } + + private static void ExportConfig() => ImportExportResetHelper.TryExportConfigToClipboard(System.Config); +} \ No newline at end of file