From 342564d6bf1538215f8749f03c20a4e645fb4171 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Mon, 25 Sep 2023 21:40:10 +0200 Subject: [PATCH] Add config command --- Deliveroo/DeliverooPlugin.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 5867a64..63f7145 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -7,6 +7,7 @@ using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Game.Command; using Dalamud.Game.Gui; using Dalamud.Interface.Windowing; using Dalamud.Logging; @@ -33,6 +34,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin private readonly ObjectTable _objectTable; private readonly TargetManager _targetManager; private readonly Condition _condition; + private readonly CommandManager _commandManager; // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable private readonly Configuration _configuration; @@ -54,7 +56,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin public DeliverooPlugin(DalamudPluginInterface pluginInterface, ChatGui chatGui, GameGui gameGui, Framework framework, ClientState clientState, ObjectTable objectTable, TargetManager targetManager, - DataManager dataManager, Condition condition) + DataManager dataManager, Condition condition, CommandManager commandManager) { _pluginInterface = pluginInterface; _chatGui = chatGui; @@ -64,6 +66,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _objectTable = objectTable; _targetManager = targetManager; _condition = condition; + _commandManager = commandManager; var dalamudReflector = new DalamudReflector(_pluginInterface, _framework); _yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector); @@ -79,6 +82,10 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _framework.Update += FrameworkUpdate; _pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle; + _commandManager.AddHandler("/deliveroo", new CommandInfo(ProcessCommand) + { + HelpMessage = "Open the configuration" + }); } public string Name => "Deliveroo"; @@ -233,6 +240,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin public void Dispose() { + _commandManager.RemoveHandler("/deliveroo"); _pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _framework.Update -= FrameworkUpdate; @@ -240,6 +248,8 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin RestoreYesAlready(); } + private void ProcessCommand(string command, string arguments) => _configWindow.Toggle(); + private void SaveYesAlready() { if (_yesAlreadyState.Saved)