diff --git a/Questionable/Data/JournalData.cs b/Questionable/Data/JournalData.cs index 115d806e..52f37e22 100644 --- a/Questionable/Data/JournalData.cs +++ b/Questionable/Data/JournalData.cs @@ -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() - .Where(x => x.RowId > 0 && x.Icon > 0) - .Select(x => new Genre(x, questData.GetAllByJournalGenre(x.RowId))) - .ToList(); + _dataManager = dataManager; + _questData = questData; - var limsaStart = dataManager.GetExcelSheet().GetRow(1); - var gridaniaStart = dataManager.GetExcelSheet().GetRow(2); - var uldahStart = dataManager.GetExcelSheet().GetRow(3); + Reload(); + } + + public List Genres { get; set; } + public List Categories { get; set; } + public List
Sections { get; set; } + + public void Reload() + { + var genres = _dataManager.GetExcelSheet() + .Where(x => x.RowId > 0 && x.Icon > 0) + .Select(x => new Genre(x, _questData.GetAllByJournalGenre(x.RowId))) + .ToList(); + + var limsaStart = _dataManager.GetExcelSheet().GetRow(1); + var gridaniaStart = _dataManager.GetExcelSheet().GetRow(2); + var uldahStart = _dataManager.GetExcelSheet().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() + Genres = genres.ToList(); + Categories = _dataManager.GetExcelSheet() .Where(x => x.RowId > 0) .Select(x => new Category(x, Genres.Where(y => y.CategoryId == x.RowId).ToList())) - .ToList() - .AsReadOnly(); - Sections = dataManager.GetExcelSheet() + .ToList(); + Sections = _dataManager.GetExcelSheet() .Select(x => new Section(x, Categories.Where(y => y.SectionId == x.RowId).ToList())) .ToList(); } - public IReadOnlyList Genres { get; } - public IReadOnlyList Categories { get; } - public List
Sections { get; set; } - internal sealed class Genre { public Genre(JournalGenre journalGenre, List quests) diff --git a/Questionable/Functions/QuestFunctions.cs b/Questionable/Functions/QuestFunctions.cs index ace8ed3c..2078ca9e 100644 --- a/Questionable/Functions/QuestFunctions.cs +++ b/Questionable/Functions/QuestFunctions.cs @@ -455,6 +455,9 @@ internal sealed unsafe class QuestFunctions if (QuestManager.Instance()->IsDailyQuestCompleted(questId.Value)) return false; } + + if (IsQuestComplete(questId)) + return false; } else { diff --git a/Questionable/Windows/JournalComponents/QuestJournalComponent.cs b/Questionable/Windows/JournalComponents/QuestJournalComponent.cs index 04dc9bca..de5a7bb8 100644 --- a/Questionable/Windows/JournalComponents/QuestJournalComponent.cs +++ b/Questionable/Windows/JournalComponents/QuestJournalComponent.cs @@ -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 _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 match; - if (string.IsNullOrWhiteSpace(_searchText)) - match = _ => true; - else - match = x => x.Contains(_searchText, StringComparison.CurrentCultureIgnoreCase); + _journalData.Reload(); + Predicate 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() .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 match) diff --git a/Questionable/Windows/JournalComponents/QuestJournalUtils.cs b/Questionable/Windows/JournalComponents/QuestJournalUtils.cs index 40f59278..8d43d7f7 100644 --- a/Questionable/Windows/JournalComponents/QuestJournalUtils.cs +++ b/Questionable/Windows/JournalComponents/QuestJournalUtils.cs @@ -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(); + + + } }