From b9a9e30388a0227e99affc40d725df50778df990 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 15 Feb 2021 13:58:56 +0100 Subject: [PATCH] Added Filter to Installed Mod List. --- Penumbra/UI/SettingsInterface.cs | 2 + Penumbra/UI/TabInstalledDetails.cs | 2 +- Penumbra/UI/TabInstalledSelector.cs | 62 +++++++++++++++++++++-------- Penumbra/Util/ArrayExtensions.cs | 56 ++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 Penumbra/Util/ArrayExtensions.cs diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index 2b8f9bbf..9273b1e4 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -35,12 +35,14 @@ namespace Penumbra.UI private void ReloadMods() { + _menu._installedTab._selector.ResetModNamesLower(); _menu._installedTab._selector.ClearSelection(); // create the directory if it doesn't exist Directory.CreateDirectory( _plugin.Configuration.CurrentCollection ); _plugin.ModManager.DiscoverMods( _plugin.Configuration.CurrentCollection ); _menu._effectiveTab.RebuildFileList(_plugin.Configuration.ShowAdvanced); + _menu._installedTab._selector.ResetModNamesLower(); } } } \ No newline at end of file diff --git a/Penumbra/UI/TabInstalledDetails.cs b/Penumbra/UI/TabInstalledDetails.cs index 42d08416..5e30c00a 100644 --- a/Penumbra/UI/TabInstalledDetails.cs +++ b/Penumbra/UI/TabInstalledDetails.cs @@ -416,7 +416,7 @@ namespace Penumbra.UI foreach (var gamePath in gamePaths) { string tmp = gamePath; - if (ImGui.InputText($"##{gamePath}", ref tmp, 128, ImGuiInputTextFlags.EnterReturnsTrue)) + if (ImGui.InputText($"##{fileName}_{gamePath}", ref tmp, 128, ImGuiInputTextFlags.EnterReturnsTrue)) { if (tmp != gamePath) { diff --git a/Penumbra/UI/TabInstalledSelector.cs b/Penumbra/UI/TabInstalledSelector.cs index 5cb0544a..27f20bda 100644 --- a/Penumbra/UI/TabInstalledSelector.cs +++ b/Penumbra/UI/TabInstalledSelector.cs @@ -13,17 +13,19 @@ namespace Penumbra.UI { private class Selector { - private const string LabelSelectorList = "##availableModList"; - private const string TooltipMoveDown = "Move the selected mod down in priority"; - private const string TooltipMoveUp = "Move the selected mod up in priority"; - private const string TooltipDelete = "Delete the selected mod"; - private const string TooltipAdd = "Add an empty mod"; - private const string DialogDeleteMod = "PenumbraDeleteMod"; - private const string ButtonYesDelete = "Yes, delete it"; - private const string ButtonNoDelete = "No, keep it"; - private const float SelectorPanelWidth = 240f; - private const uint DisabledModColor = 0xFF666666; - private const uint ConflictingModColor = 0xFFAAAAFF; + private const string LabelSelectorList = "##availableModList"; + private const string LabelModFilter = "##ModFilter"; + private const string TooltipModFilter = "Filter mods for those containing the given substring."; + private const string TooltipMoveDown = "Move the selected mod down in priority"; + private const string TooltipMoveUp = "Move the selected mod up in priority"; + private const string TooltipDelete = "Delete the selected mod"; + private const string TooltipAdd = "Add an empty mod"; + private const string DialogDeleteMod = "PenumbraDeleteMod"; + private const string ButtonYesDelete = "Yes, delete it"; + private const string ButtonNoDelete = "No, keep it"; + private const float SelectorPanelWidth = 240f; + private const uint DisabledModColor = 0xFF666666; + private const uint ConflictingModColor = 0xFFAAAAFF; private static readonly Vector2 SelectorButtonSizes = new(60, 0); private static readonly string ArrowUpString = FontAwesomeIcon.ArrowUp.ToIconString(); @@ -32,13 +34,22 @@ namespace Penumbra.UI private readonly SettingsInterface _base; private ModCollection Mods{ get{ return _base._plugin.ModManager.Mods; } } - private ModInfo _mod = null; - private int _index = 0; - private int? _deleteIndex = null; + private ModInfo _mod = null; + private int _index = 0; + private int? _deleteIndex = null; + private string _modFilter = ""; + private string[] _modNamesLower = null; + public Selector(SettingsInterface ui) { _base = ui; + ResetModNamesLower(); + } + + public void ResetModNamesLower() + { + _modNamesLower = Mods.ModSettings.Select( I => I.Mod.Meta.Name.ToLowerInvariant() ).ToArray(); } private void DrawPriorityChangeButton(string iconString, bool up, int unavailableWhen) @@ -50,6 +61,7 @@ namespace Penumbra.UI { SetSelection(_index); _base._plugin.ModManager.ChangeModPriority( _mod, up ); + _modNamesLower.Swap(_index, _index + (up ? 1 : -1)); _index += up ? 1 : -1; } } @@ -100,6 +112,18 @@ namespace Penumbra.UI ImGui.SetTooltip( TooltipAdd ); } + private void DrawModsSelectorFilter() + { + ImGui.SetNextItemWidth( SelectorButtonSizes.X * 4 ); + string tmp = _modFilter; + if (ImGui.InputText(LabelModFilter, ref tmp, 256)) + { + _modFilter = tmp.ToLowerInvariant(); + } + if( ImGui.IsItemHovered() ) + ImGui.SetTooltip( TooltipModFilter ); + } + private void DrawModsSelectorButtons() { // Selector controls @@ -168,12 +192,17 @@ namespace Penumbra.UI ImGui.BeginGroup(); ImGui.PushStyleVar( ImGuiStyleVar.ItemSpacing, ZeroVector ); + DrawModsSelectorFilter(); + // Inlay selector list ImGui.BeginChild( LabelSelectorList, new Vector2(SelectorPanelWidth, -ImGui.GetFrameHeightWithSpacing() ), true ); for( var modIndex = 0; modIndex < Mods.ModSettings.Count; modIndex++ ) { var settings = Mods.ModSettings[ modIndex ]; + var modName = settings.Mod.Meta.Name; + if (_modFilter.Length > 0 && !_modNamesLower[modIndex].Contains(_modFilter) ) + continue; var changedColour = false; if( !settings.Enabled ) @@ -189,11 +218,11 @@ namespace Penumbra.UI #if DEBUG var selected = ImGui.Selectable( - $"id={modIndex} {settings.Mod.Meta.Name}", + $"id={modIndex} {modName}", modIndex == _index ); #else - var selected = ImGui.Selectable( settings.Mod.Meta.Name, modIndex == _index ); + var selected = ImGui.Selectable( modName, modIndex == _index ); #endif if( changedColour ) @@ -266,6 +295,7 @@ namespace Penumbra.UI _mod.Mod.RefreshModFiles(); _base._plugin.ModManager.CalculateEffectiveFileList(); _base._menu._effectiveTab.RebuildFileList(_base._plugin.Configuration.ShowAdvanced); + ResetModNamesLower(); } public string SaveCurrentMod() diff --git a/Penumbra/Util/ArrayExtensions.cs b/Penumbra/Util/ArrayExtensions.cs new file mode 100644 index 00000000..2b9ea22a --- /dev/null +++ b/Penumbra/Util/ArrayExtensions.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace Penumbra +{ + public static class ArrayExtensions + { + public static void Swap( this T[] array, int idx1, int idx2 ) + { + var tmp = array[idx1]; + array[idx1] = array[idx2]; + array[idx2] = tmp; + } + + public static void Swap( this List array, int idx1, int idx2 ) + { + var tmp = array[idx1]; + array[idx1] = array[idx2]; + array[idx2] = tmp; + } + + public static void Swap( this T[] array, T lhs, T rhs ) + { + var idx1 = Array.IndexOf( array, lhs ); + if( idx1 < 0 ) + { + return; + } + + var idx2 = Array.IndexOf( array, rhs ); + if( idx2 < 0 ) + { + return; + } + + array.Swap( idx1, idx2 ); + } + + public static void Swap( this List array, T lhs, T rhs ) + { + var idx1 = array.IndexOf( lhs ); + if( idx1 < 0 ) + { + return; + } + + var idx2 = array.IndexOf( rhs ); + if( idx2 < 0 ) + { + return; + } + + array.Swap( idx1, idx2 ); + } + } +}