Small fixes.

This commit is contained in:
Ottermandias 2022-02-03 23:53:27 +01:00
parent a62fa06b03
commit 09c92ef0b1
3 changed files with 120 additions and 109 deletions

View file

@ -1,3 +1,4 @@
using System;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Logging; using Dalamud.Logging;
using Dalamud.Plugin; using Dalamud.Plugin;
@ -38,7 +39,6 @@ public class Penumbra : IDalamudPlugin
private WebServer? _webServer; private WebServer? _webServer;
private readonly ModManager _modManager; private readonly ModManager _modManager;
private readonly ModCollection[] _collections;
public Penumbra( DalamudPluginInterface pluginInterface ) public Penumbra( DalamudPluginInterface pluginInterface )
{ {
@ -95,8 +95,6 @@ public class Penumbra : IDalamudPlugin
PluginLog.Debug( "Triggered Redraw of {Player}.", p.Name ); PluginLog.Debug( "Triggered Redraw of {Player}.", p.Name );
ObjectReloader.RedrawObject( p, RedrawType.OnlyWithSettings ); ObjectReloader.RedrawObject( p, RedrawType.OnlyWithSettings );
}; };
_collections = _modManager.Collections.Collections.Values.ToArray();
} }
public bool Enable() public bool Enable()
@ -171,7 +169,7 @@ public class Penumbra : IDalamudPlugin
.WithWebApi( "/api", m => m .WithWebApi( "/api", m => m
.WithController( () => new ModsController( this ) ) ); .WithController( () => new ModsController( this ) ) );
_webServer.StateChanged += ( s, e ) => PluginLog.Information( $"WebServer New State - {e.NewState}" ); _webServer.StateChanged += ( _, e ) => PluginLog.Information( $"WebServer New State - {e.NewState}" );
_webServer.RunAsync(); _webServer.RunAsync();
} }
@ -197,45 +195,50 @@ public class Penumbra : IDalamudPlugin
ShutdownWebServer(); ShutdownWebServer();
} }
public bool SetCollection(string type, string collection) public bool SetCollection( string type, string collectionName )
{ {
type = type.ToLower(); type = type.ToLowerInvariant();
collection = collection.ToLower(); collectionName = collectionName.ToLowerInvariant();
if( type != "default" && type != "forced" ) var collection = string.Equals( collectionName, ModCollection.Empty.Name, StringComparison.InvariantCultureIgnoreCase )
{ ? ModCollection.Empty
Dalamud.Chat.Print( "Second command argument is not default or forced, the correct command format is: /penumbra collection {default|forced} <collectionName>" ); : _modManager.Collections.Collections.Values.FirstOrDefault( c
return false; => string.Equals( c.Name, collectionName, StringComparison.InvariantCultureIgnoreCase ) );
} if( collection == null )
var currentCollection = ( type == "default" ) ? _modManager.Collections.DefaultCollection : _modManager.Collections.ForcedCollection;
if( collection == currentCollection.Name.ToLower() )
{
Dalamud.Chat.Print( $"{currentCollection.Name} is already the active collection." );
return false;
}
var newCollection = ( collection == "none" ) ? ModCollection.Empty : _collections.FirstOrDefault( c => c.Name.ToLower() == collection );
if ( newCollection == null )
{ {
Dalamud.Chat.Print( $"The collection {collection} does not exist." ); Dalamud.Chat.Print( $"The collection {collection} does not exist." );
return false; return false;
} }
if( type == "default" ) switch( type )
{ {
_modManager.Collections.SetDefaultCollection( newCollection ); case "default":
Dalamud.Chat.Print( $"Set { newCollection.Name } as default collection." ); if( collection == _modManager.Collections.DefaultCollection )
} {
else if ( type == "forced" ) Dalamud.Chat.Print( $"{collection.Name} already is the default collection." );
{ return false;
_modManager.Collections.SetForcedCollection( newCollection ); }
Dalamud.Chat.Print( $"Set { newCollection.Name } as forced collection." );
}
return true; _modManager.Collections.SetDefaultCollection( collection );
Dalamud.Chat.Print( $"Set {collection.Name} as default collection." );
SettingsInterface.ResetDefaultCollection();
return true;
case "forced":
if( collection == _modManager.Collections.ForcedCollection )
{
Dalamud.Chat.Print( $"{collection.Name} already is the forced collection." );
return false;
}
_modManager.Collections.SetForcedCollection( collection );
Dalamud.Chat.Print( $"Set {collection.Name} as forced collection." );
SettingsInterface.ResetForcedCollection();
return true;
default:
Dalamud.Chat.Print(
"Second command argument is not default or forced, the correct command format is: /penumbra collection {default|forced} <collectionName>" );
return false;
}
} }
private void OnCommand( string command, string rawArgs ) private void OnCommand( string command, string rawArgs )
@ -252,7 +255,7 @@ public class Penumbra : IDalamudPlugin
{ {
Service< ModManager >.Get().DiscoverMods(); Service< ModManager >.Get().DiscoverMods();
Dalamud.Chat.Print( Dalamud.Chat.Print(
$"Reloaded Penumbra mods. You have {Service< ModManager >.Get()?.Mods.Count} mods." $"Reloaded Penumbra mods. You have {_modManager.Mods.Count} mods."
); );
break; break;
} }
@ -300,11 +303,14 @@ public class Penumbra : IDalamudPlugin
{ {
if( args.Length == 3 ) if( args.Length == 3 )
{ {
SetCollection(args[ 1 ], args[ 2 ]); SetCollection( args[ 1 ], args[ 2 ] );
} else
{
Dalamud.Chat.Print( "Missing arguments, the correct command format is: /penumbra collection {default|forced} <collectionName>" );
} }
else
{
Dalamud.Chat.Print( "Missing arguments, the correct command format is:"
+ " /penumbra collection {default|forced} <collectionName>" );
}
break; break;
} }
} }

