1
0
forked from liza/Questionable

Add minimal debug overlay

This commit is contained in:
Liza 2024-06-18 17:51:23 +02:00
parent 7dff411947
commit 2f73fd64fb
Signed by: liza
GPG Key ID: 7199F8D727D55F67
7 changed files with 94 additions and 16 deletions

View File

@ -285,8 +285,7 @@
}, },
"TerritoryId": 958, "TerritoryId": 958,
"InteractionType": "Interact", "InteractionType": "Interact",
"Mount": false, "Mount": false
"Comment": "TODO Should cancel Navmesh on fade out"
} }
] ]
}, },

View File

@ -21,6 +21,7 @@ internal sealed class Configuration : IPluginConfiguration
internal sealed class AdvancedConfiguration internal sealed class AdvancedConfiguration
{ {
public bool DebugOverlay { get; set; }
public bool NeverFly { get; set; } public bool NeverFly { get; set; }
} }
} }

View File

@ -17,13 +17,13 @@ internal sealed class DalamudInitializer : IDisposable
private readonly MovementController _movementController; private readonly MovementController _movementController;
private readonly NavigationShortcutController _navigationShortcutController; private readonly NavigationShortcutController _navigationShortcutController;
private readonly WindowSystem _windowSystem; private readonly WindowSystem _windowSystem;
private readonly DebugWindow _debugWindow; private readonly QuestWindow _questWindow;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
public DalamudInitializer(DalamudPluginInterface pluginInterface, IFramework framework, public DalamudInitializer(DalamudPluginInterface pluginInterface, IFramework framework,
ICommandManager commandManager, QuestController questController, MovementController movementController, ICommandManager commandManager, QuestController questController, MovementController movementController,
GameUiController gameUiController, NavigationShortcutController navigationShortcutController, GameUiController gameUiController, NavigationShortcutController navigationShortcutController,
WindowSystem windowSystem, DebugWindow debugWindow, ConfigWindow configWindow) WindowSystem windowSystem, QuestWindow questWindow, DebugOverlay debugOverlay, ConfigWindow configWindow)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_framework = framework; _framework = framework;
@ -32,14 +32,15 @@ internal sealed class DalamudInitializer : IDisposable
_movementController = movementController; _movementController = movementController;
_navigationShortcutController = navigationShortcutController; _navigationShortcutController = navigationShortcutController;
_windowSystem = windowSystem; _windowSystem = windowSystem;
_debugWindow = debugWindow; _questWindow = questWindow;
_configWindow = configWindow; _configWindow = configWindow;
_windowSystem.AddWindow(debugWindow); _windowSystem.AddWindow(questWindow);
_windowSystem.AddWindow(configWindow); _windowSystem.AddWindow(configWindow);
_windowSystem.AddWindow(debugOverlay);
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenMainUi += _debugWindow.Toggle; _pluginInterface.UiBuilder.OpenMainUi += _questWindow.Toggle;
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle; _pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
_framework.Update += FrameworkUpdate; _framework.Update += FrameworkUpdate;
_commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand) _commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand)
@ -70,14 +71,14 @@ internal sealed class DalamudInitializer : IDisposable
if (arguments is "c" or "config") if (arguments is "c" or "config")
_configWindow.Toggle(); _configWindow.Toggle();
else else
_debugWindow.Toggle(); _questWindow.Toggle();
} }
public void Dispose() public void Dispose()
{ {
_commandManager.RemoveHandler("/qst"); _commandManager.RemoveHandler("/qst");
_framework.Update -= FrameworkUpdate; _framework.Update -= FrameworkUpdate;
_pluginInterface.UiBuilder.OpenMainUi -= _debugWindow.Toggle; _pluginInterface.UiBuilder.OpenMainUi -= _questWindow.Toggle;
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
_windowSystem.RemoveAllWindows(); _windowSystem.RemoveAllWindows();

View File

@ -80,6 +80,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>(); serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>();
serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckTask>(); serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckTask>();
serviceCollection.AddTaskWithFactory<AethernetShortcut.Factory, AethernetShortcut.UseAethernetShortcut>(); serviceCollection.AddTaskWithFactory<AethernetShortcut.Factory, AethernetShortcut.UseAethernetShortcut>();
serviceCollection.AddTaskWithFactory<WaitAtStart.Factory, WaitAtStart.WaitDelay>();
serviceCollection.AddTaskWithFactory<Move.Factory, Move.MoveInternal, Move.ExpectToBeNearDataId>(); serviceCollection.AddTaskWithFactory<Move.Factory, Move.MoveInternal, Move.ExpectToBeNearDataId>();
serviceCollection.AddTransient<Move.MoveBuilder>(); serviceCollection.AddTransient<Move.MoveBuilder>();
@ -109,13 +110,14 @@ public sealed class QuestionablePlugin : IDalamudPlugin
serviceCollection.AddSingleton<GameUiController>(); serviceCollection.AddSingleton<GameUiController>();
serviceCollection.AddSingleton<NavigationShortcutController>(); serviceCollection.AddSingleton<NavigationShortcutController>();
serviceCollection.AddSingleton<DebugWindow>(); serviceCollection.AddSingleton<QuestWindow>();
serviceCollection.AddSingleton<ConfigWindow>(); serviceCollection.AddSingleton<ConfigWindow>();
serviceCollection.AddSingleton<DebugOverlay>();
serviceCollection.AddSingleton<DalamudInitializer>(); serviceCollection.AddSingleton<DalamudInitializer>();
_serviceProvider = serviceCollection.BuildServiceProvider(); _serviceProvider = serviceCollection.BuildServiceProvider();
_serviceProvider.GetRequiredService<QuestRegistry>().Reload(); _serviceProvider.GetRequiredService<QuestRegistry>().Reload();
_serviceProvider.GetRequiredService<DebugWindow>(); _serviceProvider.GetRequiredService<QuestWindow>();
_serviceProvider.GetRequiredService<DalamudInitializer>(); _serviceProvider.GetRequiredService<DalamudInitializer>();
} }

