From 1eee89ab4c482f77ac29bbc809c9065c8d1f3b3b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 26 Jul 2021 17:45:01 +0200 Subject: [PATCH] Fix meta change counting and reloading on manual meta change edits. --- Penumbra/Meta/MetaCollection.cs | 10 ++++++++-- Penumbra/Mod/ModResources.cs | 4 ++-- Penumbra/Mods/ModManager.cs | 2 +- .../UI/MenuTabs/TabInstalled/TabInstalledDetails.cs | 7 ++++--- .../TabInstalledDetailsManipulations.cs | 13 ++++++++----- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Penumbra/Meta/MetaCollection.cs b/Penumbra/Meta/MetaCollection.cs index b8e42f7f..c6eb3b0e 100644 --- a/Penumbra/Meta/MetaCollection.cs +++ b/Penumbra/Meta/MetaCollection.cs @@ -22,8 +22,8 @@ namespace Penumbra.Meta // Store total number of manipulations for some ease of access. - [JsonProperty] - public int Count { get; private set; } = 0; + [JsonIgnore] + internal int Count = 0; // Return an enumeration of all active meta manipulations for a given mod with given settings. @@ -216,6 +216,12 @@ namespace Penumbra.Meta var collection = JsonConvert.DeserializeObject< MetaCollection >( text, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore } ); + if( collection != null ) + { + collection.Count = collection.DefaultData.Count + + collection.GroupData.Values.SelectMany( kvp => kvp.Values ).Sum( l => l.Count ); + } + return collection; } catch( Exception e ) diff --git a/Penumbra/Mod/ModResources.cs b/Penumbra/Mod/ModResources.cs index 947b4333..859a92a5 100644 --- a/Penumbra/Mod/ModResources.cs +++ b/Penumbra/Mod/ModResources.cs @@ -29,7 +29,7 @@ namespace Penumbra.Mod MetaManipulations.SaveToFile( MetaCollection.FileName( basePath ) ); } - public void SetManipulations( ModMeta meta, DirectoryInfo basePath ) + public void SetManipulations( ModMeta meta, DirectoryInfo basePath, bool validate = true ) { var newManipulations = MetaCollection.LoadFromFile( MetaCollection.FileName( basePath ) ); if( newManipulations == null ) @@ -39,7 +39,7 @@ namespace Penumbra.Mod else { MetaManipulations = newManipulations; - if( !MetaManipulations.Validate( meta ) ) + if( validate && !MetaManipulations.Validate( meta ) ) { ForceManipulationsUpdate( meta, basePath ); } diff --git a/Penumbra/Mods/ModManager.cs b/Penumbra/Mods/ModManager.cs index f2ac48d8..804345f2 100644 --- a/Penumbra/Mods/ModManager.cs +++ b/Penumbra/Mods/ModManager.cs @@ -163,7 +163,7 @@ namespace Penumbra.Mods var metaChanges = mod.Meta.RefreshFromFile( mod.MetaFile ); var fileChanges = mod.Resources.RefreshModFiles( mod.BasePath ); - if( !recomputeMeta && !metaChanges && fileChanges == 0 ) + if( !recomputeMeta && !reloadMeta && !metaChanges && fileChanges == 0 ) { return false; } diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs index 800a7ef9..0756c9f6 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs @@ -647,7 +647,7 @@ namespace Penumbra.UI private void DrawMetaManipulationsTab() { - if( Mod.Data.Resources.MetaManipulations.Count == 0 ) + if( !_editMode && Mod.Data.Resources.MetaManipulations.Count == 0 ) { return; } @@ -665,7 +665,7 @@ namespace Penumbra.UI { if( ImGui.CollapsingHeader( "Default" ) ) { - changes = DrawMetaManipulationsTable( "##DefaultManips", manips.DefaultData ); + changes = DrawMetaManipulationsTable( "##DefaultManips", manips.DefaultData, ref manips.Count ); } } @@ -675,7 +675,7 @@ namespace Penumbra.UI { if( ImGui.CollapsingHeader( $"{group.Key} - {option.Key}" ) ) { - changes |= DrawMetaManipulationsTable( $"##{group.Key}{option.Key}manips", option.Value ); + changes |= DrawMetaManipulationsTable( $"##{group.Key}{option.Key}manips", option.Value, ref manips.Count ); } } } @@ -683,6 +683,7 @@ namespace Penumbra.UI if( changes ) { Mod.Data.Resources.MetaManipulations.SaveToFile( MetaCollection.FileName( Mod.Data.BasePath ) ); + Mod.Data.Resources.SetManipulations( Meta, Mod.Data.BasePath, false ); _selector.ReloadCurrentMod( true, false ); } diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsManipulations.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsManipulations.cs index 5026cc1e..b4cdfa13 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsManipulations.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetailsManipulations.cs @@ -535,7 +535,7 @@ namespace Penumbra.UI return ret; } - private bool DrawManipulationRow( ref int manipIdx, IList< MetaManipulation > list ) + private bool DrawManipulationRow( ref int manipIdx, IList< MetaManipulation > list, ref int count ) { var type = list[ manipIdx ].Type; @@ -549,6 +549,7 @@ namespace Penumbra.UI ImGui.PopFont(); ImGui.TableNextRow(); --manipIdx; + --count; return true; } @@ -609,7 +610,7 @@ namespace Penumbra.UI return ( MetaType )_newManipTypeIdx; } - private bool DrawNewManipulationPopup( string popupName, IList< MetaManipulation > list ) + private bool DrawNewManipulationPopup( string popupName, IList< MetaManipulation > list, ref int count ) { var change = false; if( ImGui.BeginPopup( popupName ) ) @@ -714,7 +715,9 @@ namespace Penumbra.UI }; list.Add( manip ); change = true; + ++count; } + ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); @@ -723,7 +726,7 @@ namespace Penumbra.UI return change; } - private bool DrawMetaManipulationsTable( string label, IList< MetaManipulation > list ) + private bool DrawMetaManipulationsTable( string label, IList< MetaManipulation > list, ref int count ) { var numRows = _editMode ? 11 : 10; var changes = false; @@ -759,7 +762,7 @@ namespace Penumbra.UI for( var i = 0; i < list.Count; ++i ) { - changes |= DrawManipulationRow( ref i, list ); + changes |= DrawManipulationRow( ref i, list, ref count ); } ImGui.EndTable(); @@ -768,7 +771,7 @@ namespace Penumbra.UI var popupName = $"##newManip{label}"; if( _editMode ) { - changes |= DrawNewManipulationPopup( $"##newManip{label}", list ); + changes |= DrawNewManipulationPopup( $"##newManip{label}", list, ref count ); if( ImGui.Button( $"Add New Manipulation##{label}", Vector2.UnitX * -1 ) ) { ImGui.OpenPopup( popupName );