From 21063217a500f5d509758d3357b9e91e1b3ffdf5 Mon Sep 17 00:00:00 2001 From: goat Date: Sat, 20 Jul 2024 02:17:27 +0200 Subject: [PATCH] pi: add "hidden" tab if there are any hidden plugins --- .../Internal/PluginCategoryManager.cs | 21 +++++++- .../PluginInstaller/PluginInstallerWindow.cs | 48 ++++++++++++++++--- Dalamud/Plugin/Internal/PluginManager.cs | 6 --- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/Dalamud/Interface/Internal/PluginCategoryManager.cs b/Dalamud/Interface/Internal/PluginCategoryManager.cs index ec2a1c15b..71c869ede 100644 --- a/Dalamud/Interface/Internal/PluginCategoryManager.cs +++ b/Dalamud/Interface/Internal/PluginCategoryManager.cs @@ -23,6 +23,7 @@ internal class PluginCategoryManager new(CategoryKind.All, "special.all", () => Locs.Category_All), new(CategoryKind.IsTesting, "special.isTesting", () => Locs.Category_IsTesting, CategoryInfo.AppearCondition.DoPluginTest), new(CategoryKind.AvailableForTesting, "special.availableForTesting", () => Locs.Category_AvailableForTesting, CategoryInfo.AppearCondition.DoPluginTest), + new(CategoryKind.Hidden, "special.hidden", () => Locs.Category_Hidden, CategoryInfo.AppearCondition.AnyHiddenPlugins), new(CategoryKind.DevInstalled, "special.devInstalled", () => Locs.Category_DevInstalled), new(CategoryKind.IconTester, "special.devIconTester", () => Locs.Category_IconTester), new(CategoryKind.DalamudChangelogs, "special.dalamud", () => Locs.Category_Dalamud), @@ -106,6 +107,11 @@ internal class PluginCategoryManager /// AvailableForTesting = 2, + /// + /// Plugins that were hidden. + /// + Hidden = 3, + /// /// Installed dev plugins. /// @@ -309,6 +315,9 @@ internal class PluginCategoryManager { groupAvail.Categories.Add(this.CategoryList[categoryIdx].CategoryKind); } + + // Hidden at the end + groupAvail.Categories.Add(CategoryKind.Hidden); // compare with prev state and mark as dirty if needed var noCategoryChanges = prevCategoryIds.SequenceEqual(groupAvail.Categories); @@ -332,7 +341,10 @@ internal class PluginCategoryManager { var groupInfo = this.groupList[this.currentGroupIdx]; - var includeAll = (this.currentCategoryKind == CategoryKind.All) || (groupInfo.GroupKind != GroupKind.Available); + var includeAll = this.currentCategoryKind == CategoryKind.All || + this.currentCategoryKind == CategoryKind.Hidden || + groupInfo.GroupKind != GroupKind.Available; + if (includeAll) { result.AddRange(plugins); @@ -455,6 +467,11 @@ internal class PluginCategoryManager /// Check if plugin testing is enabled. /// DoPluginTest, + + /// + /// Check if there are any hidden plugins. + /// + AnyHiddenPlugins, } /// @@ -529,6 +546,8 @@ internal class PluginCategoryManager public static string Category_AvailableForTesting => Loc.Localize("InstallerCategoryAvailableForTesting", "Testing Available"); + public static string Category_Hidden => Loc.Localize("InstallerCategoryHidden", "Hidden"); + public static string Category_DevInstalled => Loc.Localize("InstallerInstalledDevPlugins", "Installed Dev Plugins"); public static string Category_IconTester => "Image/Icon Tester"; diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index fd9ef1044..466277a2f 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -118,7 +118,8 @@ internal class PluginInstallerWindow : Window, IDisposable private List pluginListInstalled = new(); private List pluginListUpdatable = new(); private bool hasDevPlugins = false; - + private bool hasHiddenPlugins = false; + private string searchText = string.Empty; private bool isSearchTextPrefilled = false; @@ -1277,6 +1278,19 @@ internal class PluginInstallerWindow : Window, IDisposable proxies.Add(new PluginInstallerAvailablePluginProxy(null, installedPlugin)); } + var configuration = Service.Get(); + bool IsProxyHidden(PluginInstallerAvailablePluginProxy proxy) + { + var isHidden = + configuration.HiddenPluginInternalName.Contains(proxy.RemoteManifest?.InternalName); + if (this.categoryManager.CurrentCategoryKind == PluginCategoryManager.CategoryKind.Hidden) + return isHidden; + return !isHidden; + } + + // Filter out plugins that are not hidden + proxies = proxies.Where(IsProxyHidden).ToList(); + return proxies; } #pragma warning restore SA1201 @@ -1305,6 +1319,12 @@ internal class PluginInstallerWindow : Window, IDisposable ImGui.PopID(); } + + // Reset the category to "All" if we're on the "Hidden" category and there are no hidden plugins (we removed the last one) + if (i == 0 && this.categoryManager.CurrentCategoryKind == PluginCategoryManager.CategoryKind.Hidden) + { + this.categoryManager.CurrentCategoryKind = PluginCategoryManager.CategoryKind.All; + } } private void DrawInstalledPluginList(InstalledPluginListFilter filter) @@ -1471,6 +1491,10 @@ internal class PluginInstallerWindow : Window, IDisposable if (!Service.Get().DoPluginTest) continue; break; + case PluginCategoryManager.CategoryInfo.AppearCondition.AnyHiddenPlugins: + if (!this.hasHiddenPlugins) + continue; + break; default: throw new ArgumentOutOfRangeException(); } @@ -2456,12 +2480,19 @@ internal class PluginInstallerWindow : Window, IDisposable pluginManager.RefilterPluginMasters(); } - if (ImGui.Selectable(Locs.PluginContext_HidePlugin)) + var isHidden = configuration.HiddenPluginInternalName.Contains(manifest.InternalName); + switch (isHidden) { - Log.Debug($"Adding {manifest.InternalName} to hidden plugins"); - configuration.HiddenPluginInternalName.Add(manifest.InternalName); - configuration.QueueSave(); - pluginManager.RefilterPluginMasters(); + case false when ImGui.Selectable(Locs.PluginContext_HidePlugin): + configuration.HiddenPluginInternalName.Add(manifest.InternalName); + configuration.QueueSave(); + pluginManager.RefilterPluginMasters(); + break; + case true when ImGui.Selectable(Locs.PluginContext_UnhidePlugin): + configuration.HiddenPluginInternalName.Remove(manifest.InternalName); + configuration.QueueSave(); + pluginManager.RefilterPluginMasters(); + break; } if (ImGui.Selectable(Locs.PluginContext_DeletePluginConfig)) @@ -3638,6 +3669,7 @@ internal class PluginInstallerWindow : Window, IDisposable private void OnAvailablePluginsChanged() { var pluginManager = Service.Get(); + var configuration = Service.Get(); lock (this.listLock) { @@ -3647,6 +3679,8 @@ internal class PluginInstallerWindow : Window, IDisposable this.pluginListUpdatable = pluginManager.UpdatablePlugins.ToList(); this.ResortPlugins(); } + + this.hasHiddenPlugins = this.pluginListAvailable.Any(x => configuration.HiddenPluginInternalName.Contains(x.InternalName)); this.UpdateCategoriesOnPluginsChange(); } @@ -3974,6 +4008,8 @@ internal class PluginInstallerWindow : Window, IDisposable public static string PluginContext_MarkAllSeen => Loc.Localize("InstallerMarkAllSeen", "Mark all as seen"); public static string PluginContext_HidePlugin => Loc.Localize("InstallerHidePlugin", "Hide from installer"); + + public static string PluginContext_UnhidePlugin => Loc.Localize("InstallerUnhidePlugin", "Unhide from installer"); public static string PluginContext_DeletePluginConfig => Loc.Localize("InstallerDeletePluginConfig", "Reset plugin data"); diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index ca9e4a922..5d365d66c 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -258,12 +258,6 @@ internal class PluginManager : IInternalDisposableService /// If the manifest is visible. public static bool IsManifestVisible(RemotePluginManifest manifest) { - var configuration = Service.Get(); - - // Hidden by user - if (configuration.HiddenPluginInternalName.Contains(manifest.InternalName)) - return false; - // Hidden by manifest return !manifest.IsHide; }