diff --git a/Questionable/QuestionablePlugin.cs b/Questionable/QuestionablePlugin.cs index db6d7469..8e4ad410 100644 --- a/Questionable/QuestionablePlugin.cs +++ b/Questionable/QuestionablePlugin.cs @@ -262,6 +262,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); diff --git a/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs b/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs index e5adbc86..92cc96b7 100644 --- a/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs +++ b/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs @@ -21,6 +21,7 @@ internal sealed class AlliedSocietyJournalComponent private readonly AlliedSocietyQuestFunctions _alliedSocietyQuestFunctions; private readonly QuestData _questData; private readonly QuestRegistry _questRegistry; + private readonly QuestJournalUtils _questJournalUtils; private readonly QuestTooltipComponent _questTooltipComponent; private readonly UiUtils _uiUtils; @@ -29,6 +30,7 @@ internal sealed class AlliedSocietyJournalComponent AlliedSocietyQuestFunctions alliedSocietyQuestFunctions, QuestData questData, QuestRegistry questRegistry, + QuestJournalUtils questJournalUtils, QuestTooltipComponent questTooltipComponent, UiUtils uiUtils) { @@ -36,6 +38,7 @@ internal sealed class AlliedSocietyJournalComponent _alliedSocietyQuestFunctions = alliedSocietyQuestFunctions; _questData = questData; _questRegistry = questRegistry; + _questJournalUtils = questJournalUtils; _questTooltipComponent = questTooltipComponent; _uiUtils = uiUtils; } @@ -85,13 +88,15 @@ internal sealed class AlliedSocietyJournalComponent } } - private void DrawQuest(QuestInfo quest) + private void DrawQuest(QuestInfo questInfo) { - var (color, icon, tooltipText) = _uiUtils.GetQuestStyle(quest.QuestId); - if (!_questRegistry.IsKnownQuest(quest.QuestId)) + var (color, icon, tooltipText) = _uiUtils.GetQuestStyle(questInfo.QuestId); + if (!_questRegistry.TryGetQuest(questInfo.QuestId, out var quest)) color = ImGuiColors.DalamudGrey; - if (_uiUtils.ChecklistItem($"{quest.Name} ({tooltipText})", color, icon)) - _questTooltipComponent.Draw(quest); + if (_uiUtils.ChecklistItem($"{questInfo.Name} ({tooltipText})", color, icon)) + _questTooltipComponent.Draw(questInfo); + + _questJournalUtils.ShowContextMenu(questInfo, quest, nameof(AlliedSocietyJournalComponent)); } } diff --git a/Questionable/Windows/JournalComponents/QuestJournalComponent.cs b/Questionable/Windows/JournalComponents/QuestJournalComponent.cs index 36565fdf..b68f9dd3 100644 --- a/Questionable/Windows/JournalComponents/QuestJournalComponent.cs +++ b/Questionable/Windows/JournalComponents/QuestJournalComponent.cs @@ -30,8 +30,7 @@ internal sealed class QuestJournalComponent private readonly UiUtils _uiUtils; private readonly QuestTooltipComponent _questTooltipComponent; private readonly IDalamudPluginInterface _pluginInterface; - private readonly QuestController _questController; - private readonly ICommandManager _commandManager; + private readonly QuestJournalUtils _questJournalUtils; private readonly QuestValidator _questValidator; private List _filteredSections = []; @@ -39,7 +38,7 @@ internal sealed class QuestJournalComponent public QuestJournalComponent(JournalData journalData, QuestRegistry questRegistry, QuestFunctions questFunctions, UiUtils uiUtils, QuestTooltipComponent questTooltipComponent, IDalamudPluginInterface pluginInterface, - QuestController questController, ICommandManager commandManager, QuestValidator questValidator) + QuestJournalUtils questJournalUtils, QuestValidator questValidator) { _journalData = journalData; _questRegistry = questRegistry; @@ -47,8 +46,7 @@ internal sealed class QuestJournalComponent _uiUtils = uiUtils; _questTooltipComponent = questTooltipComponent; _pluginInterface = pluginInterface; - _questController = questController; - _commandManager = commandManager; + _questJournalUtils = questJournalUtils; _questValidator = questValidator; } @@ -184,23 +182,7 @@ internal sealed class QuestJournalComponent if (ImGui.IsItemHovered()) _questTooltipComponent.Draw(questInfo); - if (ImGui.BeginPopupContextItem($"##QuestPopup{questInfo.QuestId}", ImGuiPopupFlags.MouseButtonRight)) - { - if (ImGui.MenuItem("Start as next quest", _questFunctions.IsReadyToAcceptQuest(questInfo.QuestId))) - { - _questController.SetNextQuest(quest); - _questController.Start("SeasonalEventSelection"); - } - - bool openInQuestMap = _commandManager.Commands.TryGetValue("/questinfo", out var commandInfo); - if (ImGui.MenuItem("View in Quest Map", questInfo.QuestId is QuestId && openInQuestMap)) - { - _commandManager.DispatchCommand("/questinfo", questInfo.QuestId.ToString() ?? string.Empty, - commandInfo!); - } - - ImGui.EndPopup(); - } + _questJournalUtils.ShowContextMenu(questInfo, quest, nameof(QuestJournalComponent)); ImGui.TableNextColumn(); float spacing; diff --git a/Questionable/Windows/JournalComponents/QuestJournalUtils.cs b/Questionable/Windows/JournalComponents/QuestJournalUtils.cs new file mode 100644 index 00000000..c98dba68 --- /dev/null +++ b/Questionable/Windows/JournalComponents/QuestJournalUtils.cs @@ -0,0 +1,44 @@ +using Dalamud.Interface.Utility.Raii; +using Dalamud.Plugin.Services; +using ImGuiNET; +using Questionable.Controller; +using Questionable.Functions; +using Questionable.Model; +using Questionable.Model.Questing; + +namespace Questionable.Windows.JournalComponents; + +internal sealed class QuestJournalUtils +{ + private readonly QuestController _questController; + private readonly QuestFunctions _questFunctions; + private readonly ICommandManager _commandManager; + + public QuestJournalUtils(QuestController questController, QuestFunctions questFunctions, + ICommandManager commandManager) + { + _questController = questController; + _questFunctions = questFunctions; + _commandManager = commandManager; + } + + public void ShowContextMenu(IQuestInfo questInfo, Quest? quest, string label) + { + using var popup = ImRaii.ContextPopup($"##QuestPopup{questInfo.QuestId}", ImGuiPopupFlags.MouseButtonRight); + if (!popup) + return; + + if (ImGui.MenuItem("Start as next quest", _questFunctions.IsReadyToAcceptQuest(questInfo.QuestId))) + { + _questController.SetNextQuest(quest); + _questController.Start(label); + } + + bool openInQuestMap = _commandManager.Commands.TryGetValue("/questinfo", out var commandInfo); + if (ImGui.MenuItem("View in Quest Map", questInfo.QuestId is QuestId && openInQuestMap)) + { + _commandManager.DispatchCommand("/questinfo", questInfo.QuestId.ToString() ?? string.Empty, + commandInfo!); + } + } +}