Add right click menu to Allied Society journal tab

This commit is contained in:
Liza 2024-12-09 15:14:53 +01:00
parent 312a16f85f
commit 5bf6cbfcbb
Signed by: liza
GPG Key ID: 8DD6D21C03BB0848
4 changed files with 59 additions and 27 deletions

View File

@ -262,6 +262,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
serviceCollection.AddSingleton<QuickAccessButtonsComponent>(); serviceCollection.AddSingleton<QuickAccessButtonsComponent>();
serviceCollection.AddSingleton<RemainingTasksComponent>(); serviceCollection.AddSingleton<RemainingTasksComponent>();
serviceCollection.AddSingleton<QuestJournalUtils>();
serviceCollection.AddSingleton<QuestJournalComponent>(); serviceCollection.AddSingleton<QuestJournalComponent>();
serviceCollection.AddSingleton<GatheringJournalComponent>(); serviceCollection.AddSingleton<GatheringJournalComponent>();
serviceCollection.AddSingleton<AlliedSocietyJournalComponent>(); serviceCollection.AddSingleton<AlliedSocietyJournalComponent>();

View File

@ -21,6 +21,7 @@ internal sealed class AlliedSocietyJournalComponent
private readonly AlliedSocietyQuestFunctions _alliedSocietyQuestFunctions; private readonly AlliedSocietyQuestFunctions _alliedSocietyQuestFunctions;
private readonly QuestData _questData; private readonly QuestData _questData;
private readonly QuestRegistry _questRegistry; private readonly QuestRegistry _questRegistry;
private readonly QuestJournalUtils _questJournalUtils;
private readonly QuestTooltipComponent _questTooltipComponent; private readonly QuestTooltipComponent _questTooltipComponent;
private readonly UiUtils _uiUtils; private readonly UiUtils _uiUtils;
@ -29,6 +30,7 @@ internal sealed class AlliedSocietyJournalComponent
AlliedSocietyQuestFunctions alliedSocietyQuestFunctions, AlliedSocietyQuestFunctions alliedSocietyQuestFunctions,
QuestData questData, QuestData questData,
QuestRegistry questRegistry, QuestRegistry questRegistry,
QuestJournalUtils questJournalUtils,
QuestTooltipComponent questTooltipComponent, QuestTooltipComponent questTooltipComponent,
UiUtils uiUtils) UiUtils uiUtils)
{ {
@ -36,6 +38,7 @@ internal sealed class AlliedSocietyJournalComponent
_alliedSocietyQuestFunctions = alliedSocietyQuestFunctions; _alliedSocietyQuestFunctions = alliedSocietyQuestFunctions;
_questData = questData; _questData = questData;
_questRegistry = questRegistry; _questRegistry = questRegistry;
_questJournalUtils = questJournalUtils;
_questTooltipComponent = questTooltipComponent; _questTooltipComponent = questTooltipComponent;
_uiUtils = uiUtils; _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); var (color, icon, tooltipText) = _uiUtils.GetQuestStyle(questInfo.QuestId);
if (!_questRegistry.IsKnownQuest(quest.QuestId)) if (!_questRegistry.TryGetQuest(questInfo.QuestId, out var quest))
color = ImGuiColors.DalamudGrey; color = ImGuiColors.DalamudGrey;
if (_uiUtils.ChecklistItem($"{quest.Name} ({tooltipText})", color, icon)) if (_uiUtils.ChecklistItem($"{questInfo.Name} ({tooltipText})", color, icon))
_questTooltipComponent.Draw(quest); _questTooltipComponent.Draw(questInfo);
_questJournalUtils.ShowContextMenu(questInfo, quest, nameof(AlliedSocietyJournalComponent));
} }
} }

View File

@ -30,8 +30,7 @@ internal sealed class QuestJournalComponent
private readonly UiUtils _uiUtils; private readonly UiUtils _uiUtils;
private readonly QuestTooltipComponent _questTooltipComponent; private readonly QuestTooltipComponent _questTooltipComponent;
private readonly IDalamudPluginInterface _pluginInterface; private readonly IDalamudPluginInterface _pluginInterface;
private readonly QuestController _questController; private readonly QuestJournalUtils _questJournalUtils;
private readonly ICommandManager _commandManager;
private readonly QuestValidator _questValidator; private readonly QuestValidator _questValidator;
private List<FilteredSection> _filteredSections = []; private List<FilteredSection> _filteredSections = [];
@ -39,7 +38,7 @@ internal sealed class QuestJournalComponent
public QuestJournalComponent(JournalData journalData, QuestRegistry questRegistry, QuestFunctions questFunctions, public QuestJournalComponent(JournalData journalData, QuestRegistry questRegistry, QuestFunctions questFunctions,
UiUtils uiUtils, QuestTooltipComponent questTooltipComponent, IDalamudPluginInterface pluginInterface, UiUtils uiUtils, QuestTooltipComponent questTooltipComponent, IDalamudPluginInterface pluginInterface,
QuestController questController, ICommandManager commandManager, QuestValidator questValidator) QuestJournalUtils questJournalUtils, QuestValidator questValidator)
{ {
_journalData = journalData; _journalData = journalData;
_questRegistry = questRegistry; _questRegistry = questRegistry;
@ -47,8 +46,7 @@ internal sealed class QuestJournalComponent
_uiUtils = uiUtils; _uiUtils = uiUtils;
_questTooltipComponent = questTooltipComponent; _questTooltipComponent = questTooltipComponent;
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_questController = questController; _questJournalUtils = questJournalUtils;
_commandManager = commandManager;
_questValidator = questValidator; _questValidator = questValidator;
} }
@ -184,23 +182,7 @@ internal sealed class QuestJournalComponent
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
_questTooltipComponent.Draw(questInfo); _questTooltipComponent.Draw(questInfo);
if (ImGui.BeginPopupContextItem($"##QuestPopup{questInfo.QuestId}", ImGuiPopupFlags.MouseButtonRight)) _questJournalUtils.ShowContextMenu(questInfo, quest, nameof(QuestJournalComponent));
{
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();
}
ImGui.TableNextColumn(); ImGui.TableNextColumn();
float spacing; float spacing;

View File

@ -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!);
}
}
}