From d7fda7cf1b685fbb88afbb2649df203d185f297f Mon Sep 17 00:00:00 2001 From: Adam <893184+NotAdam@users.noreply.github.com> Date: Sat, 26 Dec 2020 14:47:36 +1100 Subject: [PATCH] fix a bug where priorities weren't fixed after deleting mods --- Penumbra/Mods/ModCollection.cs | 10 +++++++ Penumbra/Plugin.cs | 26 +++++++++++++----- Penumbra/UI/SettingsInterface.cs | 45 +++++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/Penumbra/Mods/ModCollection.cs b/Penumbra/Mods/ModCollection.cs index 75dbcd26..f988508c 100644 --- a/Penumbra/Mods/ModCollection.cs +++ b/Penumbra/Mods/ModCollection.cs @@ -84,6 +84,14 @@ namespace Penumbra.Mods ) ).ToList(); + // if anything gets removed above, the priority ordering gets fucked, so we need to resort and reindex them otherwise BAD THINGS HAPPEN + ModSettings = ModSettings.OrderBy( x => x.Priority ).ToList(); + var p = 0; + foreach( var modSetting in ModSettings ) + { + modSetting.Priority = p++; + } + // reorder the resourcemods list so we can just directly iterate EnabledMods = GetOrderedAndEnabledModList().ToArray(); @@ -129,6 +137,8 @@ namespace Penumbra.Mods // save new prios Save(); } + + public ModInfo FindModSettings( string name ) { diff --git a/Penumbra/Plugin.cs b/Penumbra/Plugin.cs index f4f3bc17..3b6647b5 100644 --- a/Penumbra/Plugin.cs +++ b/Penumbra/Plugin.cs @@ -43,7 +43,7 @@ namespace Penumbra PluginInterface.CommandManager.AddHandler( CommandName, new CommandInfo( OnCommand ) { - HelpMessage = "/penumbra 0 will disable penumbra, /penumbra 1 will enable it." + HelpMessage = "/penumbra - toggle ui\n/penumbra reload - reload mod file lists & discover any new mods" } ); ResourceLoader.Init(); @@ -65,15 +65,27 @@ namespace Penumbra ResourceLoader.Dispose(); } - private void OnCommand( string command, string args ) + private void OnCommand( string command, string rawArgs ) { + var args = rawArgs.Split( ' ' ); if( args.Length > 0 ) - Configuration.IsEnabled = args[ 0 ] == '1'; + { + switch( args[ 0 ] ) + { + case "reload": + { + ModManager.DiscoverMods(); + PluginInterface.Framework.Gui.Chat.Print( + $"Reloaded Penumbra mods. You have {ModManager.Mods.ModSettings.Count} mods, {ModManager.Mods.EnabledMods.Length} of which are enabled." + ); + break; + } + } - if( Configuration.IsEnabled ) - ResourceLoader.Enable(); - else - ResourceLoader.Disable(); + return; + } + + SettingsInterface.Visible = !SettingsInterface.Visible; } } } \ No newline at end of file diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index a89add44..21daedb2 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -18,6 +18,7 @@ namespace Penumbra.UI private readonly Plugin _plugin; public bool Visible = false; + public bool ShowDebugBar = false; private static readonly Vector2 AutoFillSize = new Vector2( -1, -1 ); private static readonly Vector2 ModListSize = new Vector2( 200, -1 ); @@ -36,10 +37,46 @@ namespace Penumbra.UI public SettingsInterface( Plugin plugin ) { _plugin = plugin; +#if DEBUG + Visible = true; + ShowDebugBar = true; +#endif } public void Draw() { + if( ShowDebugBar && ImGui.BeginMainMenuBar() ) + { + if( ImGui.BeginMenu( "Penumbra" ) ) + { + if( ImGui.MenuItem( "Toggle UI", "/penumbra", Visible ) ) + { + Visible = !Visible; + } + + if( ImGui.MenuItem( "Rediscover Mods" ) ) + { + ReloadMods(); + } + +// ImGui.Separator(); +// #if DEBUG +// ImGui.Text( _plugin.PluginDebugTitleStr ); +// #else +// ImGui.Text( _plugin.Name ); +// #endif + + ImGui.EndMenu(); + } + + ImGui.EndMainMenuBar(); + } + + if( !Visible ) + { + return; + } + ImGui.SetNextWindowSizeConstraints( MinSettingsSize, MaxSettingsSize ); #if DEBUG var ret = ImGui.Begin( _plugin.PluginDebugTitleStr, ref Visible ); @@ -94,7 +131,7 @@ namespace Penumbra.UI { Process.Start( _plugin.Configuration.CurrentCollection ); } - + ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 15 ); #if DEBUG @@ -105,12 +142,12 @@ namespace Penumbra.UI { _plugin.ResourceLoader.ReloadPlayerResource(); } - + if( _plugin.ResourceLoader != null ) { ImGui.Checkbox( "DEBUG Log all loaded files", ref _plugin.ResourceLoader.LogAllFiles ); } - + ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 15 ); #endif @@ -164,7 +201,7 @@ namespace Penumbra.UI { ImGui.Button( "Import in progress..." ); } - + ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 15 ); if( ImGui.Button( "Save Settings" ) )