171 lines
5.7 KiB
C#
Raw Normal View History

2024-07-26 17:17:52 +02:00
using System;
using System.Numerics;
2024-08-10 00:57:09 +02:00
using Dalamud.Interface;
using Dalamud.Interface.Colors;
2024-06-08 11:30:26 +02:00
using Dalamud.Plugin;
2024-05-25 23:51:37 +02:00
using Dalamud.Plugin.Services;
using ImGuiNET;
2024-06-08 11:30:26 +02:00
using LLib.ImGui;
2024-05-25 23:51:37 +02:00
using Questionable.Controller;
2024-08-18 01:55:38 +02:00
using Questionable.Controller.GameUi;
using Questionable.Data;
using Questionable.Windows.QuestComponents;
2024-05-25 23:51:37 +02:00
namespace Questionable.Windows;
2024-06-18 17:51:23 +02:00
internal sealed class QuestWindow : LWindow, IPersistableWindowConfig
2024-05-25 23:51:37 +02:00
{
2024-07-26 17:17:52 +02:00
private static readonly Version PluginVersion = typeof(QuestionablePlugin).Assembly.GetName().Version!;
2024-07-03 21:00:04 +02:00
private readonly IDalamudPluginInterface _pluginInterface;
2024-05-26 21:45:26 +02:00
private readonly QuestController _questController;
2024-05-25 23:51:37 +02:00
private readonly IClientState _clientState;
2024-06-08 11:30:26 +02:00
private readonly Configuration _configuration;
private readonly TerritoryData _territoryData;
private readonly ActiveQuestComponent _activeQuestComponent;
private readonly ARealmRebornComponent _aRealmRebornComponent;
private readonly CreationUtilsComponent _creationUtilsComponent;
2024-08-19 15:19:15 +02:00
private readonly EventInfoComponent _eventInfoComponent;
private readonly QuickAccessButtonsComponent _quickAccessButtonsComponent;
private readonly RemainingTasksComponent _remainingTasksComponent;
2024-08-10 00:57:09 +02:00
private readonly IFramework _framework;
2024-08-18 01:55:38 +02:00
private readonly InteractionUiController _interactionUiController;
2024-08-10 00:57:09 +02:00
private readonly TitleBarButton _minimizeButton;
2024-05-25 23:51:37 +02:00
2024-07-03 21:00:04 +02:00
public QuestWindow(IDalamudPluginInterface pluginInterface,
2024-06-12 18:03:48 +02:00
QuestController questController,
IClientState clientState,
Configuration configuration,
TerritoryData territoryData,
ActiveQuestComponent activeQuestComponent,
ARealmRebornComponent aRealmRebornComponent,
2024-08-19 15:19:15 +02:00
EventInfoComponent eventInfoComponent,
CreationUtilsComponent creationUtilsComponent,
QuickAccessButtonsComponent quickAccessButtonsComponent,
2024-08-10 00:57:09 +02:00
RemainingTasksComponent remainingTasksComponent,
IFramework framework,
2024-08-18 01:55:38 +02:00
InteractionUiController interactionUiController)
2024-08-10 00:57:09 +02:00
: base($"Questionable v{PluginVersion.ToString(2)}###Questionable",
ImGuiWindowFlags.AlwaysAutoResize)
2024-05-25 23:51:37 +02:00
{
2024-06-08 11:30:26 +02:00
_pluginInterface = pluginInterface;
2024-05-26 21:45:26 +02:00
_questController = questController;
2024-05-25 23:51:37 +02:00
_clientState = clientState;
2024-06-08 11:30:26 +02:00
_configuration = configuration;
_territoryData = territoryData;
_activeQuestComponent = activeQuestComponent;
_aRealmRebornComponent = aRealmRebornComponent;
2024-08-19 15:19:15 +02:00
_eventInfoComponent = eventInfoComponent;
_creationUtilsComponent = creationUtilsComponent;
_quickAccessButtonsComponent = quickAccessButtonsComponent;
_remainingTasksComponent = remainingTasksComponent;
2024-08-10 00:57:09 +02:00
_framework = framework;
2024-08-18 01:55:38 +02:00
_interactionUiController = interactionUiController;
2024-05-25 23:51:37 +02:00
2024-06-17 00:32:24 +02:00
#if DEBUG
2024-05-25 23:51:37 +02:00
IsOpen = true;
2024-06-17 00:32:24 +02:00
#endif
2024-05-25 23:51:37 +02:00
SizeConstraints = new WindowSizeConstraints
{
2024-05-27 21:54:34 +02:00
MinimumSize = new Vector2(200, 30),
2024-05-25 23:51:37 +02:00
MaximumSize = default
};
RespectCloseHotkey = false;
2024-08-11 03:34:47 +02:00
AllowClickthrough = false;
2024-08-10 00:57:09 +02:00
_minimizeButton = new TitleBarButton
{
Icon = FontAwesomeIcon.Minus,
Priority = int.MinValue,
IconOffset = new Vector2(1.5f, 1),
Click = _ =>
{
IsMinimized = !IsMinimized;
_minimizeButton!.Icon = IsMinimized ? FontAwesomeIcon.WindowMaximize : FontAwesomeIcon.Minus;
},
AvailableClickthrough = true,
};
TitleBarButtons.Insert(0, _minimizeButton);
_activeQuestComponent.Reload += OnReload;
_quickAccessButtonsComponent.Reload += OnReload;
2024-05-25 23:51:37 +02:00
}
2024-06-08 11:30:26 +02:00
public WindowConfig WindowConfig => _configuration.DebugWindowConfig;
2024-08-10 00:57:09 +02:00
public bool IsMinimized { get; set; }
2024-06-08 11:30:26 +02:00
public void SaveWindowConfig() => _pluginInterface.SavePluginConfig(_configuration);
public override void PreOpenCheck()
{
if (_questController.IsRunning)
{
IsOpen = true;
Flags |= ImGuiWindowFlags.NoCollapse;
ShowCloseButton = false;
}
else
{
Flags &= ~ImGuiWindowFlags.NoCollapse;
ShowCloseButton = true;
}
}
public override bool DrawConditions()
{
2024-11-03 19:25:33 +01:00
if (!_configuration.IsPluginSetupComplete())
return false;
if (!_clientState.IsLoggedIn || _clientState.LocalPlayer == null || _clientState.IsPvPExcludingDen)
return false;
if (_configuration.General.HideInAllInstances && _territoryData.IsDutyInstance(_clientState.TerritoryType))
return false;
return true;
}
2024-06-09 16:37:26 +02:00
public override void Draw()
2024-05-25 23:51:37 +02:00
{
try
2024-05-25 23:51:37 +02:00
{
_activeQuestComponent.Draw(IsMinimized);
if (!IsMinimized)
2024-08-10 00:57:09 +02:00
{
ImGui.Separator();
if (_aRealmRebornComponent.ShouldDraw)
{
_aRealmRebornComponent.Draw();
ImGui.Separator();
}
2024-08-19 15:19:15 +02:00
if (_eventInfoComponent.ShouldDraw)
{
_eventInfoComponent.Draw();
ImGui.Separator();
}
_creationUtilsComponent.Draw();
ImGui.Separator();
2024-08-10 00:57:09 +02:00
_quickAccessButtonsComponent.Draw();
_remainingTasksComponent.Draw();
}
}
catch (Exception e)
{
ImGui.TextColored(ImGuiColors.DalamudRed, e.ToString());
}
2024-08-10 00:57:09 +02:00
}
2024-08-10 00:57:09 +02:00
private void OnReload(object? sender, EventArgs e) => Reload();
2024-08-10 00:57:09 +02:00
internal void Reload()
{
_questController.Reload();
2024-08-18 01:55:38 +02:00
_framework.RunOnTick(() => _interactionUiController.HandleCurrentDialogueChoices(),
2024-08-10 00:57:09 +02:00
TimeSpan.FromMilliseconds(200));
2024-05-25 23:51:37 +02:00
}
}