diff --git a/AetherBags/Addons/AddonInventoryWindow.cs b/AetherBags/Addons/AddonInventoryWindow.cs index b56d771..93eeb92 100644 --- a/AetherBags/Addons/AddonInventoryWindow.cs +++ b/AetherBags/Addons/AddonInventoryWindow.cs @@ -297,6 +297,16 @@ public class AddonInventoryWindow : NativeAddon }, delayTicks: 1); } + public void SetSearchText(string searchText) + { + Services.Framework.RunOnTick(() => + { + if(IsOpen) _searchInputNode.SearchString = searchText; + RefreshCategoriesCore(autosize: true); + }, delayTicks: 1); + } + + protected override unsafe void OnFinalize(AtkUnitBase* addon) { Services.AddonLifecycle.UnregisterListener(OnInventoryUpdate); diff --git a/AetherBags/Commands/CommandHandler.cs b/AetherBags/Commands/CommandHandler.cs new file mode 100644 index 0000000..2cecabd --- /dev/null +++ b/AetherBags/Commands/CommandHandler.cs @@ -0,0 +1,134 @@ +using System; +using AetherBags.Helpers; +using Dalamud.Game.Command; + +namespace AetherBags.Commands; + +public class CommandHandler : IDisposable +{ + private const string MainCommand = "/aetherbags"; + private const string ShortCommand = "/ab"; + private const string HelpDescription = "Opens your inventory. Use '/ab help' for more options."; + + public CommandHandler() + { + Services.CommandManager.AddHandler(MainCommand, new CommandInfo(OnCommand) + { + DisplayOrder = 1, + ShowInHelp = true, + HelpMessage = HelpDescription + }); + + Services.CommandManager.AddHandler(ShortCommand, new CommandInfo(OnCommand) + { + DisplayOrder = 2, + ShowInHelp = true, + HelpMessage = HelpDescription + }); + } + + private void OnCommand(string command, string args) + { + var argsParts = args.Trim().Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); + var subCommand = argsParts.Length > 0 ? argsParts[0].ToLowerInvariant() : string.Empty; + var subArgs = argsParts.Length > 1 ? argsParts[1] : string.Empty; + + switch (subCommand) + { + case "": + case "toggle": + System.AddonInventoryWindow.Toggle(); + break; + + case "config": + case "settings": + System.AddonConfigurationWindow.Toggle(); + break; + + case "show": + case "open": + System.AddonInventoryWindow.Open(); + break; + + case "hide": + case "close": + System.AddonInventoryWindow.Close(); + break; + + case "refresh": + System.AddonInventoryWindow.ManualInventoryRefresh(); + PrintChat("Inventory refreshed."); + break; + + case "search": + HandleSearch(subArgs); + break; + + case "import-sk": + ImportExportResetHelper.TryImportSortaKindaFromClipboard(true); + System.AddonInventoryWindow.ManualInventoryRefresh(); + break; + + case "export": + HandleExport(); + break; + + case "help": + case "?": + PrintHelp(); + break; + + default: + PrintChat($"Unknown command: {subCommand}. Use '/ab help' for available commands."); + break; + } + } + + private void HandleSearch(string searchTerm) + { + if (!System.AddonInventoryWindow.IsOpen) + { + System.AddonInventoryWindow.Open(); + } + + if (!string.IsNullOrWhiteSpace(searchTerm)) + { + System.AddonInventoryWindow.SetSearchText(searchTerm); + } + + PrintChat($"Searching for: {searchTerm}"); + } + + private void HandleExport() + { + // TODO: Implement export functionality + PrintChat("Export functionality coming soon!"); + } + + private void PrintHelp() + { + var helpText = @"AetherBags Commands: + /ab - Toggle inventory window + /ab config - Toggle configuration window + /ab show - Open inventory window + /ab hide - Close inventory window + /ab refresh - Force refresh inventory + /ab search - Open and search for items + /ab import-sk - Import from SortaKinda clipboard + /ab export - Export config to clipboard + /ab help - Show this help message"; + + PrintChat(helpText); + } + + private static void PrintChat(string message) + { + Services.ChatGui.Print($"[AetherBags] {message}"); + } + + public void Dispose() + { + Services.CommandManager.RemoveHandler(MainCommand); + Services.CommandManager.RemoveHandler(ShortCommand); + } +} \ No newline at end of file diff --git a/AetherBags/Plugin.cs b/AetherBags/Plugin.cs index b22e51a..2ad2522 100644 --- a/AetherBags/Plugin.cs +++ b/AetherBags/Plugin.cs @@ -2,6 +2,7 @@ using System; using System.Numerics; using AetherBags.AddonLifecycles; using AetherBags.Addons; +using AetherBags.Commands; using AetherBags.Helpers; using AetherBags.Hooks; using Dalamud.Plugin; @@ -16,6 +17,7 @@ public unsafe class Plugin : IDalamudPlugin { private static string HelpDescription => "Opens your inventory."; + private readonly CommandHandler _commandHandler; private readonly InventoryHooks _inventoryHooks; private readonly InventoryLifecycles _inventoryLifecycles; @@ -46,18 +48,8 @@ public unsafe class Plugin : IDalamudPlugin Services.PluginInterface.UiBuilder.OpenMainUi += System.AddonInventoryWindow.Toggle; Services.PluginInterface.UiBuilder.OpenConfigUi += System.AddonConfigurationWindow.Toggle; - Services.CommandManager.AddHandler("/aetherbags", new CommandInfo(OnCommand) - { - DisplayOrder = 1, - ShowInHelp = true, - HelpMessage = HelpDescription - }); - Services.CommandManager.AddHandler("/ab", new CommandInfo(OnCommand) - { - DisplayOrder = 2, - ShowInHelp = true, - HelpMessage = HelpDescription - }); + _commandHandler = new CommandHandler(); + Services.ClientState.Login += OnLogin; Services.ClientState.Logout += OnLogout; @@ -76,8 +68,7 @@ public unsafe class Plugin : IDalamudPlugin Services.ClientState.Login -= OnLogin; Services.ClientState.Logout -= OnLogout; - Services.CommandManager.RemoveHandler("/aetherbags"); - Services.CommandManager.RemoveHandler("/ab"); + _commandHandler.Dispose(); System.AddonInventoryWindow.Dispose(); System.AddonConfigurationWindow.Dispose(); @@ -88,26 +79,6 @@ public unsafe class Plugin : IDalamudPlugin _inventoryLifecycles.Dispose(); } - private void OnCommand(string command, string args) - { - switch (command) - { - case "/aetherbags": - case "/ab": - if(args.Length == 0) - System.AddonInventoryWindow.Toggle(); - if(args == "config") - System.AddonConfigurationWindow.Toggle(); - if (args == "import-sk") - { - // Manually import from SortaKinda for testing until we have a proper config window - ImportExportResetHelper.TryImportSortaKindaFromClipboard(true); - System.AddonInventoryWindow.ManualInventoryRefresh(); - } - break; - } - } - private void OnLogin() { System.Config = Util.LoadConfigOrDefault(); diff --git a/AetherBags/Services.cs b/AetherBags/Services.cs index 1569de2..7abf28a 100644 --- a/AetherBags/Services.cs +++ b/AetherBags/Services.cs @@ -8,6 +8,7 @@ namespace AetherBags; public class Services { [PluginService] public static IAddonLifecycle AddonLifecycle { get; set; } = null!; + [PluginService] public static IChatGui ChatGui { get; set; } = null!; [PluginService] public static IClientState ClientState { get; private set; } = null!; [PluginService] public static ICommandManager CommandManager { get; private set; } = null!; [PluginService] public static IDataManager DataManager { get; set; } = null!;