From 8462b86544776feee08419cf7e41033d9dab8954 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 8 Dec 2024 19:03:52 +0100 Subject: [PATCH] Add tab to view available daily quests only --- Questionable/Functions/QuestFunctions.cs | 2 +- Questionable/QuestionablePlugin.cs | 1 + .../AlliedSocietyJournalComponent.cs | 97 +++++++++++++++++++ Questionable/Windows/JournalProgressWindow.cs | 4 + 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs diff --git a/Questionable/Functions/QuestFunctions.cs b/Questionable/Functions/QuestFunctions.cs index 2f0cb841..fb720e2f 100644 --- a/Questionable/Functions/QuestFunctions.cs +++ b/Questionable/Functions/QuestFunctions.cs @@ -552,7 +552,7 @@ internal sealed unsafe class QuestFunctions if (questInfo.GrandCompany != GrandCompany.None && questInfo.GrandCompany != GetGrandCompany()) return true; - if (questInfo.AlliedSociety != EAlliedSociety.None) + if (questInfo.AlliedSociety != EAlliedSociety.None && questInfo.IsRepeatable) return !IsDailyAlliedSocietyQuestAndAvailableToday(questId); return !HasCompletedPreviousQuests(questInfo, extraCompletedQuest) || !HasCompletedPreviousInstances(questInfo); diff --git a/Questionable/QuestionablePlugin.cs b/Questionable/QuestionablePlugin.cs index 2af5c204..db6d7469 100644 --- a/Questionable/QuestionablePlugin.cs +++ b/Questionable/QuestionablePlugin.cs @@ -264,6 +264,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); diff --git a/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs b/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs new file mode 100644 index 00000000..e5adbc86 --- /dev/null +++ b/Questionable/Windows/JournalComponents/AlliedSocietyJournalComponent.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Dalamud.Interface.Colors; +using Dalamud.Interface.Utility.Raii; +using ImGuiNET; +using Questionable.Controller; +using Questionable.Data; +using Questionable.Functions; +using Questionable.Model; +using Questionable.Windows.QuestComponents; + +namespace Questionable.Windows.JournalComponents; + +internal sealed class AlliedSocietyJournalComponent +{ + private static readonly string[] RankNames = + ["Neutral", "Recognized", "Friendly", "Trusted", "Respected", "Honored", "Sworn", "Allied"]; + + private readonly QuestFunctions _questFunctions; + private readonly AlliedSocietyQuestFunctions _alliedSocietyQuestFunctions; + private readonly QuestData _questData; + private readonly QuestRegistry _questRegistry; + private readonly QuestTooltipComponent _questTooltipComponent; + private readonly UiUtils _uiUtils; + + public AlliedSocietyJournalComponent( + QuestFunctions questFunctions, + AlliedSocietyQuestFunctions alliedSocietyQuestFunctions, + QuestData questData, + QuestRegistry questRegistry, + QuestTooltipComponent questTooltipComponent, + UiUtils uiUtils) + { + _questFunctions = questFunctions; + _alliedSocietyQuestFunctions = alliedSocietyQuestFunctions; + _questData = questData; + _questRegistry = questRegistry; + _questTooltipComponent = questTooltipComponent; + _uiUtils = uiUtils; + } + + public void DrawAlliedSocietyQuests() + { + using var tab = ImRaii.TabItem("Allied Societies"); + if (!tab) + return; + + foreach (EAlliedSociety alliedSociety in Enum.GetValues().Where(x => x != EAlliedSociety.None)) + { + List quests = _alliedSocietyQuestFunctions.GetAvailableAlliedSocietyQuests(alliedSociety) + .Select(x => (QuestInfo)_questData.GetQuestInfo(x)) + .ToList(); + if (quests.Count == 0) + continue; + + bool containsNewQuests = quests.Any(x => !_questFunctions.IsQuestComplete(x.QuestId)); + if (containsNewQuests) + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow); + + if (!ImGui.CollapsingHeader($"{alliedSociety}###AlliedSociety{(int)alliedSociety}")) + continue; + + if (containsNewQuests) + ImGui.PopStyleColor(); + + if (alliedSociety <= EAlliedSociety.Ixal) + { + for (byte i = 1; i <= 8; ++i) + { + var questsByRank = quests.Where(x => x.AlliedSocietyRank == i).ToList(); + if (questsByRank.Count == 0) + continue; + + ImGui.Text(RankNames[i - 1]); + foreach (var quest in questsByRank) + DrawQuest(quest); + } + } + else + { + foreach (var quest in quests) + DrawQuest(quest); + } + } + } + + private void DrawQuest(QuestInfo quest) + { + var (color, icon, tooltipText) = _uiUtils.GetQuestStyle(quest.QuestId); + if (!_questRegistry.IsKnownQuest(quest.QuestId)) + color = ImGuiColors.DalamudGrey; + + if (_uiUtils.ChecklistItem($"{quest.Name} ({tooltipText})", color, icon)) + _questTooltipComponent.Draw(quest); + } +} diff --git a/Questionable/Windows/JournalProgressWindow.cs b/Questionable/Windows/JournalProgressWindow.cs index 531828f8..6a5724a7 100644 --- a/Questionable/Windows/JournalProgressWindow.cs +++ b/Questionable/Windows/JournalProgressWindow.cs @@ -11,18 +11,21 @@ namespace Questionable.Windows; internal sealed class JournalProgressWindow : LWindow, IDisposable { private readonly QuestJournalComponent _questJournalComponent; + private readonly AlliedSocietyJournalComponent _alliedSocietyJournalComponent; private readonly GatheringJournalComponent _gatheringJournalComponent; private readonly QuestRegistry _questRegistry; private readonly IClientState _clientState; public JournalProgressWindow( QuestJournalComponent questJournalComponent, + AlliedSocietyJournalComponent alliedSocietyJournalComponent, GatheringJournalComponent gatheringJournalComponent, QuestRegistry questRegistry, IClientState clientState) : base("Journal Progress###QuestionableJournalProgress") { _questJournalComponent = questJournalComponent; + _alliedSocietyJournalComponent = alliedSocietyJournalComponent; _gatheringJournalComponent = gatheringJournalComponent; _questRegistry = questRegistry; _clientState = clientState; @@ -60,6 +63,7 @@ internal sealed class JournalProgressWindow : LWindow, IDisposable return; _questJournalComponent.DrawQuests(); + _alliedSocietyJournalComponent.DrawAlliedSocietyQuests(); _gatheringJournalComponent.DrawGatheringItems(); }