From 7a34bdabba5965abe6ef52a5c8772b2b26f7faaa Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 4 Jul 2021 20:05:10 +0200 Subject: [PATCH] Uncouple the currently manipulated collection from the default collection. --- Penumbra/Configuration.cs | 1 + Penumbra/Interop/ActorRefresher.cs | 2 +- Penumbra/MigrateConfiguration.cs | 1 + Penumbra/Mods/CollectionManager.cs | 39 +++++++++++++++++++++++--- Penumbra/UI/MenuTabs/TabCollections.cs | 37 ++++++++++++++++++++++-- 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 4a86a3d4..968fef36 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -25,6 +25,7 @@ namespace Penumbra public string ModDirectory { get; set; } = @"D:/ffxiv/fs_mods/"; public string CurrentCollection { get; set; } = "Default"; + public string DefaultCollection { get; set; } = "Default"; public string ForcedCollection { get; set; } = ""; public Dictionary< string, string > CharacterCollections { get; set; } = new(); public Dictionary< string, string > ModSortOrder { get; set; } = new(); diff --git a/Penumbra/Interop/ActorRefresher.cs b/Penumbra/Interop/ActorRefresher.cs index b7aed584..41fa5982 100644 --- a/Penumbra/Interop/ActorRefresher.cs +++ b/Penumbra/Interop/ActorRefresher.cs @@ -55,7 +55,7 @@ namespace Penumbra.Interop private void RestoreSettings() { - _mods.Collections.ActiveCollection = _mods.Collections.CurrentCollection; + _mods.Collections.ActiveCollection = _mods.Collections.DefaultCollection; _changedSettings = false; } diff --git a/Penumbra/MigrateConfiguration.cs b/Penumbra/MigrateConfiguration.cs index 61b3f283..7da6a9f1 100644 --- a/Penumbra/MigrateConfiguration.cs +++ b/Penumbra/MigrateConfiguration.cs @@ -21,6 +21,7 @@ namespace Penumbra config.ModDirectory = config.CurrentCollection; config.CurrentCollection = "Default"; + config.DefaultCollection = "Default"; config.Version = 1; ResettleCollectionJson( config ); } diff --git a/Penumbra/Mods/CollectionManager.cs b/Penumbra/Mods/CollectionManager.cs index a25bf124..629ef8ba 100644 --- a/Penumbra/Mods/CollectionManager.cs +++ b/Penumbra/Mods/CollectionManager.cs @@ -18,6 +18,7 @@ namespace Penumbra.Mods public Dictionary< string, ModCollection > Collections { get; } = new(); public ModCollection CurrentCollection { get; private set; } = null!; + public ModCollection DefaultCollection { get; private set; } = null!; public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty; public Dictionary< string, ModCollection > CharacterCollection { get; } = new(); @@ -30,7 +31,7 @@ namespace Penumbra.Mods ReadCollections(); LoadConfigCollections( _plugin.Configuration ); - ActiveCollection = CurrentCollection; + ActiveCollection = DefaultCollection; } public void RecreateCaches() @@ -77,7 +78,7 @@ namespace Penumbra.Mods if( recomputeMeta ) { - Service.Get().ReloadPlayerResources(); + Service< GameResourceManagement >.Get().ReloadPlayerResources(); } } @@ -117,6 +118,11 @@ namespace Penumbra.Mods SetForcedCollection( ModCollection.Empty ); } + if( DefaultCollection == collection ) + { + SetDefaultCollection( ModCollection.Empty ); + } + foreach( var kvp in CharacterCollection.ToArray() ) { if( kvp.Value == collection ) @@ -170,10 +176,10 @@ namespace Penumbra.Mods public void SetCurrentCollection( ModCollection newCollection ) => SetCollection( newCollection, CurrentCollection, c => { - if( ActiveCollection == CurrentCollection ) + if( ActiveCollection == DefaultCollection ) { ActiveCollection = c; - var resourceManager = Service.Get(); + var resourceManager = Service< GameResourceManagement >.Get(); resourceManager.ReloadPlayerResources(); } @@ -183,6 +189,9 @@ namespace Penumbra.Mods public void SetForcedCollection( ModCollection newCollection ) => SetCollection( newCollection, ForcedCollection, c => ForcedCollection = c, s => _plugin.Configuration.ForcedCollection = s ); + public void SetDefaultCollection( ModCollection newCollection ) + => SetCollection( newCollection, DefaultCollection, c => DefaultCollection = c, s => _plugin.Configuration.DefaultCollection = s ); + public void SetCharacterCollection( string characterName, ModCollection newCollection ) => SetCollection( newCollection, CharacterCollection.TryGetValue( characterName, out var oldCollection ) ? oldCollection : ModCollection.Empty, @@ -253,6 +262,27 @@ namespace Penumbra.Mods return true; } + private bool LoadDefaultCollection( Configuration config ) + { + if( config.DefaultCollection == string.Empty ) + { + DefaultCollection = ModCollection.Empty; + return false; + } + + if( Collections.TryGetValue( config.DefaultCollection, out var defaultCollection ) ) + { + DefaultCollection = defaultCollection; + AddCache( DefaultCollection ); + return false; + } + + PluginLog.Error( $"Last choice of DefaultCollection {config.DefaultCollection} is not available, reset to None." ); + DefaultCollection = ModCollection.Empty; + config.DefaultCollection = string.Empty; + return true; + } + private bool LoadCharacterCollections( Configuration config ) { var configChanged = false; @@ -283,6 +313,7 @@ namespace Penumbra.Mods private void LoadConfigCollections( Configuration config ) { var configChanged = LoadCurrentCollection( config ); + configChanged |= LoadDefaultCollection( config ); configChanged |= LoadForcedCollection( config ); configChanged |= LoadCharacterCollections( config ); diff --git a/Penumbra/UI/MenuTabs/TabCollections.cs b/Penumbra/UI/MenuTabs/TabCollections.cs index c2f9018a..a5b9436c 100644 --- a/Penumbra/UI/MenuTabs/TabCollections.cs +++ b/Penumbra/UI/MenuTabs/TabCollections.cs @@ -23,6 +23,7 @@ namespace Penumbra.UI private ModCollection[] _collections = null!; private int _currentCollectionIndex = 0; private int _currentForcedIndex = 0; + private int _currentDefaultIndex = 0; private readonly Dictionary< string, int > _currentCharacterIndices = new(); private string _newCollectionName = string.Empty; private string _newCharacterName = string.Empty; @@ -54,6 +55,9 @@ namespace Penumbra.UI private void UpdateForcedIndex() => _currentForcedIndex = GetIndex( _manager.Collections.ForcedCollection ); + private void UpdateDefaultIndex() + => _currentDefaultIndex = GetIndex( _manager.Collections.DefaultCollection ); + private void UpdateCharacterIndices() { _currentCharacterIndices.Clear(); @@ -66,6 +70,7 @@ namespace Penumbra.UI private void UpdateIndices() { UpdateIndex(); + UpdateDefaultIndex(); UpdateForcedIndex(); UpdateCharacterIndices(); } @@ -130,12 +135,14 @@ namespace Penumbra.UI private void DrawCurrentCollectionSelector() { var index = _currentCollectionIndex; - if( !ImGui.Combo( "Current Collection", ref index, _collectionNames ) ) + var combo = ImGui.Combo( "Current Collection", ref index, _collectionNames ); + if( ImGui.IsItemHovered() ) { - return; + ImGui.SetTooltip( + "This collection will be modified when using the Installed Mods tab and making changes. It does not apply to anything by itself." ); } - if( index != _currentCollectionIndex ) + if( combo && index != _currentCollectionIndex ) { _manager.Collections.SetCurrentCollection( _collections[ index + 1 ] ); _currentCollectionIndex = index; @@ -143,6 +150,28 @@ namespace Penumbra.UI } } + private void DrawDefaultCollectionSelector() + { + var index = _currentDefaultIndex; + if( ImGui.Combo( "##Default Collection", ref index, _collectionNamesWithNone ) && index != _currentDefaultIndex ) + { + _manager.Collections.SetDefaultCollection( _collections[ index ] ); + _currentDefaultIndex = index; + } + + if( ImGui.IsItemHovered() ) + { + ImGui.SetTooltip( + "Mods in the default collection are loaded for any character that is not explicitly named in the character collections below.\n" + + "They also take precedence before the forced collection." ); + } + + ImGui.SameLine(); + ImGui.Dummy( new Vector2( 24, 0 ) ); + ImGui.SameLine(); + ImGui.Text( "Default Collection" ); + } + private void DrawForcedCollectionSelector() { var index = _currentForcedIndex; @@ -181,6 +210,7 @@ namespace Penumbra.UI { _manager.Collections.CreateCharacterCollection( _newCharacterName ); _currentCharacterIndices[ _newCharacterName ] = 0; + _newCharacterName = string.Empty; } if( changedStyle ) @@ -197,6 +227,7 @@ namespace Penumbra.UI return; } + DrawDefaultCollectionSelector(); DrawForcedCollectionSelector(); foreach( var name in _manager.Collections.CharacterCollection.Keys.ToArray() )