Uncouple the currently manipulated collection from the default collection.

This commit is contained in:
Ottermandias 2021-07-04 20:05:10 +02:00
parent 2ff98f2338
commit 7a34bdabba
5 changed files with 72 additions and 8 deletions

View file

@ -25,6 +25,7 @@ namespace Penumbra
public string ModDirectory { get; set; } = @"D:/ffxiv/fs_mods/"; public string ModDirectory { get; set; } = @"D:/ffxiv/fs_mods/";
public string CurrentCollection { get; set; } = "Default"; public string CurrentCollection { get; set; } = "Default";
public string DefaultCollection { get; set; } = "Default";
public string ForcedCollection { get; set; } = ""; public string ForcedCollection { get; set; } = "";
public Dictionary< string, string > CharacterCollections { get; set; } = new(); public Dictionary< string, string > CharacterCollections { get; set; } = new();
public Dictionary< string, string > ModSortOrder { get; set; } = new(); public Dictionary< string, string > ModSortOrder { get; set; } = new();

View file

@ -55,7 +55,7 @@ namespace Penumbra.Interop
private void RestoreSettings() private void RestoreSettings()
{ {
_mods.Collections.ActiveCollection = _mods.Collections.CurrentCollection; _mods.Collections.ActiveCollection = _mods.Collections.DefaultCollection;
_changedSettings = false; _changedSettings = false;
} }

View file

@ -21,6 +21,7 @@ namespace Penumbra
config.ModDirectory = config.CurrentCollection; config.ModDirectory = config.CurrentCollection;
config.CurrentCollection = "Default"; config.CurrentCollection = "Default";
config.DefaultCollection = "Default";
config.Version = 1; config.Version = 1;
ResettleCollectionJson( config ); ResettleCollectionJson( config );
} }

View file

