Update ModSelector to reselect a mod on update instead of directly in most cases.

This commit is contained in:
Ottermandias 2021-08-19 11:15:09 +02:00
parent 238a4b0cef
commit 9d51b3d6f1
5 changed files with 22 additions and 16 deletions

View file

@ -144,7 +144,7 @@ namespace Penumbra.UI
_selector.Cache.TriggerListReset(); _selector.Cache.TriggerListReset();
if( _selector.Mod != null ) if( _selector.Mod != null )
{ {
_selector.SelectModByDir( _selector.Mod.Data.BasePath.Name ); _selector.SelectModOnUpdate( _selector.Mod.Data.BasePath.Name );
} }
} }

View file

@ -87,7 +87,7 @@ namespace Penumbra.UI
_base.ReloadMods(); _base.ReloadMods();
if( directory != null ) if( directory != null )
{ {
_base._menu.InstalledTab.Selector.SelectModByDir( directory.Name ); _base._menu.InstalledTab.Selector.SelectModOnUpdate( directory.Name );
} }
} }
} }

View file

@ -215,7 +215,7 @@ namespace Penumbra.UI
var mod = kv.Key; var mod = kv.Key;
if( ImGui.Selectable( mod.Data.Meta.Name ) ) if( ImGui.Selectable( mod.Data.Meta.Name ) )
{ {
_selector.SelectModByName( mod.Data.Meta.Name ); _selector.SelectModByDir( mod.Data.BasePath.Name );
} }
ImGui.SameLine(); ImGui.SameLine();

View file

@ -74,7 +74,7 @@ namespace Penumbra.UI
var name = Meta!.Name; var name = Meta!.Name;
if( Custom.ImGuiCustom.InputOrText( _editMode, LabelEditName, ref name, 64 ) && _modManager.RenameMod( name, Mod!.Data ) ) if( Custom.ImGuiCustom.InputOrText( _editMode, LabelEditName, ref name, 64 ) && _modManager.RenameMod( name, Mod!.Data ) )
{ {
_selector.SelectModByDir( Mod.Data.BasePath.Name ); _selector.SelectModOnUpdate( Mod.Data.BasePath.Name );
if( !_modManager.Config.ModSortOrder.ContainsKey( Mod!.Data.BasePath.Name ) ) if( !_modManager.Config.ModSortOrder.ContainsKey( Mod!.Data.BasePath.Name ) )
{ {
Mod.Data.Rename( name ); Mod.Data.Rename( name );
@ -233,7 +233,7 @@ namespace Penumbra.UI
if( ImGui.InputText( "Sort Order", ref currentSortOrder, 256, ImGuiInputTextFlags.EnterReturnsTrue ) ) if( ImGui.InputText( "Sort Order", ref currentSortOrder, 256, ImGuiInputTextFlags.EnterReturnsTrue ) )
{ {
manager.ChangeSortOrder( mod, currentSortOrder ); manager.ChangeSortOrder( mod, currentSortOrder );
selector.SelectModByDir( mod.BasePath.Name ); selector.SelectModOnUpdate( mod.BasePath.Name );
return true; return true;
} }
@ -331,7 +331,7 @@ namespace Penumbra.UI
{ {
Service< ModManager >.Get()!.RenameModFolder( Mod.Data, newDir, false ); Service< ModManager >.Get()!.RenameModFolder( Mod.Data, newDir, false );
_selector.SelectModByDir( _newName ); _selector.SelectModOnUpdate( _newName );
closeParent = true; closeParent = true;
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();

View file

@ -168,7 +168,7 @@ namespace Penumbra.UI
modMeta.SaveToFile( metaFile ); modMeta.SaveToFile( metaFile );
_modManager.AddMod( newDir ); _modManager.AddMod( newDir );
ModFileSystem.InvokeChange(); ModFileSystem.InvokeChange();
SelectModByDir( newDir.Name ); SelectModOnUpdate( newDir.Name );
} }
catch( Exception e ) catch( Exception e )
{ {
@ -421,7 +421,8 @@ namespace Penumbra.UI
private partial class Selector private partial class Selector
{ {
public Mod.Mod? Mod { get; private set; } public Mod.Mod? Mod { get; private set; }
private int _index; private int _index;
private string _nextDir = string.Empty;
private void SetSelection( int idx, Mod.Mod? info ) private void SetSelection( int idx, Mod.Mod? info )
{ {
@ -458,11 +459,8 @@ namespace Penumbra.UI
public void ClearSelection() public void ClearSelection()
=> SetSelection( -1 ); => SetSelection( -1 );
public void SelectModByName( string name ) public void SelectModOnUpdate( string directory )
{ => _nextDir = directory;
var (mod, idx) = Cache.GetModByName( name );
SetSelection( idx, mod );
}
public void SelectModByDir( string name ) public void SelectModByDir( string name )
{ {
@ -479,7 +477,7 @@ namespace Penumbra.UI
if( _index >= 0 && _modManager.UpdateMod( Mod.Data, reloadMeta, recomputeMeta ) ) if( _index >= 0 && _modManager.UpdateMod( Mod.Data, reloadMeta, recomputeMeta ) )
{ {
SelectModByDir( Mod.Data.BasePath.Name ); SelectModOnUpdate( Mod.Data.BasePath.Name );
_base._menu.InstalledTab.ModPanel.Details.ResetState(); _base._menu.InstalledTab.ModPanel.Details.ResetState();
} }
} }
@ -744,9 +742,17 @@ namespace Penumbra.UI
public void Draw() public void Draw()
{ {
if( Cache.Update() && Mod != null ) if( Cache.Update() )
{ {
SelectModByDir( Mod.Data.BasePath.Name ); if( _nextDir.Any() )
{
SelectModByDir( _nextDir );
_nextDir = string.Empty;
}
else if( Mod != null )
{
SelectModByDir( Mod.Data.BasePath.Name );
}
} }
try try