Hide quest filters added
authorTaurenkey <github@taurenkey.co.uk>
Thu, 26 Dec 2024 17:04:08 +0000 (17:04 +0000)
committerTaurenkey <github@taurenkey.co.uk>
Thu, 26 Dec 2024 17:04:08 +0000 (17:04 +0000)
Questionable/Data/JournalData.cs
Questionable/Functions/QuestFunctions.cs
Questionable/Windows/JournalComponents/QuestJournalComponent.cs
Questionable/Windows/JournalComponents/QuestJournalUtils.cs

index 115d806e21eceed71c598af92df59720158abed8..52f37e22eddc7eb59dba3bdc0715110808a0a179 100644 (file)
@@ -1,6 +1,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using Dalamud.Plugin.Services;
+using FFXIVClientStructs.FFXIV.Client.Game.Fate;
 using Lumina.Excel.Sheets;
 using Questionable.Model;
 using Questionable.Model.Questing;
@@ -9,30 +10,44 @@ namespace Questionable.Data;
 
 internal sealed class JournalData
 {
+    private readonly IDataManager _dataManager;
+    private readonly QuestData _questData;
     public JournalData(IDataManager dataManager, QuestData questData)
     {
-        var genres = dataManager.GetExcelSheet<JournalGenre>()
+        _dataManager = dataManager;
+        _questData = questData;
+
+        Reload();
+    }
+
+    public List<Genre> Genres { get; set; }
+    public List<Category> Categories { get; set; }
+    public List<Section> Sections { get; set; }
+
+    public void Reload()
+    {
+        var genres = _dataManager.GetExcelSheet<JournalGenre>()
             .Where(x => x.RowId > 0 && x.Icon > 0)
-            .Select(x => new Genre(x, questData.GetAllByJournalGenre(x.RowId)))
-            .ToList();
+            .Select(x => new Genre(x, _questData.GetAllByJournalGenre(x.RowId)))
+        .ToList();
 
-        var limsaStart = dataManager.GetExcelSheet<QuestRedo>().GetRow(1);
-        var gridaniaStart = dataManager.GetExcelSheet<QuestRedo>().GetRow(2);
-        var uldahStart = dataManager.GetExcelSheet<QuestRedo>().GetRow(3);
+        var limsaStart = _dataManager.GetExcelSheet<QuestRedo>().GetRow(1);
+        var gridaniaStart = _dataManager.GetExcelSheet<QuestRedo>().GetRow(2);
+        var uldahStart = _dataManager.GetExcelSheet<QuestRedo>().GetRow(3);
         var genreLimsa = new Genre(uint.MaxValue - 3, "Starting in Limsa Lominsa", 1,
             new uint[] { 108, 109 }.Concat(limsaStart.QuestRedoParam.Select(x => x.Quest.RowId))
                 .Where(x => x != 0)
-                .Select(x => questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
+                .Select(x => _questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
                 .ToList());
         var genreGridania = new Genre(uint.MaxValue - 2, "Starting in Gridania", 1,
             new uint[] { 85, 123, 124 }.Concat(gridaniaStart.QuestRedoParam.Select(x => x.Quest.RowId))
                 .Where(x => x != 0)
-                .Select(x => questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
+                .Select(x => _questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
                 .ToList());
         var genreUldah = new Genre(uint.MaxValue - 1, "Starting in Ul'dah", 1,
             new uint[] { 568, 569, 570 }.Concat(uldahStart.QuestRedoParam.Select(x => x.Quest.RowId))
                 .Where(x => x != 0)
-                .Select(x => questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
+                .Select(x => _questData.GetQuestInfo(new QuestId((ushort)(x & 0xFFFF))))
                 .ToList());
         genres.InsertRange(0, [genreLimsa, genreGridania, genreUldah]);
         genres.Single(x => x.Id == 1)
@@ -40,21 +55,16 @@ internal sealed class JournalData
             .RemoveAll(x =>
                 genreLimsa.Quests.Contains(x) || genreGridania.Quests.Contains(x) || genreUldah.Quests.Contains(x));
 
-        Genres = genres.AsReadOnly();
-        Categories = dataManager.GetExcelSheet<JournalCategory>()
+        Genres = genres.ToList();
+        Categories = _dataManager.GetExcelSheet<JournalCategory>()
             .Where(x => x.RowId > 0)
             .Select(x => new Category(x, Genres.Where(y => y.CategoryId == x.RowId).ToList()))
-            .ToList()
-            .AsReadOnly();
-        Sections = dataManager.GetExcelSheet<JournalSection>()
+        .ToList();
+        Sections = _dataManager.GetExcelSheet<JournalSection>()
             .Select(x => new Section(x, Categories.Where(y => y.SectionId == x.RowId).ToList()))
             .ToList();
     }
 
-    public IReadOnlyList<Genre> Genres { get; }
-    public IReadOnlyList<Category> Categories { get; }
-    public List<Section> Sections { get; set; }
-
     internal sealed class Genre
     {
         public Genre(JournalGenre journalGenre, List<IQuestInfo> quests)
index 8c937bcc991560efe641c7ffbb358c1b12093d52..cc38e87457ddcaf104633cc5cced565a59a5334c 100644 (file)
@@ -455,6 +455,9 @@ internal sealed unsafe class QuestFunctions
                 if (QuestManager.Instance()->IsDailyQuestCompleted(questId.Value))
                     return false;
             }
+
+            if (IsQuestComplete(questId))
+                return false;
         }
         else
         {
index 04dc9bca8fb7c031bc521cccce8446fbefb925b9..de5a7bb884ca77556cc0b2121fc68ef8ed57c02c 100644 (file)
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using Dalamud.Interface;
+using Dalamud.Interface;
 using Dalamud.Interface.Colors;
 using Dalamud.Interface.Utility.Raii;
 using Dalamud.Plugin;
@@ -12,9 +8,12 @@ using Questionable.Controller;
 using Questionable.Data;
 using Questionable.Functions;
 using Questionable.Model;
-using Questionable.Model.Questing;
 using Questionable.Validation;
 using Questionable.Windows.QuestComponents;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
 
 namespace Questionable.Windows.JournalComponents;
 
@@ -32,13 +31,14 @@ internal sealed class QuestJournalComponent
     private readonly IDalamudPluginInterface _pluginInterface;
     private readonly QuestJournalUtils _questJournalUtils;
     private readonly QuestValidator _questValidator;
+    private readonly IPluginLog _log;
 
     private List<FilteredSection> _filteredSections = [];
     private string _searchText = string.Empty;
 
     public QuestJournalComponent(JournalData journalData, QuestRegistry questRegistry, QuestFunctions questFunctions,
         UiUtils uiUtils, QuestTooltipComponent questTooltipComponent, IDalamudPluginInterface pluginInterface,
-        QuestJournalUtils questJournalUtils, QuestValidator questValidator)
+        QuestJournalUtils questJournalUtils, QuestValidator questValidator, IPluginLog log)
     {
         _journalData = journalData;
         _questRegistry = questRegistry;
@@ -48,6 +48,7 @@ internal sealed class QuestJournalComponent
         _pluginInterface = pluginInterface;
         _questJournalUtils = questJournalUtils;
         _questValidator = questValidator;
+        _log = log;
     }
 
     public void DrawQuests()
@@ -69,6 +70,9 @@ internal sealed class QuestJournalComponent
             ImGui.Spacing();
         }
 
+        QuestJournalUtils.ShowFilterContextMenu(this);
+
+        ImGui.SameLine();
         ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
         if (ImGui.InputTextWithHint(string.Empty, "Search quests and categories", ref _searchText, 256))
             UpdateFilter();
@@ -235,17 +239,41 @@ internal sealed class QuestJournalComponent
 
     public void UpdateFilter()
     {
-        Predicate<string> match;
-        if (string.IsNullOrWhiteSpace(_searchText))
-            match = _ => true;
-        else
-            match = x => x.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase);
+        _journalData.Reload();
+        Predicate<string> match = string.IsNullOrWhiteSpace(_searchText) ? x => true : x => x.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase);
 
         _filteredSections = _journalData.Sections
             .Select(section => FilterSection(section, match))
             .Where(x => x != null)
             .Cast<FilteredSection>()
             .ToList();
+
+        for (int i = 0; i < _filteredSections.Count; i++)
+        {
+            var section = _filteredSections[i];
+            for (int s = 0; s < section.Categories.Count; s++)
+            {
+                var category = section.Categories[s];
+                for (int c = 0; c < category.Genres.Count; c++)
+                {
+                    var genre = category.Genres[c];
+                    for (int g = 0; g < genre.Quests.Count; g++)
+                    {
+                        var quest = genre.Quests[g];
+
+                        //All Quest Filter conditions checked here, cause we just love IEnumerable
+                        if (QuestJournalUtils.AvailableOnly && !_questFunctions.IsReadyToAcceptQuest(quest.QuestId) ||
+                            QuestJournalUtils.HideNoPaths && !_questRegistry.TryGetQuest(quest.QuestId, out _))
+                        {
+                            genre.Quests.Remove(quest);
+                            g--;
+                        }
+                    }
+                }
+            }
+        }
+
+        RefreshCounts();
     }
 
     private static FilteredSection? FilterSection(JournalData.Section section, Predicate<string> match)
index 40f59278a06d38e64539689f497a97ac6205c9f0..8d43d7f757d41fc873f8798b3e345b9d4fa88236 100644 (file)
@@ -1,10 +1,12 @@
-using Dalamud.Interface.Utility.Raii;
+using Dalamud.Interface.Components;
+using Dalamud.Interface.Utility.Raii;
 using Dalamud.Plugin.Services;
 using ImGuiNET;
 using Questionable.Controller;
 using Questionable.Functions;
 using Questionable.Model;
 using Questionable.Model.Questing;
+using System;
 
 namespace Questionable.Windows.JournalComponents;
 
@@ -14,6 +16,9 @@ internal sealed class QuestJournalUtils
     private readonly QuestFunctions _questFunctions;
     private readonly ICommandManager _commandManager;
 
+    public static bool AvailableOnly;
+    public static bool HideNoPaths;
+
     public QuestJournalUtils(QuestController questController, QuestFunctions questFunctions,
         ICommandManager commandManager)
     {
@@ -44,4 +49,20 @@ internal sealed class QuestJournalUtils
                 commandInfo!);
         }
     }
+
+    internal static void ShowFilterContextMenu(QuestJournalComponent journalUI)
+    {
+        if (ImGuiComponents.IconButton(Dalamud.Interface.FontAwesomeIcon.Filter))
+            ImGui.OpenPopup($"##QuestFilters");
+
+        using var popup = ImRaii.Popup($"##QuestFilters");
+        if (!popup)
+            return;
+
+        if (ImGui.Checkbox("Show only Available Quests", ref AvailableOnly) ||
+            ImGui.Checkbox("Hide Quests Without Path", ref HideNoPaths))
+            journalUI.UpdateFilter();
+
+
+    }
 }