2024-06-08 19:16:57 +00:00
|
|
|
|
using System;
|
2024-08-09 21:58:19 +00:00
|
|
|
|
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;
|
2024-08-09 21:58:19 +00:00
|
|
|
|
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;
|
2024-07-10 15:58:11 +00:00
|
|
|
|
private readonly ConfigWindow _configWindow;
|
2024-08-09 21:58:19 +00:00
|
|
|
|
private readonly IToastGui _toastGui;
|
|
|
|
|
private readonly ILogger<DalamudInitializer> _logger;
|
2024-06-08 19:16:57 +00:00
|
|
|
|
|
2024-07-11 00:56:42 +00:00
|
|
|
|
public DalamudInitializer(
|
|
|
|
|
IDalamudPluginInterface pluginInterface,
|
|
|
|
|
IFramework framework,
|
|
|
|
|
QuestController questController,
|
|
|
|
|
MovementController movementController,
|
2024-08-17 23:55:38 +00:00
|
|
|
|
InteractionUiController interactionUiController,
|
2024-07-11 00:56:42 +00:00
|
|
|
|
WindowSystem windowSystem,
|
|
|
|
|
QuestWindow questWindow,
|
|
|
|
|
DebugOverlay debugOverlay,
|
2024-07-14 19:31:07 +00:00
|
|
|
|
ConfigWindow configWindow,
|
2024-07-15 22:18:10 +00:00
|
|
|
|
QuestSelectionWindow questSelectionWindow,
|
2024-07-29 14:54:18 +00:00
|
|
|
|
QuestValidationWindow questValidationWindow,
|
2024-08-09 21:58:19 +00:00
|
|
|
|
JournalProgressWindow journalProgressWindow,
|
2024-08-24 23:30:42 +00:00
|
|
|
|
PriorityWindow priorityWindow,
|
2024-08-09 21:58:19 +00:00
|
|
|
|
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;
|
2024-07-10 15:58:11 +00:00
|
|
|
|
_configWindow = configWindow;
|
2024-08-09 21:58:19 +00:00
|
|
|
|
_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);
|
2024-07-14 19:31:07 +00:00
|
|
|
|
_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));
|
2024-08-09 21:58:19 +00:00
|
|
|
|
_toastGui.Toast += OnToast;
|
|
|
|
|
_toastGui.ErrorToast += OnErrorToast;
|
|
|
|
|
_toastGui.QuestToast += OnQuestToast;
|
2024-06-08 19:16:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrameworkUpdate(IFramework framework)
|
|
|
|
|
{
|
|
|
|
|
_questController.Update();
|
2024-06-09 14:30:53 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_movementController.Update();
|
|
|
|
|
}
|
|
|
|
|
catch (MovementController.PathfindingFailedException)
|
|
|
|
|
{
|
2024-06-10 17:56:13 +00:00
|
|
|
|
_questController.Stop("Pathfinding failed");
|
2024-06-09 14:30:53 +00:00
|
|
|
|
}
|
2024-06-08 19:16:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 21:58:19 +00:00
|
|
|
|
private void OnToast(ref SeString message, ref ToastOptions options, ref bool isHandled)
|
2024-08-18 00:13:33 +00:00
|
|
|
|
=> _logger.LogTrace("Normal Toast: {Message}", message);
|
2024-08-09 21:58:19 +00:00
|
|
|
|
|
|
|
|
|
private void OnErrorToast(ref SeString message, ref bool isHandled)
|
2024-08-18 00:13:33 +00:00
|
|
|
|
=> _logger.LogTrace("Error Toast: {Message}", message);
|
2024-08-09 21:58:19 +00:00
|
|
|
|
|
|
|
|
|
private void OnQuestToast(ref SeString message, ref QuestToastOptions options, ref bool isHandled)
|
2024-08-18 00:13:33 +00:00
|
|
|
|
=> _logger.LogTrace("Quest Toast: {Message}", message);
|
2024-08-09 21:58:19 +00:00
|
|
|
|
|
2024-06-08 19:16:57 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2024-08-09 21:58:19 +00:00
|
|
|
|
_toastGui.QuestToast -= OnQuestToast;
|
|
|
|
|
_toastGui.ErrorToast -= OnErrorToast;
|
|
|
|
|
_toastGui.Toast -= OnToast;
|
2024-06-08 19:16:57 +00:00
|
|
|
|
_framework.Update -= FrameworkUpdate;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
}
|