From 916d49041a72680c3aca086c8472f28707749a6f Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 24 Mar 2024 12:04:44 -0400 Subject: [PATCH] feat: add option to enable integrations old older versions --- Configuration.cs | 1 + PenumbraIpc.cs | 10 +++++++++- Ui/Components/Importer.cs | 2 +- Ui/ExternalImportWindow.cs | 2 +- Ui/InstallerWindow.cs | 2 +- Ui/PenumbraWindowIntegration.cs | 2 ++ Ui/PromptWindow.cs | 2 +- Ui/Tabs/Manager.cs | 8 ++++---- Ui/Tabs/Settings.cs | 11 ++++++++++- Util/ImGuiHelper.cs | 6 +++++- 10 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Configuration.cs b/Configuration.cs index de3bdd1..26c505d 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -91,6 +91,7 @@ internal enum SpeedLimit { [Serializable] internal class PenumbraIntegration { + public bool IntegrateOnLowVersion; public bool ShowImages = true; public bool ShowButtons = true; public float ImageSize = 0.375f; diff --git a/PenumbraIpc.cs b/PenumbraIpc.cs index efbf2ae..fb4823e 100644 --- a/PenumbraIpc.cs +++ b/PenumbraIpc.cs @@ -112,12 +112,16 @@ private void RegisterEvents() { Task.Run(async () => await this.Plugin.State.UpdatePackages()); }); - if (this.AtLeastVersion(4, 24)) { + if (this.AtLeastVersion(PenumbraWindowIntegration.NeededVersion)) { this.PostEnabledDrawEvent = Penumbra.Api.Ipc.PostEnabledDraw.Subscriber(this.Plugin.Interface, this.WindowIntegration.PostEnabledDraw); this.PreSettingsTabBarDrawEvent = Penumbra.Api.Ipc.PreSettingsTabBarDraw.Subscriber(this.Plugin.Interface, this.WindowIntegration.PreSettingsTabBarDraw); } else { this.PreSettingsDrawEvent = Penumbra.Api.Ipc.PreSettingsDraw.Subscriber(this.Plugin.Interface, directory => { + if (!this.Plugin.Config.Penumbra.IntegrateOnLowVersion) { + return; + } + var width = ImGui.GetScrollMaxY() == 0 ? ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ScrollbarSize : ImGui.GetContentRegionAvail().X; @@ -127,6 +131,10 @@ private void RegisterEvents() { } } + internal bool AtLeastVersion((int breaking, int features) tuple) { + return this.AtLeastVersion(tuple.breaking, tuple.features); + } + internal bool AtLeastVersion(int breaking, int features) { if (this.GetApiVersions() is not var (installedBreaking, installedFeatures)) { return false; diff --git a/Ui/Components/Importer.cs b/Ui/Components/Importer.cs index 78c282d..9cb76bf 100644 --- a/Ui/Components/Importer.cs +++ b/Ui/Components/Importer.cs @@ -28,7 +28,7 @@ internal Importer(Plugin plugin, string modName, Guid packageId, Guid variantId, /// true if import succeeded, false if not started/failed internal bool Draw() { var installed = this.Plugin.State.InstalledNoBlock.Any(entry => entry.Value.Variants.Any(variant => variant.VersionId == this.VersionId)); - using var disabled = ImGuiHelper.WithDisabled(installed); + using var disabled = ImGuiHelper.DisabledIf(installed); if (installed) { ImGui.SetNextItemOpen(false); diff --git a/Ui/ExternalImportWindow.cs b/Ui/ExternalImportWindow.cs index d192741..44782af 100644 --- a/Ui/ExternalImportWindow.cs +++ b/Ui/ExternalImportWindow.cs @@ -38,7 +38,7 @@ public DrawStatus Draw() { ImGui.TextUnformatted("Mods that have been installed without using the Heliosphere plugin may be imported into Heliosphere and benefit from automatic updates. You can choose which mods you would like to import below."); ImGui.Separator(); - using var disabled = ImGuiHelper.WithDisabled(this._processing); + using var disabled = ImGuiHelper.DisabledIf(this._processing); if (ImGui.Button("Select all")) { foreach (var id in external.Keys) { this.Selected.Add(id); diff --git a/Ui/InstallerWindow.cs b/Ui/InstallerWindow.cs index a5c578d..e5fc0b6 100644 --- a/Ui/InstallerWindow.cs +++ b/Ui/InstallerWindow.cs @@ -195,7 +195,7 @@ public DrawStatus Draw() { var nextSize = ImGuiHelpers.GetButtonSize(atEnd ? "Download" : "Next"); var offset = ImGui.GetContentRegionAvail().X - nextSize.X + ImGui.GetStyle().ItemSpacing.X; - using (ImGuiHelper.WithDisabled(atZero)) { + using (ImGuiHelper.DisabledIf(atZero)) { if (ImGui.Button("Previous")) { this._page -= 1; } diff --git a/Ui/PenumbraWindowIntegration.cs b/Ui/PenumbraWindowIntegration.cs index 381b06c..16cf0de 100644 --- a/Ui/PenumbraWindowIntegration.cs +++ b/Ui/PenumbraWindowIntegration.cs @@ -10,6 +10,8 @@ namespace Heliosphere.Ui; internal class PenumbraWindowIntegration { + internal static readonly (int, int) NeededVersion = (4, 24); + private Plugin Plugin { get; } internal PenumbraWindowIntegration(Plugin plugin) { diff --git a/Ui/PromptWindow.cs b/Ui/PromptWindow.cs index c4ae6c1..4407264 100644 --- a/Ui/PromptWindow.cs +++ b/Ui/PromptWindow.cs @@ -180,7 +180,7 @@ ref this._collection if (this.Info.Groups.Count > 0 && ImGui.CollapsingHeader("Choose options to install")) { var shiftHeld = ImGui.GetIO().KeyShift; - using (ImGuiHelper.WithDisabled(!shiftHeld)) { + using (ImGuiHelper.DisabledUnless(shiftHeld)) { if (ImGuiHelper.FullWidthButton("Choose options to install##actual-button")) { ret = DrawStatus.Finished; Task.Run(async () => await InstallerWindow.OpenAndAdd(new InstallerWindow.OpenOptions { diff --git a/Ui/Tabs/Manager.cs b/Ui/Tabs/Manager.cs index e4fbd3f..8c0cf55 100644 --- a/Ui/Tabs/Manager.cs +++ b/Ui/Tabs/Manager.cs @@ -146,7 +146,7 @@ private void DrawPackageList(Dictionary allInfo) { ImGui.SameLine(); - using (ImGuiHelper.WithDisabled(this._checkingForUpdates)) { + using (ImGuiHelper.DisabledIf(this._checkingForUpdates)) { if (ImGuiHelper.IconButton(FontAwesomeIcon.Search, tooltip: "Check for updates")) { this._checkingForUpdates = true; Task.Run(async () => { @@ -161,7 +161,7 @@ private void DrawPackageList(Dictionary allInfo) { ImGui.SameLine(); - using (ImGuiHelper.WithDisabled(this._downloadingUpdates)) { + using (ImGuiHelper.DisabledIf(this._downloadingUpdates)) { if (ImGuiHelper.IconButton(FontAwesomeIcon.CloudDownloadAlt, tooltip: "Download updates")) { Task.Run(async () => await this.DownloadUpdates(false)); } @@ -355,7 +355,7 @@ private void DrawActionsTab(HeliosphereMeta pkg) { using (var openingHandle = this._openingInstaller.Wait(0)) { var opening = openingHandle == null || openingHandle.Data.Contains(pkg.Id); - using (ImGuiHelper.WithDisabled(opening)) { + using (ImGuiHelper.DisabledIf(opening)) { if (!pkg.IsSimple() && ImGuiHelper.CentredWideButton("Download different options") && openingHandle != null) { openingHandle.Data.Add(pkg.Id); Task.Run(async () => { @@ -390,7 +390,7 @@ await InstallerWindow.OpenAndAdd(new InstallerWindow.OpenOptions { } var ctrlShift = ImGui.GetIO().KeyCtrl && ImGui.GetIO().KeyShift; - using (ImGuiHelper.WithDisabled(!ctrlShift)) { + using (ImGuiHelper.DisabledUnless(ctrlShift)) { if (ImGuiHelper.CentredWideButton("Delete mod")) { var dir = pkg.ModDirectoryName(); if (this.Plugin.Penumbra.DeleteMod(dir)) { diff --git a/Ui/Tabs/Settings.cs b/Ui/Tabs/Settings.cs index 16d7828..f570a7e 100644 --- a/Ui/Tabs/Settings.cs +++ b/Ui/Tabs/Settings.cs @@ -22,6 +22,15 @@ internal Settings(Plugin plugin) { internal static bool DrawPenumbraIntegrationSettings(Plugin plugin) { var anyChanged = false; + var newEnough = plugin.Penumbra.AtLeastVersion(PenumbraWindowIntegration.NeededVersion); + if (!newEnough) { + anyChanged |= ImGui.Checkbox("Enable Penumbra UI integrations on old versions", ref plugin.Config.Penumbra.IntegrateOnLowVersion); + ImGui.SameLine(); + ImGuiHelper.Help("Your version of Penumbra is older than the expected version for Penumbra UI integrations.\n\nYou can still enable them, but they won't look as good. This setting will disappear if you're on a new enough version."); + } + + using var disabled = ImGuiHelper.DisabledUnless(newEnough || plugin.Config.Penumbra.IntegrateOnLowVersion); + anyChanged |= ImGui.Checkbox("Show mod image previews in Penumbra", ref plugin.Config.Penumbra.ShowImages); anyChanged |= ImGui.Checkbox("Show Heliosphere buttons in Penumbra", ref plugin.Config.Penumbra.ShowButtons); @@ -66,7 +75,7 @@ internal void Draw() { if (ImGui.TreeNodeEx("User interface", ImGuiTreeNodeFlags.DefaultOpen)) { using var treePop = new OnDispose(ImGui.TreePop); - using (ImGuiHelper.WithDisabled(this.Plugin.Config.UseNotificationProgress)) { + using (ImGuiHelper.DisabledIf(this.Plugin.Config.UseNotificationProgress)) { ImGui.Checkbox("Preview download status window", ref this.Ui.StatusWindow.Preview); ImGui.SameLine(); ImGuiHelper.Help("Shows fake mod downloads so you can position the status window where you like."); diff --git a/Util/ImGuiHelper.cs b/Util/ImGuiHelper.cs index a53bac7..8999645 100644 --- a/Util/ImGuiHelper.cs +++ b/Util/ImGuiHelper.cs @@ -551,7 +551,11 @@ internal static bool CollectionChooser(PenumbraIpc penumbra, string label, ref s return anyChanged; } - internal static OnDispose WithDisabled(bool disabled) { + internal static OnDispose DisabledUnless(bool unless) { + return DisabledIf(!unless); + } + + internal static OnDispose DisabledIf(bool disabled) { if (disabled) { ImGui.BeginDisabled(); }