From fb9e31cd803ab8144adf1131fa5e9984a9886a58 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 16 Jul 2024 11:15:28 +0200 Subject: [PATCH] Add currently visible unaccepted quest markers to /qst zone (only for unknown/not mapped quests) --- Questionable/Controller/CommandHandler.cs | 9 ++---- Questionable/Windows/QuestSelectionWindow.cs | 34 ++++++++++++-------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Questionable/Controller/CommandHandler.cs b/Questionable/Controller/CommandHandler.cs index 33ccf29a6..e7fa9767f 100644 --- a/Questionable/Controller/CommandHandler.cs +++ b/Questionable/Controller/CommandHandler.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using System.Linq; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.Command; using Dalamud.Plugin.Services; -using Questionable.Data; using Questionable.Model; using Questionable.Windows; @@ -23,13 +21,11 @@ internal sealed class CommandHandler : IDisposable private readonly QuestSelectionWindow _questSelectionWindow; private readonly ITargetManager _targetManager; private readonly GameFunctions _gameFunctions; - private readonly IClientState _clientState; public CommandHandler(ICommandManager commandManager, IChatGui chatGui, QuestController questController, MovementController movementController, QuestRegistry questRegistry, ConfigWindow configWindow, DebugOverlay debugOverlay, QuestWindow questWindow, - QuestSelectionWindow questSelectionWindow, ITargetManager targetManager, GameFunctions gameFunctions, - IClientState clientState) + QuestSelectionWindow questSelectionWindow, ITargetManager targetManager, GameFunctions gameFunctions) { _commandManager = commandManager; _chatGui = chatGui; @@ -42,7 +38,6 @@ internal sealed class CommandHandler : IDisposable _questSelectionWindow = questSelectionWindow; _targetManager = targetManager; _gameFunctions = gameFunctions; - _clientState = clientState; _commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand) { @@ -87,7 +82,7 @@ internal sealed class CommandHandler : IDisposable case "z": case "zone": - _questSelectionWindow.OpenForZone(_clientState.TerritoryType); + _questSelectionWindow.OpenForCurrentZone(); break; default: diff --git a/Questionable/Windows/QuestSelectionWindow.cs b/Questionable/Windows/QuestSelectionWindow.cs index 164f03b62..569fd28bc 100644 --- a/Questionable/Windows/QuestSelectionWindow.cs +++ b/Questionable/Windows/QuestSelectionWindow.cs @@ -9,6 +9,7 @@ using Dalamud.Interface.Components; using Dalamud.Interface.Utility.Raii; using Dalamud.Plugin; using Dalamud.Plugin.Services; +using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.UI; using ImGuiNET; using LLib.GameUI; @@ -30,6 +31,7 @@ internal sealed class QuestSelectionWindow : LWindow private readonly QuestRegistry _questRegistry; private readonly IDalamudPluginInterface _pluginInterface; private readonly TerritoryData _territoryData; + private readonly IClientState _clientState; private List _quests = []; private List _offeredQuests = []; @@ -37,7 +39,7 @@ internal sealed class QuestSelectionWindow : LWindow public QuestSelectionWindow(QuestData questData, IGameGui gameGui, IChatGui chatGui, GameFunctions gameFunctions, QuestController questController, QuestRegistry questRegistry, IDalamudPluginInterface pluginInterface, - TerritoryData territoryData) + TerritoryData territoryData, IClientState clientState) : base($"Quest Selection{WindowId}") { _questData = questData; @@ -48,6 +50,7 @@ internal sealed class QuestSelectionWindow : LWindow _questRegistry = questRegistry; _pluginInterface = pluginInterface; _territoryData = territoryData; + _clientState = clientState; Size = new Vector2(500, 200); SizeCondition = ImGuiCond.Once; @@ -57,18 +60,15 @@ internal sealed class QuestSelectionWindow : LWindow }; } - public uint TargetId { get; private set; } - public string TargetName { get; private set; } = string.Empty; - public unsafe void OpenForTarget(IGameObject? gameObject) { if (gameObject != null) { - TargetId = gameObject.DataId; - TargetName = gameObject.Name.ToString(); - WindowName = $"Quests starting with {TargetName} [{TargetId}]{WindowId}"; + var targetId = gameObject.DataId; + var targetName = gameObject.Name.ToString(); + WindowName = $"Quests starting with {targetName} [{targetId}]{WindowId}"; - _quests = _questData.GetAllByIssuerDataId(TargetId); + _quests = _questData.GetAllByIssuerDataId(targetId); if (_gameGui.TryGetAddonByName("SelectIconString", out var addonSelectIconString)) { var answers = GameUiController.GetChoices(addonSelectIconString); @@ -88,24 +88,30 @@ internal sealed class QuestSelectionWindow : LWindow IsOpen = _quests.Count > 0; } - public void OpenForZone(ushort territoryId) + public unsafe void OpenForCurrentZone() { - TargetId = territoryId; - TargetName = _territoryData.GetNameAndId(territoryId); - WindowName = $"Quests starting in {TargetName}{WindowId}"; + var territoryId = _clientState.TerritoryType; + var territoryName = _territoryData.GetNameAndId(territoryId); + WindowName = $"Quests starting in {territoryName}{WindowId}"; _quests = _questRegistry.AllQuests .Where(x => x.FindSequence(0)?.FindStep(0)?.TerritoryId == territoryId) .Select(x => _questData.GetQuestInfo(x.QuestId)) .ToList(); + + foreach (var unacceptedQuest in Map.Instance()->UnacceptedQuestMarkers) + { + ushort questId = (ushort)(unacceptedQuest.ObjectiveId & 0xFFFF); + if (_quests.All(q => q.QuestId != questId)) + _quests.Add(_questData.GetQuestInfo(questId)); + } + _offeredQuests = []; IsOpen = true; } public override void OnClose() { - TargetId = default; - TargetName = string.Empty; _quests = []; _offeredQuests = []; }