View File

@ -79,6 +79,13 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig
ImGui.Separator(); ImGui.Separator();
bool debugOverlay = _configuration.Advanced.DebugOverlay;
if (ImGui.Checkbox("Enable debug overlay", ref debugOverlay))
{
_configuration.Advanced.DebugOverlay = debugOverlay;
Save();
}
bool neverFly = _configuration.Advanced.NeverFly; bool neverFly = _configuration.Advanced.NeverFly;
if (ImGui.Checkbox("Disable flying (even if unlocked for the zone)", ref neverFly)) if (ImGui.Checkbox("Disable flying (even if unlocked for the zone)", ref neverFly))
{ {

View File

@ -0,0 +1,68 @@
using System;
using System.Globalization;
using System.Linq;
using System.Numerics;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using ImGuiNET;
using Questionable.Controller;
using Questionable.Model.V1;
namespace Questionable.Windows;
internal sealed class DebugOverlay : Window
{
private readonly QuestController _questController;
private readonly IGameGui _gameGui;
private readonly Configuration _configuration;
public DebugOverlay(QuestController questController, IGameGui gameGui, Configuration configuration)
: base("Questionable Debug Overlay###QuestionableDebugOverlay",
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoBackground |
ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoSavedSettings, true)
{
_questController = questController;
_gameGui = gameGui;
_configuration = configuration;
Position = Vector2.Zero;
PositionCondition = ImGuiCond.Always;
Size = ImGui.GetIO().DisplaySize;
SizeCondition = ImGuiCond.Always;
IsOpen = true;
}
public override bool DrawConditions() => _configuration.Advanced.DebugOverlay;
public override void PreDraw()
{
Size = ImGui.GetIO().DisplaySize;
}
public override void Draw()
{
var currentQuest = _questController.CurrentQuest;
if (currentQuest == null)
return;
var sequence = currentQuest.Quest.FindSequence(currentQuest.Sequence);
if (sequence == null)
return;
for (int i = currentQuest.Step; i <= sequence.Steps.Count; ++i)
{
QuestStep? step = sequence.FindStep(i);
if (step == null || step.Position == null)
continue;
bool visible = _gameGui.WorldToScreen(step.Position.Value, out Vector2 screenPos);
if (!visible)
continue;
ImGui.GetWindowDrawList().AddCircleFilled(screenPos, 3f, 0xFF0000FF);
ImGui.GetWindowDrawList().AddText(screenPos + new Vector2(10, -8), 0xFF0000FF,
$"{i}: {step.InteractionType}\n{step.Position.Value.ToString("G", CultureInfo.InvariantCulture)}\n{step.Comment}");
}
}
}

View File

@ -24,7 +24,7 @@ using Questionable.Model.V1;
namespace Questionable.Windows; namespace Questionable.Windows;
internal sealed class DebugWindow : LWindow, IPersistableWindowConfig internal sealed class QuestWindow : LWindow, IPersistableWindowConfig
{ {
private readonly DalamudPluginInterface _pluginInterface; private readonly DalamudPluginInterface _pluginInterface;
private readonly MovementController _movementController; private readonly MovementController _movementController;
@ -36,9 +36,9 @@ internal sealed class DebugWindow : LWindow, IPersistableWindowConfig
private readonly GameUiController _gameUiController; private readonly GameUiController _gameUiController;
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly NavmeshIpc _navmeshIpc; private readonly NavmeshIpc _navmeshIpc;
private readonly ILogger<DebugWindow> _logger; private readonly ILogger<QuestWindow> _logger;
public DebugWindow(DalamudPluginInterface pluginInterface, public QuestWindow(DalamudPluginInterface pluginInterface,
MovementController movementController, MovementController movementController,
QuestController questController, QuestController questController,
GameFunctions gameFunctions, GameFunctions gameFunctions,
@ -48,8 +48,8 @@ internal sealed class DebugWindow : LWindow, IPersistableWindowConfig
GameUiController gameUiController, GameUiController gameUiController,
Configuration configuration, Configuration configuration,
NavmeshIpc navmeshIpc, NavmeshIpc navmeshIpc,
ILogger<DebugWindow> logger) ILogger<QuestWindow> logger)
: base("Questionable", ImGuiWindowFlags.AlwaysAutoResize) : base("Questionable###Questionable", ImGuiWindowFlags.AlwaysAutoResize)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_movementController = movementController; _movementController = movementController;