qstbak/Questionable/Questionable.Controller/CommandHandler.cs
2025-11-30 10:36:46 +10:00

183 lines
6.8 KiB
C#

using System;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.Command;
using Dalamud.Plugin.Services;
using Questionable.Functions;
using Questionable.Windows;
namespace Questionable.Controller;
internal sealed class CommandHandler : IDisposable
{
public const string MessageTag = "Questionable";
public const ushort TagColor = 576;
private readonly ICommandManager _commandManager;
private readonly IChatGui _chatGui;
private readonly QuestController _questController;
private readonly MovementController _movementController;
private readonly ConfigWindow _configWindow;
private readonly OneTimeSetupWindow _oneTimeSetupWindow;
private readonly QuestWindow _questWindow;
private readonly QuestSelectionWindow _questSelectionWindow;
private readonly QuestSequenceWindow _questSequenceWindow;
private readonly JournalProgressWindow _journalProgressWindow;
private readonly PriorityWindow _priorityWindow;
private readonly ITargetManager _targetManager;
private readonly IClientState _clientState;
private readonly Configuration _configuration;
private readonly ChangelogWindow _changelogWindow;
public CommandHandler(ICommandManager commandManager, IChatGui chatGui, QuestController questController, MovementController movementController, QuestRegistry questRegistry, ConfigWindow configWindow, DebugOverlay debugOverlay, OneTimeSetupWindow oneTimeSetupWindow, QuestWindow questWindow, QuestSelectionWindow questSelectionWindow, QuestSequenceWindow questSequenceWindow, JournalProgressWindow journalProgressWindow, PriorityWindow priorityWindow, ITargetManager targetManager, QuestFunctions questFunctions, GameFunctions gameFunctions, AetheryteFunctions aetheryteFunctions, IDataManager dataManager, IClientState clientState, IObjectTable objectTable, Configuration configuration, ChangelogWindow changelogWindow)
{
_commandManager = commandManager;
_chatGui = chatGui;
_questController = questController;
_movementController = movementController;
_configWindow = configWindow;
_oneTimeSetupWindow = oneTimeSetupWindow;
_questWindow = questWindow;
_questSelectionWindow = questSelectionWindow;
_questSequenceWindow = questSequenceWindow;
_journalProgressWindow = journalProgressWindow;
_priorityWindow = priorityWindow;
_targetManager = targetManager;
_clientState = clientState;
_configuration = configuration;
_changelogWindow = changelogWindow;
_clientState.Logout += OnLogout;
_commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand)
{
HelpMessage = string.Join(Environment.NewLine + "\t", "Opens the Questing window", "/qst help - displays simplified commands", "/qst help-all - displays all available commands", "/qst config - opens the configuration window", "/qst changelog - opens the changelog window", "/qst start - starts doing quests", "/qst stop - stops doing quests")
});
}
private void ProcessCommand(string command, string arguments)
{
if (!OpenSetupIfNeeded(arguments))
{
string[] array = arguments.Split(' ');
switch (array[0])
{
case "h":
case "help":
_chatGui.Print("Available commands:", "Questionable", 576);
_chatGui.Print("/qst - toggles the Questing window", "Questionable", 576);
_chatGui.Print("/qst help - displays simplified commands", "Questionable", 576);
_chatGui.Print("/qst help-all - displays all available commands", "Questionable", 576);
_chatGui.Print("/qst config - opens the configuration window", "Questionable", 576);
_chatGui.Print("/qst changelog - opens the changelog window", "Questionable", 576);
_chatGui.Print("/qst start - starts doing quests", "Questionable", 576);
_chatGui.Print("/qst stop - stops doing quests", "Questionable", 576);
_chatGui.Print("/qst reload - reload all quest data", "Questionable", 576);
break;
case "ha":
case "help-all":
_chatGui.Print("Available commands:", "Questionable", 576);
_chatGui.Print("/qst - toggles the Questing window", "Questionable", 576);
_chatGui.Print("/qst help - displays available commands", "Questionable", 576);
_chatGui.Print("/qst help-all - displays all available commands", "Questionable", 576);
_chatGui.Print("/qst config - opens the configuration window", "Questionable", 576);
_chatGui.Print("/qst changelog - opens the changelog window", "Questionable", 576);
_chatGui.Print("/qst start - starts doing quests", "Questionable", 576);
_chatGui.Print("/qst stop - stops doing quests", "Questionable", 576);
_chatGui.Print("/qst reload - reload all quest data", "Questionable", 576);
_chatGui.Print("/qst which - shows all quests starting with your selected target", "Questionable", 576);
_chatGui.Print("/qst zone - shows all quests starting in the current zone (only includes quests with a known quest path, and currently visible unaccepted quests)", "Questionable", 576);
_chatGui.Print("/qst journal - toggles the Journal Progress window", "Questionable", 576);
_chatGui.Print("/qst priority - toggles the Priority window", "Questionable", 576);
_chatGui.Print("/qst handle-interrupt - makes Questionable handle queued interrupts immediately (useful if you manually start combat)", "Questionable", 576);
break;
case "c":
case "config":
_configWindow.ToggleOrUncollapse();
break;
case "cl":
case "changelog":
_changelogWindow.ToggleOrUncollapse();
break;
case "start":
_questWindow.IsOpenAndUncollapsed = true;
_questController.Start("Start command");
break;
case "stop":
_movementController.Stop();
_questController.Stop("Stop command");
break;
case "reload":
_questWindow.Reload();
break;
case "which":
_questSelectionWindow.OpenForTarget(_targetManager.Target);
break;
case "z":
case "zone":
_questSelectionWindow.OpenForCurrentZone();
break;
case "j":
case "journal":
_journalProgressWindow.ToggleOrUncollapse();
break;
case "p":
case "priority":
_priorityWindow.ToggleOrUncollapse();
break;
case "handle-interrupt":
_questController.InterruptQueueWithCombat();
break;
case "":
_questWindow.ToggleOrUncollapse();
break;
default:
_chatGui.PrintError("Unknown subcommand " + array[0], "Questionable", 576);
break;
}
}
}
private void ProcessDebugCommand(string command, string arguments)
{
}
private bool OpenSetupIfNeeded(string arguments)
{
if (!_configuration.IsPluginSetupComplete())
{
if (string.IsNullOrEmpty(arguments))
{
_oneTimeSetupWindow.IsOpenAndUncollapsed = true;
}
else
{
_chatGui.PrintError("Please complete the one-time setup first.", "Questionable", 576);
}
return true;
}
return false;
}
private void OnLogout(int type, int code)
{
}
public void Dispose()
{
_commandManager.RemoveHandler("/qst");
_clientState.Logout -= OnLogout;
}
}