Questionable/Questionable/DalamudInitializer.cs

107 lines
3.9 KiB
C#
Raw Normal View History

2024-06-08 19:16:57 +00:00
using System;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Text.SeStringHandling;
2024-06-08 19:16:57 +00:00
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Microsoft.Extensions.Logging;
2024-06-08 19:16:57 +00:00
using Questionable.Controller;
2024-08-17 23:55:38 +00:00
using Questionable.Controller.GameUi;
2024-06-08 19:16:57 +00:00
using Questionable.Windows;
namespace Questionable;
internal sealed class DalamudInitializer : IDisposable
{
2024-07-03 19:00:04 +00:00
private readonly IDalamudPluginInterface _pluginInterface;
2024-06-08 19:16:57 +00:00
private readonly IFramework _framework;
private readonly QuestController _questController;
private readonly MovementController _movementController;
private readonly WindowSystem _windowSystem;
2024-06-18 15:51:23 +00:00
private readonly QuestWindow _questWindow;
private readonly ConfigWindow _configWindow;
private readonly IToastGui _toastGui;
private readonly ILogger<DalamudInitializer> _logger;
2024-06-08 19:16:57 +00:00
public DalamudInitializer(
IDalamudPluginInterface pluginInterface,
IFramework framework,
QuestController questController,
MovementController movementController,
2024-08-17 23:55:38 +00:00
InteractionUiController interactionUiController,
WindowSystem windowSystem,
QuestWindow questWindow,
DebugOverlay debugOverlay,
ConfigWindow configWindow,
2024-07-15 22:18:10 +00:00
QuestSelectionWindow questSelectionWindow,
2024-07-29 14:54:18 +00:00
QuestValidationWindow questValidationWindow,
JournalProgressWindow journalProgressWindow,
2024-08-24 23:30:42 +00:00
PriorityWindow priorityWindow,
IToastGui toastGui,
ILogger<DalamudInitializer> logger)
2024-06-08 19:16:57 +00:00
{
_pluginInterface = pluginInterface;
_framework = framework;
_questController = questController;
_movementController = movementController;
_windowSystem = windowSystem;
2024-06-18 15:51:23 +00:00
_questWindow = questWindow;
_configWindow = configWindow;
_toastGui = toastGui;
_logger = logger;
2024-06-12 16:03:48 +00:00
2024-06-18 15:51:23 +00:00
_windowSystem.AddWindow(questWindow);
2024-06-12 16:03:48 +00:00
_windowSystem.AddWindow(configWindow);
2024-06-18 15:51:23 +00:00
_windowSystem.AddWindow(debugOverlay);
_windowSystem.AddWindow(questSelectionWindow);
2024-07-15 22:18:10 +00:00
_windowSystem.AddWindow(questValidationWindow);
2024-07-29 14:54:18 +00:00
_windowSystem.AddWindow(journalProgressWindow);
2024-08-24 23:30:42 +00:00
_windowSystem.AddWindow(priorityWindow);
2024-06-08 19:16:57 +00:00
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
2024-06-18 15:51:23 +00:00
_pluginInterface.UiBuilder.OpenMainUi += _questWindow.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;
2024-08-17 23:55:38 +00:00
_framework.RunOnTick(interactionUiController.HandleCurrentDialogueChoices, TimeSpan.FromMilliseconds(200));
_toastGui.Toast += OnToast;
_toastGui.ErrorToast += OnErrorToast;
_toastGui.QuestToast += OnQuestToast;
2024-06-08 19:16:57 +00:00
}
private void FrameworkUpdate(IFramework framework)
{
_questController.Update();
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 OnToast(ref SeString message, ref ToastOptions options, ref bool isHandled)
=> _logger.LogTrace("Normal Toast: {Message}", message);
private void OnErrorToast(ref SeString message, ref bool isHandled)
=> _logger.LogTrace("Error Toast: {Message}", message);
private void OnQuestToast(ref SeString message, ref QuestToastOptions options, ref bool isHandled)
=> _logger.LogTrace("Quest Toast: {Message}", message);
2024-06-08 19:16:57 +00:00
public void Dispose()
{
_toastGui.QuestToast -= OnQuestToast;
_toastGui.ErrorToast -= OnErrorToast;
_toastGui.Toast -= OnToast;
2024-06-08 19:16:57 +00:00
_framework.Update -= FrameworkUpdate;
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
2024-06-18 15:51:23 +00:00
_pluginInterface.UiBuilder.OpenMainUi -= _questWindow.Toggle;
2024-06-08 19:16:57 +00:00
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
2024-06-12 16:03:48 +00:00
_windowSystem.RemoveAllWindows();
2024-06-08 19:16:57 +00:00
}
}