diff --git a/Penumbra.Api b/Penumbra.Api index d2a1406b..a28a2537 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit d2a1406bc32f715c0687613f02e3f74caf7ceea9 +Subproject commit a28a2537c0ff030cf09f740bff3b1a51ac0b41f6 diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index c8be90aa..da1eafd0 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -33,12 +33,24 @@ namespace Penumbra.Api; public class PenumbraApi : IDisposable, IPenumbraApi { public (int, int) ApiVersion - => (4, 23); + => (4, 24); + + public event Action? PreSettingsTabBarDraw + { + add => _communicator.PreSettingsTabBarDraw.Subscribe(value!, Communication.PreSettingsTabBarDraw.Priority.Default); + remove => _communicator.PreSettingsTabBarDraw.Unsubscribe(value!); + } public event Action? PreSettingsPanelDraw { add => _communicator.PreSettingsPanelDraw.Subscribe(value!, Communication.PreSettingsPanelDraw.Priority.Default); remove => _communicator.PreSettingsPanelDraw.Unsubscribe(value!); + } + + public event Action? PostEnabledDraw + { + add => _communicator.PostEnabledDraw.Subscribe(value!, Communication.PostEnabledDraw.Priority.Default); + remove => _communicator.PostEnabledDraw.Unsubscribe(value!); } public event Action? PostSettingsPanelDraw diff --git a/Penumbra/Communication/PostEnabledDraw.cs b/Penumbra/Communication/PostEnabledDraw.cs new file mode 100644 index 00000000..68637442 --- /dev/null +++ b/Penumbra/Communication/PostEnabledDraw.cs @@ -0,0 +1,18 @@ +using OtterGui.Classes; + +namespace Penumbra.Communication; + +/// +/// Triggered after the Enabled Checkbox line in settings is drawn, but before options are drawn. +/// +/// Parameter is the identifier (directory name) of the currently selected mod. +/// +/// +public sealed class PostEnabledDraw() : EventWrapper(nameof(PostEnabledDraw)) +{ + public enum Priority + { + /// + Default = 0, + } +} diff --git a/Penumbra/Communication/PreSettingsTabBarDraw.cs b/Penumbra/Communication/PreSettingsTabBarDraw.cs new file mode 100644 index 00000000..2c14cdf1 --- /dev/null +++ b/Penumbra/Communication/PreSettingsTabBarDraw.cs @@ -0,0 +1,20 @@ +using OtterGui.Classes; + +namespace Penumbra.Communication; + +/// +/// Triggered before the settings tab bar for a mod is drawn, after the title group is drawn. +/// +/// Parameter is the identifier (directory name) of the currently selected mod. +/// is the total width of the header group. +/// is the width of the title box. +/// +/// +public sealed class PreSettingsTabBarDraw() : EventWrapper(nameof(PreSettingsTabBarDraw)) +{ + public enum Priority + { + /// + Default = 0, + } +} diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index ff068928..34451dfa 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -95,6 +95,17 @@ public class Penumbra : IDalamudPlugin if (_characterUtility.Ready) _residentResources.Reload(); + + var api = _services.GetService(); + api.PostEnabledDraw += ImGui.TextUnformatted; + api.PreSettingsTabBarDraw += (name, width, titleWidth) => + { + ImGui.TextUnformatted(width.ToString()); + ImGui.TextUnformatted(titleWidth.ToString()); + ImGui.TextUnformatted(ImGui.GetContentRegionMax().X.ToString()); + ImGui.SetCursorPosX(ImGui.GetCursorPosX() + (width - titleWidth) / 2); + ImGui.Button("Test", new Vector2(titleWidth, 0)); + }; } catch (Exception ex) { diff --git a/Penumbra/Services/CommunicatorService.cs b/Penumbra/Services/CommunicatorService.cs index da852855..cacbe689 100644 --- a/Penumbra/Services/CommunicatorService.cs +++ b/Penumbra/Services/CommunicatorService.cs @@ -57,9 +57,15 @@ public class CommunicatorService : IDisposable, IService /// public readonly EnabledChanged EnabledChanged = new(); + /// + public readonly PreSettingsTabBarDraw PreSettingsTabBarDraw = new(); + /// public readonly PreSettingsPanelDraw PreSettingsPanelDraw = new(); + /// + public readonly PostEnabledDraw PostEnabledDraw = new(); + /// public readonly PostSettingsPanelDraw PostSettingsPanelDraw = new(); @@ -91,7 +97,9 @@ public class CommunicatorService : IDisposable, IService ModSettingChanged.Dispose(); CollectionInheritanceChanged.Dispose(); EnabledChanged.Dispose(); + PreSettingsTabBarDraw.Dispose(); PreSettingsPanelDraw.Dispose(); + PostEnabledDraw.Dispose(); PostSettingsPanelDraw.Dispose(); ChangedItemHover.Dispose(); ChangedItemClick.Dispose(); diff --git a/Penumbra/UI/ModsTab/ModPanelHeader.cs b/Penumbra/UI/ModsTab/ModPanelHeader.cs index ed499b4f..05f47809 100644 --- a/Penumbra/UI/ModsTab/ModPanelHeader.cs +++ b/Penumbra/UI/ModsTab/ModPanelHeader.cs @@ -32,9 +32,14 @@ public class ModPanelHeader : IDisposable /// public void Draw() { - var offset = DrawModName(); - DrawVersion(offset); - DrawSecondRow(offset); + using (ImRaii.Group()) + { + var offset = DrawModName(); + DrawVersion(offset); + DrawSecondRow(offset); + } + + _communicator.PreSettingsTabBarDraw.Invoke(_mod.Identifier, ImGui.GetItemRectSize().X, _nameWidth); } /// @@ -43,6 +48,7 @@ public class ModPanelHeader : IDisposable /// public void UpdateModData(Mod mod) { + _mod = mod; // Name var name = $" {mod.Name} "; if (name != _modName) @@ -90,6 +96,7 @@ public class ModPanelHeader : IDisposable } // Header data. + private Mod _mod = null!; private string _modName = string.Empty; private string _modAuthor = string.Empty; private string _modVersion = string.Empty; @@ -103,6 +110,8 @@ public class ModPanelHeader : IDisposable private float _modWebsiteButtonWidth; private float _secondRowWidth; + private float _nameWidth; + /// /// Draw the mod name in the game font with a 2px border, centered, /// with at least the width of the version space to each side. @@ -124,6 +133,7 @@ public class ModPanelHeader : IDisposable using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, 2 * UiHelpers.Scale); using var f = _nameFont.Push(); ImGuiUtil.DrawTextButton(_modName, Vector2.Zero, 0); + _nameWidth = ImGui.GetItemRectSize().X; return offset; } diff --git a/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs b/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs index 5c7ddbf3..b14cad01 100644 --- a/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs +++ b/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs @@ -61,7 +61,7 @@ public class ModPanelSettingsTab : ITab DrawInheritedWarning(); UiHelpers.DefaultLineSpace(); - _communicator.PreSettingsPanelDraw.Invoke(_selector.Selected!.ModPath.Name); + _communicator.PreSettingsPanelDraw.Invoke(_selector.Selected!.Identifier); DrawEnabledInput(); _tutorial.OpenTutorial(BasicTutorialSteps.EnablingMods); ImGui.SameLine(); @@ -69,6 +69,8 @@ public class ModPanelSettingsTab : ITab _tutorial.OpenTutorial(BasicTutorialSteps.Priority); DrawRemoveSettings(); + _communicator.PostEnabledDraw.Invoke(_selector.Selected!.Identifier); + if (_selector.Selected!.Groups.Count > 0) { var useDummy = true; @@ -98,7 +100,7 @@ public class ModPanelSettingsTab : ITab } UiHelpers.DefaultLineSpace(); - _communicator.PostSettingsPanelDraw.Invoke(_selector.Selected!.ModPath.Name); + _communicator.PostSettingsPanelDraw.Invoke(_selector.Selected!.Identifier); } /// Draw a big red bar if the current setting is inherited.