1
0
Fork 0
Questionable/Questionable/DalamudInitializer.cs

86 lines
3.0 KiB
C#
Raw Normal View History

2024-06-08 19:16:57 +00:00
using System;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Questionable.Controller;
using Questionable.Windows;
namespace Questionable;
internal sealed class DalamudInitializer : IDisposable
{
private readonly DalamudPluginInterface _pluginInterface;
private readonly IFramework _framework;
private readonly ICommandManager _commandManager;
private readonly QuestController _questController;
private readonly MovementController _movementController;
private readonly NavigationShortcutController _navigationShortcutController;
private readonly WindowSystem _windowSystem;
private readonly DebugWindow _debugWindow;
2024-06-12 16:03:48 +00:00
private readonly ConfigWindow _configWindow;
2024-06-08 19:16:57 +00:00
public DalamudInitializer(DalamudPluginInterface pluginInterface, IFramework framework,
ICommandManager commandManager, QuestController questController, MovementController movementController,
2024-06-12 16:03:48 +00:00
GameUiController gameUiController, NavigationShortcutController navigationShortcutController,
WindowSystem windowSystem, DebugWindow debugWindow, ConfigWindow configWindow)
2024-06-08 19:16:57 +00:00
{
_pluginInterface = pluginInterface;
_framework = framework;
_commandManager = commandManager;
_questController = questController;
_movementController = movementController;
_navigationShortcutController = navigationShortcutController;
_windowSystem = windowSystem;
_debugWindow = debugWindow;
2024-06-12 16:03:48 +00:00
_configWindow = configWindow;
_windowSystem.AddWindow(debugWindow);
_windowSystem.AddWindow(configWindow);
2024-06-08 19:16:57 +00:00
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenMainUi += _debugWindow.Toggle;
2024-06-12 16:03:48 +00:00
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
2024-06-08 19:16:57 +00:00
_framework.Update += FrameworkUpdate;
_commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand)
{
HelpMessage = "Opens the Questing window"
});
_framework.RunOnTick(gameUiController.HandleCurrentDialogueChoices, TimeSpan.FromMilliseconds(200));
}
private void FrameworkUpdate(IFramework framework)
{
_questController.Update();
_navigationShortcutController.HandleNavigationShortcut();
try
{
_movementController.Update();
}
catch (MovementController.PathfindingFailedException)
{
2024-06-10 17:56:13 +00:00
_questController.Stop("Pathfinding failed");
}
2024-06-08 19:16:57 +00:00
}
private void ProcessCommand(string command, string arguments)
{
2024-06-12 16:03:48 +00:00
if (arguments is "c" or "config")
_configWindow.Toggle();
else
_debugWindow.Toggle();
2024-06-08 19:16:57 +00:00
}
public void Dispose()
{
_commandManager.RemoveHandler("/qst");
_framework.Update -= FrameworkUpdate;
_pluginInterface.UiBuilder.OpenMainUi -= _debugWindow.Toggle;
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
2024-06-12 16:03:48 +00:00
_windowSystem.RemoveAllWindows();
2024-06-08 19:16:57 +00:00
}
}