@ -18,6 +18,7 @@ namespace Penumbra.Mods
public Dictionary< string, ModCollection > Collections { get; } = new(); public Dictionary< string, ModCollection > Collections { get; } = new();
public ModCollection CurrentCollection { get; private set; } = null!; public ModCollection CurrentCollection { get; private set; } = null!;
public ModCollection DefaultCollection { get; private set; } = null!;
public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty; public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty;
public Dictionary< string, ModCollection > CharacterCollection { get; } = new(); public Dictionary< string, ModCollection > CharacterCollection { get; } = new();
@ -30,7 +31,7 @@ namespace Penumbra.Mods
ReadCollections(); ReadCollections();
LoadConfigCollections( _plugin.Configuration ); LoadConfigCollections( _plugin.Configuration );
ActiveCollection = CurrentCollection; ActiveCollection = DefaultCollection;
} }
public void RecreateCaches() public void RecreateCaches()
@ -77,7 +78,7 @@ namespace Penumbra.Mods
if( recomputeMeta ) if( recomputeMeta )
{ {
Service<GameResourceManagement>.Get().ReloadPlayerResources(); Service< GameResourceManagement >.Get().ReloadPlayerResources();
} }
} }
@ -117,6 +118,11 @@ namespace Penumbra.Mods
SetForcedCollection( ModCollection.Empty ); SetForcedCollection( ModCollection.Empty );
} }
if( DefaultCollection == collection )
{
SetDefaultCollection( ModCollection.Empty );
}
foreach( var kvp in CharacterCollection.ToArray() ) foreach( var kvp in CharacterCollection.ToArray() )
{ {
if( kvp.Value == collection ) if( kvp.Value == collection )
@ -170,10 +176,10 @@ namespace Penumbra.Mods
public void SetCurrentCollection( ModCollection newCollection ) public void SetCurrentCollection( ModCollection newCollection )
=> SetCollection( newCollection, CurrentCollection, c => => SetCollection( newCollection, CurrentCollection, c =>
{ {
if( ActiveCollection == CurrentCollection ) if( ActiveCollection == DefaultCollection )
{ {
ActiveCollection = c; ActiveCollection = c;
var resourceManager = Service<GameResourceManagement>.Get(); var resourceManager = Service< GameResourceManagement >.Get();
resourceManager.ReloadPlayerResources(); resourceManager.ReloadPlayerResources();
} }
@ -183,6 +189,9 @@ namespace Penumbra.Mods
public void SetForcedCollection( ModCollection newCollection ) public void SetForcedCollection( ModCollection newCollection )
=> SetCollection( newCollection, ForcedCollection, c => ForcedCollection = c, s => _plugin.Configuration.ForcedCollection = s ); => 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 ) public void SetCharacterCollection( string characterName, ModCollection newCollection )
=> SetCollection( newCollection, => SetCollection( newCollection,
CharacterCollection.TryGetValue( characterName, out var oldCollection ) ? oldCollection : ModCollection.Empty, CharacterCollection.TryGetValue( characterName, out var oldCollection ) ? oldCollection : ModCollection.Empty,
@ -253,6 +262,27 @@ namespace Penumbra.Mods
return true; 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 ) private bool LoadCharacterCollections( Configuration config )
{ {
var configChanged = false; var configChanged = false;
@ -283,6 +313,7 @@ namespace Penumbra.Mods
private void LoadConfigCollections( Configuration config ) private void LoadConfigCollections( Configuration config )
{ {
var configChanged = LoadCurrentCollection( config ); var configChanged = LoadCurrentCollection( config );
configChanged |= LoadDefaultCollection( config );
configChanged |= LoadForcedCollection( config ); configChanged |= LoadForcedCollection( config );
configChanged |= LoadCharacterCollections( config ); configChanged |= LoadCharacterCollections( config );

View file

@ -23,6 +23,7 @@ namespace Penumbra.UI
private ModCollection[] _collections = null!; private ModCollection[] _collections = null!;
private int _currentCollectionIndex = 0; private int _currentCollectionIndex = 0;
private int _currentForcedIndex = 0; private int _currentForcedIndex = 0;
private int _currentDefaultIndex = 0;
private readonly Dictionary< string, int > _currentCharacterIndices = new(); private readonly Dictionary< string, int > _currentCharacterIndices = new();
private string _newCollectionName = string.Empty; private string _newCollectionName = string.Empty;
private string _newCharacterName = string.Empty; private string _newCharacterName = string.Empty;
@ -54,6 +55,9 @@ namespace Penumbra.UI
private void UpdateForcedIndex() private void UpdateForcedIndex()
=> _currentForcedIndex = GetIndex( _manager.Collections.ForcedCollection ); => _currentForcedIndex = GetIndex( _manager.Collections.ForcedCollection );
private void UpdateDefaultIndex()
=> _currentDefaultIndex = GetIndex( _manager.Collections.DefaultCollection );
private void UpdateCharacterIndices() private void UpdateCharacterIndices()
{ {
_currentCharacterIndices.Clear(); _currentCharacterIndices.Clear();
@ -66,6 +70,7 @@ namespace Penumbra.UI
private void UpdateIndices() private void UpdateIndices()
{ {
UpdateIndex(); UpdateIndex();
UpdateDefaultIndex();
UpdateForcedIndex(); UpdateForcedIndex();
UpdateCharacterIndices(); UpdateCharacterIndices();
} }
@ -130,12 +135,14 @@ namespace Penumbra.UI
private void DrawCurrentCollectionSelector() private void DrawCurrentCollectionSelector()
{ {
var index = _currentCollectionIndex; 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 ] ); _manager.Collections.SetCurrentCollection( _collections[ index + 1 ] );
_currentCollectionIndex = index; _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() private void DrawForcedCollectionSelector()
{ {
var index = _currentForcedIndex; var index = _currentForcedIndex;
@ -181,6 +210,7 @@ namespace Penumbra.UI
{ {
_manager.Collections.CreateCharacterCollection( _newCharacterName ); _manager.Collections.CreateCharacterCollection( _newCharacterName );
_currentCharacterIndices[ _newCharacterName ] = 0; _currentCharacterIndices[ _newCharacterName ] = 0;
_newCharacterName = string.Empty;
} }
if( changedStyle ) if( changedStyle )
@ -197,6 +227,7 @@ namespace Penumbra.UI
return; return;
} }
DrawDefaultCollectionSelector();
DrawForcedCollectionSelector(); DrawForcedCollectionSelector();
foreach( var name in _manager.Collections.CharacterCollection.Keys.ToArray() ) foreach( var name in _manager.Collections.CharacterCollection.Keys.ToArray() )