From f8331bc4d818454e48f225257668f20e1c411b75 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 24 Dec 2023 14:36:21 +0100 Subject: [PATCH] Fix the mod panels header not resetting data when a selected mod updates. --- Penumbra/Communication/ModDataChanged.cs | 5 +++- Penumbra/Mods/Manager/ModFileSystem.cs | 6 ++--- .../UI/AdvancedWindow/ModEditWindow.Models.cs | 3 +-- Penumbra/UI/ModsTab/ModPanel.cs | 5 ++-- Penumbra/UI/ModsTab/ModPanelHeader.cs | 23 +++++++++++++++++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Penumbra/Communication/ModDataChanged.cs b/Penumbra/Communication/ModDataChanged.cs index 9ec60aa3..2f50f005 100644 --- a/Penumbra/Communication/ModDataChanged.cs +++ b/Penumbra/Communication/ModDataChanged.cs @@ -21,8 +21,11 @@ public sealed class ModDataChanged : EventWrapper ModCacheManager = 0, - /// + /// ModFileSystem = 0, + + /// + ModPanelHeader = 0, } public ModDataChanged() diff --git a/Penumbra/Mods/Manager/ModFileSystem.cs b/Penumbra/Mods/Manager/ModFileSystem.cs index 1851399d..c8a0a5db 100644 --- a/Penumbra/Mods/Manager/ModFileSystem.cs +++ b/Penumbra/Mods/Manager/ModFileSystem.cs @@ -21,7 +21,7 @@ public sealed class ModFileSystem : FileSystem, IDisposable, ISavable Reload(); Changed += OnChange; _communicator.ModDiscoveryFinished.Subscribe(Reload, ModDiscoveryFinished.Priority.ModFileSystem); - _communicator.ModDataChanged.Subscribe(OnDataChange, ModDataChanged.Priority.ModFileSystem); + _communicator.ModDataChanged.Subscribe(OnModDataChange, ModDataChanged.Priority.ModFileSystem); _communicator.ModPathChanged.Subscribe(OnModPathChange, ModPathChanged.Priority.ModFileSystem); } @@ -29,7 +29,7 @@ public sealed class ModFileSystem : FileSystem, IDisposable, ISavable { _communicator.ModPathChanged.Unsubscribe(OnModPathChange); _communicator.ModDiscoveryFinished.Unsubscribe(Reload); - _communicator.ModDataChanged.Unsubscribe(OnDataChange); + _communicator.ModDataChanged.Unsubscribe(OnModDataChange); } public struct ImportDate : ISortMode @@ -75,7 +75,7 @@ public sealed class ModFileSystem : FileSystem, IDisposable, ISavable } // Update sort order when defaulted mod names change. - private void OnDataChange(ModDataChangeType type, Mod mod, string? oldName) + private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName) { if (!type.HasFlag(ModDataChangeType.Name) || oldName == null || !FindLeaf(mod, out var leaf)) return; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs index 25bb012a..e4646d07 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs @@ -155,7 +155,6 @@ public partial class ModEditWindow var file = tab.Mdl; var mesh = file.Meshes[meshIndex]; - // Mesh material ImGui.TableNextColumn(); ImGui.AlignTextToFramePadding(); @@ -171,7 +170,7 @@ public partial class ModEditWindow return ret; } - private bool DrawMaterialCombo(MdlTab tab, int meshIndex, bool disabled) + private static bool DrawMaterialCombo(MdlTab tab, int meshIndex, bool disabled) { var mesh = tab.Mdl.Meshes[meshIndex]; using var _ = ImRaii.Disabled(disabled); diff --git a/Penumbra/UI/ModsTab/ModPanel.cs b/Penumbra/UI/ModsTab/ModPanel.cs index 15961ff3..f9a3262f 100644 --- a/Penumbra/UI/ModsTab/ModPanel.cs +++ b/Penumbra/UI/ModsTab/ModPanel.cs @@ -1,5 +1,6 @@ using Dalamud.Plugin; using Penumbra.Mods; +using Penumbra.Services; using Penumbra.UI.AdvancedWindow; namespace Penumbra.UI.ModsTab; @@ -13,13 +14,13 @@ public class ModPanel : IDisposable private readonly ModPanelTabBar _tabs; public ModPanel(DalamudPluginInterface pi, ModFileSystemSelector selector, ModEditWindow editWindow, ModPanelTabBar tabs, - MultiModPanel multiModPanel) + MultiModPanel multiModPanel, CommunicatorService communicator) { _selector = selector; _editWindow = editWindow; _tabs = tabs; _multiModPanel = multiModPanel; - _header = new ModPanelHeader(pi); + _header = new ModPanelHeader(pi, communicator); _selector.SelectionChanged += OnSelectionChange; } diff --git a/Penumbra/UI/ModsTab/ModPanelHeader.cs b/Penumbra/UI/ModsTab/ModPanelHeader.cs index 2c71426f..4b127059 100644 --- a/Penumbra/UI/ModsTab/ModPanelHeader.cs +++ b/Penumbra/UI/ModsTab/ModPanelHeader.cs @@ -3,7 +3,10 @@ using Dalamud.Plugin; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using Penumbra.Communication; using Penumbra.Mods; +using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.UI.Classes; namespace Penumbra.UI.ModsTab; @@ -13,8 +16,14 @@ public class ModPanelHeader : IDisposable /// We use a big, nice game font for the title. private readonly GameFontHandle _nameFont; - public ModPanelHeader(DalamudPluginInterface pi) - => _nameFont = pi.UiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Jupiter23)); + private readonly CommunicatorService _communicator; + + public ModPanelHeader(DalamudPluginInterface pi, CommunicatorService communicator) + { + _communicator = communicator; + _nameFont = pi.UiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Jupiter23)); + _communicator.ModDataChanged.Subscribe(OnModDataChange, ModDataChanged.Priority.ModPanelHeader); + } /// /// Draw the header for the current mod, @@ -76,6 +85,7 @@ public class ModPanelHeader : IDisposable public void Dispose() { _nameFont.Dispose(); + _communicator.ModDataChanged.Unsubscribe(OnModDataChange); } // Header data. @@ -218,4 +228,13 @@ public class ModPanelHeader : IDisposable ImGui.TextUnformatted(_modWebsite); } } + + /// Just update the data when any relevant field changes. + private void OnModDataChange(ModDataChangeType changeType, Mod mod, string? _2) + { + const ModDataChangeType relevantChanges = + ModDataChangeType.Author | ModDataChangeType.Name | ModDataChangeType.Website | ModDataChangeType.Version; + if ((changeType & relevantChanges) != 0) + UpdateModData(mod); + } }