Add Import/Export/Reset to config and small additions

This commit is contained in:
Zeffuro
2026-01-02 12:17:51 +01:00
parent 79a16b89eb
commit f87ec829b6
8 changed files with 120 additions and 40 deletions
@@ -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<ItemInfo> Items = null!;
public List<ItemInfo> FilteredItems = null!;
public bool Used;
}
public sealed class ItemCountDescComparer : IComparer<ItemInfo>
{
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;
}
}
@@ -359,31 +359,3 @@ public static class CategoryBucketManager
}; };
} }
} }
public sealed class CategoryBucket
{
public uint Key;
public CategoryInfo Category = null!;
public List<ItemInfo> Items = null!;
public List<ItemInfo> FilteredItems = null!;
public bool Used;
}
public sealed class ItemCountDescComparer : IComparer<ItemInfo>
{
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;
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ public readonly record struct InventoryLocation(InventoryType Container, ushort
public readonly record struct InventoryMappedLocation(int Container, int Slot) 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; public bool IsValid => Container != 0;
@@ -34,6 +34,14 @@ public static unsafe class InventoryOrchestrator
}); });
} }
public static void CloseAll()
{
foreach (var window in GetAllWindows())
{
window.Close();
}
}
private static IEnumerable<IInventoryWindow> GetAllWindows() private static IEnumerable<IInventoryWindow> GetAllWindows()
{ {
yield return System.AddonInventoryWindow; yield return System.AddonInventoryWindow;
@@ -65,6 +65,7 @@ public abstract class InventoryStateBase
bool userCategoriesEnabled = config.Categories.UserCategoriesEnabled && categoriesEnabled; bool userCategoriesEnabled = config.Categories.UserCategoriesEnabled && categoriesEnabled;
bool gameCategoriesEnabled = config.Categories.GameCategoriesEnabled && categoriesEnabled; bool gameCategoriesEnabled = config.Categories.GameCategoriesEnabled && categoriesEnabled;
bool allaganCategoriesEnabled = config.Categories.AllaganToolsCategoriesEnabled && categoriesEnabled; bool allaganCategoriesEnabled = config.Categories.AllaganToolsCategoriesEnabled && categoriesEnabled;
// TODO: Cache this when config changes
var userCategories = config.Categories.UserCategories.Where(c => c.Enabled).ToList(); var userCategories = config.Categories.UserCategories.Where(c => c.Enabled).ToList();
if (userCategoriesEnabled && userCategories.Count > 0) if (userCategoriesEnabled && userCategories.Count > 0)
@@ -1,7 +0,0 @@
using KamiToolKit.Nodes;
namespace AetherBags.Nodes.Configuration;
internal class ConfigurationRoot : TabbedVerticalListNode
{
}
@@ -13,20 +13,24 @@ public sealed class GeneralScrollingAreaNode : ScrollingListNode
{ {
GeneralSettings config = System.Config.General; GeneralSettings config = System.Config.General;
new ImportExportResetNode().AttachNode(this);
ItemSpacing = 32; ItemSpacing = 32;
AddNode(new FunctionalConfigurationNode()); AddNode(new FunctionalConfigurationNode());
AddNode(new LayoutConfigurationNode()); AddNode(new LayoutConfigurationNode());
_debugCheckboxNode = new CheckboxNode AddNode(new CheckboxNode
{ {
Size = new Vector2(300, 20), Size = new Vector2(300, 20),
IsVisible = true, IsVisible = true,
String = "Debug Mode", String = "Debug Mode",
IsChecked = config.DebugEnabled, IsChecked = config.DebugEnabled,
OnClick = isChecked => { config.DebugEnabled = isChecked; } OnClick = isChecked =>
}; {
AddNode(_debugCheckboxNode); config.DebugEnabled = isChecked;
}
});
} }
} }
@@ -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);
}