Implement CommandHandler
This commit is contained in:
@@ -297,6 +297,16 @@ public class AddonInventoryWindow : NativeAddon
|
|||||||
}, delayTicks: 1);
|
}, 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)
|
protected override unsafe void OnFinalize(AtkUnitBase* addon)
|
||||||
{
|
{
|
||||||
Services.AddonLifecycle.UnregisterListener(OnInventoryUpdate);
|
Services.AddonLifecycle.UnregisterListener(OnInventoryUpdate);
|
||||||
|
|||||||
@@ -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 <term> - 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-34
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using AetherBags.AddonLifecycles;
|
using AetherBags.AddonLifecycles;
|
||||||
using AetherBags.Addons;
|
using AetherBags.Addons;
|
||||||
|
using AetherBags.Commands;
|
||||||
using AetherBags.Helpers;
|
using AetherBags.Helpers;
|
||||||
using AetherBags.Hooks;
|
using AetherBags.Hooks;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
@@ -16,6 +17,7 @@ public unsafe class Plugin : IDalamudPlugin
|
|||||||
{
|
{
|
||||||
private static string HelpDescription => "Opens your inventory.";
|
private static string HelpDescription => "Opens your inventory.";
|
||||||
|
|
||||||
|
private readonly CommandHandler _commandHandler;
|
||||||
private readonly InventoryHooks _inventoryHooks;
|
private readonly InventoryHooks _inventoryHooks;
|
||||||
private readonly InventoryLifecycles _inventoryLifecycles;
|
private readonly InventoryLifecycles _inventoryLifecycles;
|
||||||
|
|
||||||
@@ -46,18 +48,8 @@ public unsafe class Plugin : IDalamudPlugin
|
|||||||
Services.PluginInterface.UiBuilder.OpenMainUi += System.AddonInventoryWindow.Toggle;
|
Services.PluginInterface.UiBuilder.OpenMainUi += System.AddonInventoryWindow.Toggle;
|
||||||
Services.PluginInterface.UiBuilder.OpenConfigUi += System.AddonConfigurationWindow.Toggle;
|
Services.PluginInterface.UiBuilder.OpenConfigUi += System.AddonConfigurationWindow.Toggle;
|
||||||
|
|
||||||
Services.CommandManager.AddHandler("/aetherbags", new CommandInfo(OnCommand)
|
_commandHandler = new CommandHandler();
|
||||||
{
|
|
||||||
DisplayOrder = 1,
|
|
||||||
ShowInHelp = true,
|
|
||||||
HelpMessage = HelpDescription
|
|
||||||
});
|
|
||||||
Services.CommandManager.AddHandler("/ab", new CommandInfo(OnCommand)
|
|
||||||
{
|
|
||||||
DisplayOrder = 2,
|
|
||||||
ShowInHelp = true,
|
|
||||||
HelpMessage = HelpDescription
|
|
||||||
});
|
|
||||||
Services.ClientState.Login += OnLogin;
|
Services.ClientState.Login += OnLogin;
|
||||||
Services.ClientState.Logout += OnLogout;
|
Services.ClientState.Logout += OnLogout;
|
||||||
|
|
||||||
@@ -76,8 +68,7 @@ public unsafe class Plugin : IDalamudPlugin
|
|||||||
Services.ClientState.Login -= OnLogin;
|
Services.ClientState.Login -= OnLogin;
|
||||||
Services.ClientState.Logout -= OnLogout;
|
Services.ClientState.Logout -= OnLogout;
|
||||||
|
|
||||||
Services.CommandManager.RemoveHandler("/aetherbags");
|
_commandHandler.Dispose();
|
||||||
Services.CommandManager.RemoveHandler("/ab");
|
|
||||||
|
|
||||||
System.AddonInventoryWindow.Dispose();
|
System.AddonInventoryWindow.Dispose();
|
||||||
System.AddonConfigurationWindow.Dispose();
|
System.AddonConfigurationWindow.Dispose();
|
||||||
@@ -88,26 +79,6 @@ public unsafe class Plugin : IDalamudPlugin
|
|||||||
_inventoryLifecycles.Dispose();
|
_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()
|
private void OnLogin()
|
||||||
{
|
{
|
||||||
System.Config = Util.LoadConfigOrDefault();
|
System.Config = Util.LoadConfigOrDefault();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace AetherBags;
|
|||||||
public class Services
|
public class Services
|
||||||
{
|
{
|
||||||
[PluginService] public static IAddonLifecycle AddonLifecycle { get; set; } = null!;
|
[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 IClientState ClientState { get; private set; } = null!;
|
||||||
[PluginService] public static ICommandManager CommandManager { get; private set; } = null!;
|
[PluginService] public static ICommandManager CommandManager { get; private set; } = null!;
|
||||||
[PluginService] public static IDataManager DataManager { get; set; } = null!;
|
[PluginService] public static IDataManager DataManager { get; set; } = null!;
|
||||||
|
|||||||
Reference in New Issue
Block a user