View file

@ -54,10 +54,10 @@ public partial class SettingsInterface
private void UpdateIndex() private void UpdateIndex()
=> _currentCollectionIndex = GetIndex( _manager.Collections.CurrentCollection ) - 1; => _currentCollectionIndex = GetIndex( _manager.Collections.CurrentCollection ) - 1;
private void UpdateForcedIndex() public void UpdateForcedIndex()
=> _currentForcedIndex = GetIndex( _manager.Collections.ForcedCollection ); => _currentForcedIndex = GetIndex( _manager.Collections.ForcedCollection );
private void UpdateDefaultIndex() public void UpdateDefaultIndex()
=> _currentDefaultIndex = GetIndex( _manager.Collections.DefaultCollection ); => _currentDefaultIndex = GetIndex( _manager.Collections.DefaultCollection );
private void UpdateCharacterIndices() private void UpdateCharacterIndices()

View file

@ -3,81 +3,86 @@ using System.Numerics;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.Util; using Penumbra.Util;
namespace Penumbra.UI namespace Penumbra.UI;
public partial class SettingsInterface : IDisposable
{ {
public partial class SettingsInterface : IDisposable private const float DefaultVerticalSpace = 20f;
private static readonly Vector2 AutoFillSize = new(-1, -1);
private static readonly Vector2 ZeroVector = new(0, 0);
private readonly Penumbra _penumbra;
private readonly ManageModsButton _manageModsButton;
private readonly MenuBar _menuBar;
private readonly SettingsMenu _menu;
private readonly ModManager _modManager;
public SettingsInterface( Penumbra penumbra )
{ {
private const float DefaultVerticalSpace = 20f; _penumbra = penumbra;
_manageModsButton = new ManageModsButton( this );
_menuBar = new MenuBar( this );
_menu = new SettingsMenu( this );
_modManager = Service< ModManager >.Get();
private static readonly Vector2 AutoFillSize = new( -1, -1 ); Dalamud.PluginInterface.UiBuilder.DisableGposeUiHide = true;
private static readonly Vector2 ZeroVector = new( 0, 0 ); Dalamud.PluginInterface.UiBuilder.Draw += Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi += OpenConfig;
}
private readonly Penumbra _penumbra; public void Dispose()
{
_manageModsButton.Dispose();
_menu.InstalledTab.Selector.Cache.Dispose();
Dalamud.PluginInterface.UiBuilder.Draw -= Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= OpenConfig;
}
private readonly ManageModsButton _manageModsButton; private void OpenConfig()
private readonly MenuBar _menuBar; => _menu.Visible = true;
private readonly SettingsMenu _menu;
private readonly ModManager _modManager;
public SettingsInterface( Penumbra penumbra ) public void FlipVisibility()
=> _menu.Visible = !_menu.Visible;
public void MakeDebugTabVisible()
=> _menu.DebugTabVisible = true;
public void Draw()
{
_menuBar.Draw();
_menu.Draw();
}
private void ReloadMods()
{
_menu.InstalledTab.Selector.ClearSelection();
_modManager.DiscoverMods( Penumbra.Config.ModDirectory );
_menu.InstalledTab.Selector.Cache.TriggerListReset();
}
private void SaveCurrentCollection( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
current.Save();
RecalculateCurrent( recalculateMeta );
}
private void RecalculateCurrent( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
if( current.Cache != null )
{ {
_penumbra = penumbra; current.CalculateEffectiveFileList( _modManager.TempPath, recalculateMeta,
_manageModsButton = new ManageModsButton( this ); current == _modManager.Collections.ActiveCollection );
_menuBar = new MenuBar( this ); _menu.InstalledTab.Selector.Cache.TriggerFilterReset();
_menu = new SettingsMenu( this );
_modManager = Service< ModManager >.Get();
Dalamud.PluginInterface.UiBuilder.DisableGposeUiHide = true;
Dalamud.PluginInterface.UiBuilder.Draw += Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi += OpenConfig;
}
public void Dispose()
{
_manageModsButton.Dispose();
_menu.InstalledTab.Selector.Cache.Dispose();
Dalamud.PluginInterface.UiBuilder.Draw -= Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= OpenConfig;
}
private void OpenConfig()
=> _menu.Visible = true;
public void FlipVisibility()
=> _menu.Visible = !_menu.Visible;
public void MakeDebugTabVisible()
=> _menu.DebugTabVisible = true;
public void Draw()
{
_menuBar.Draw();
_menu.Draw();
}
private void ReloadMods()
{
_menu.InstalledTab.Selector.ClearSelection();
_modManager.DiscoverMods( Penumbra.Config.ModDirectory );
_menu.InstalledTab.Selector.Cache.TriggerListReset();
}
private void SaveCurrentCollection( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
current.Save();
RecalculateCurrent( recalculateMeta );
}
private void RecalculateCurrent( bool recalculateMeta )
{
var current = _modManager.Collections.CurrentCollection;
if( current.Cache != null )
{
current.CalculateEffectiveFileList( _modManager.TempPath, recalculateMeta,
current == _modManager.Collections.ActiveCollection );
_menu.InstalledTab.Selector.Cache.TriggerFilterReset();
}
} }
} }
public void ResetDefaultCollection()
=> _menu.CollectionsTab.UpdateDefaultIndex();
public void ResetForcedCollection()
=> _menu.CollectionsTab.UpdateForcedIndex();
} }