Skip to content

Commit

Permalink
feat: add option to enable integrations old older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Mar 24, 2024
1 parent 161998a commit 916d490
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion PenumbraIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Ui/Components/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal Importer(Plugin plugin, string modName, Guid packageId, Guid variantId,
/// <returns>true if import succeeded, false if not started/failed</returns>
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);
Expand Down
2 changes: 1 addition & 1 deletion Ui/ExternalImportWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Ui/InstallerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions Ui/PenumbraWindowIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Ui/PromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Ui/Tabs/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void DrawPackageList(Dictionary<Guid, IVariantInfo> 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 () => {
Expand All @@ -161,7 +161,7 @@ private void DrawPackageList(Dictionary<Guid, IVariantInfo> 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));
}
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 10 additions & 1 deletion Ui/Tabs/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.");
Expand Down
6 changes: 5 additions & 1 deletion Util/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 916d490

Please sign in to comment.