From 36f646830ca9499bc43ef2a160c48bd3b40f7fbb Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 13 Apr 2025 10:09:48 +0200 Subject: [PATCH] Add Pandora's Box to initial setup window; add 'open config' button to CBT/Pandora --- Questionable/Configuration.cs | 2 +- Questionable/External/PandorasBoxIpc.cs | 40 +++++++++++++ Questionable/QuestionablePlugin.cs | 2 +- Questionable/Windows/OneTimeSetupWindow.cs | 66 +++++++++++++++++----- 4 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 Questionable/External/PandorasBoxIpc.cs diff --git a/Questionable/Configuration.cs b/Questionable/Configuration.cs index 952cf2bb..ef4eb110 100644 --- a/Questionable/Configuration.cs +++ b/Questionable/Configuration.cs @@ -11,7 +11,7 @@ namespace Questionable; internal sealed class Configuration : IPluginConfiguration { - public const int PluginSetupVersion = 4; + public const int PluginSetupVersion = 5; public int Version { get; set; } = 1; public int PluginSetupCompleteVersion { get; set; } diff --git a/Questionable/External/PandorasBoxIpc.cs b/Questionable/External/PandorasBoxIpc.cs new file mode 100644 index 00000000..e3f902c4 --- /dev/null +++ b/Questionable/External/PandorasBoxIpc.cs @@ -0,0 +1,40 @@ +using Dalamud.Plugin; +using Dalamud.Plugin.Ipc; +using Dalamud.Plugin.Ipc.Exceptions; +using Microsoft.Extensions.Logging; + +namespace Questionable.External; + +internal sealed class PandorasBoxIpc +{ + private readonly ILogger _logger; + private readonly ICallGateSubscriber _getFeatureEnabled; + private bool _loggedIpcError; + + public PandorasBoxIpc(IDalamudPluginInterface pluginInterface, ILogger logger) + { + _logger = logger; + _getFeatureEnabled = pluginInterface.GetIpcSubscriber("PandorasBox.GetFeatureEnabled"); + logger.LogInformation("Pandora's Box auto active time maneuver enabled: {IsAtmEnabled}", IsAutoActiveTimeManeuverEnabled); + } + + public bool IsAutoActiveTimeManeuverEnabled + { + get + { + try + { + return _getFeatureEnabled.InvokeFunc("Auto Active Time Maneuver"); + } + catch (IpcError e) + { + if (!_loggedIpcError) + { + _loggedIpcError = true; + _logger.LogWarning(e, "Could not query pandora's box for feature status, probably not installed"); + } + return false; + } + } + } +} diff --git a/Questionable/QuestionablePlugin.cs b/Questionable/QuestionablePlugin.cs index d283f571..f13f9069 100644 --- a/Questionable/QuestionablePlugin.cs +++ b/Questionable/QuestionablePlugin.cs @@ -133,6 +133,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); } @@ -337,7 +338,6 @@ public sealed class QuestionablePlugin : IDalamudPlugin serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); - serviceProvider.GetRequiredService(); } public void Dispose() diff --git a/Questionable/Windows/OneTimeSetupWindow.cs b/Questionable/Windows/OneTimeSetupWindow.cs index 128a2f1a..37c151f3 100644 --- a/Questionable/Windows/OneTimeSetupWindow.cs +++ b/Questionable/Windows/OneTimeSetupWindow.cs @@ -7,6 +7,7 @@ using Dalamud.Interface.Colors; using Dalamud.Interface.Components; using Dalamud.Interface.Utility.Raii; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using Dalamud.Utility; using ImGuiNET; using LLib.ImGui; @@ -79,9 +80,16 @@ internal sealed class OneTimeSetupWindow : LWindow private readonly IDalamudPluginInterface _pluginInterface; private readonly UiUtils _uiUtils; private readonly ILogger _logger; - - public OneTimeSetupWindow(Configuration configuration, IDalamudPluginInterface pluginInterface, UiUtils uiUtils, - ILogger logger, AutomatonIpc automatonIpc) + private readonly ICommandManager _commandManager; + + public OneTimeSetupWindow( + Configuration configuration, + IDalamudPluginInterface pluginInterface, + UiUtils uiUtils, + ILogger logger, + AutomatonIpc automatonIpc, + PandorasBoxIpc pandorasBoxIpc, + ICommandManager commandManager) : base("Questionable Setup###QuestionableOneTimeSetup", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings, true) { @@ -89,6 +97,7 @@ internal sealed class OneTimeSetupWindow : LWindow _pluginInterface = pluginInterface; _uiUtils = uiUtils; _logger = logger; + _commandManager = commandManager; _recommendedPlugins = [ new PluginInfo("CBT (formerly known as Automaton)", @@ -99,7 +108,20 @@ internal sealed class OneTimeSetupWindow : LWindow """, new Uri("https://github.com/Jaksuhn/Automaton"), new Uri("https://puni.sh/api/repository/croizat"), + "/cbt", [new PluginDetailInfo("'Sniper no sniping' enabled", () => automatonIpc.IsAutoSnipeEnabled)]), + new PluginInfo("Pandora's Box", + "PandorasBox", + """ + Pandora's Box is a collection of tweaks. + The 'Auto Active Time Maneuver' tweak can complete any + active time maneuvers in single player instances, trials and raids. + """, + new Uri("https://github.com/PunishXIV/PandorasBox"), + new Uri("https://puni.sh/api/plugins"), + "/pandora", + [new PluginDetailInfo("'Auto Active Time Maneuver' enabled", + () => pandorasBoxIpc.IsAutoActiveTimeManeuverEnabled)]), new("NotificationMaster", "NotificationMaster", """ @@ -249,27 +271,44 @@ internal sealed class OneTimeSetupWindow : LWindow if (!string.IsNullOrEmpty(plugin.Details)) ImGui.TextUnformatted(plugin.Details); + bool allDetailsOk = true; if (plugin.DetailsToCheck != null) { foreach (var detail in plugin.DetailsToCheck) - _uiUtils.ChecklistItem(detail.DisplayName, isInstalled && detail.Predicate()); + { + bool detailOk = detail.Predicate(); + allDetailsOk &= detailOk; + + _uiUtils.ChecklistItem(detail.DisplayName, isInstalled && detailOk); + } } ImGui.Spacing(); - if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Globe, "Open Website")) - Util.OpenLink(plugin.WebsiteUri.ToString()); - - ImGui.SameLine(); - if (plugin.DalamudRepositoryUri != null) + if (isInstalled) { - if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Code, "Open Repository")) - Util.OpenLink(plugin.DalamudRepositoryUri.ToString()); + if (!allDetailsOk && plugin.ConfigCommand != null && plugin.ConfigCommand.StartsWith('/')) + { + if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Cog, "Open configuration")) + _commandManager.ProcessCommand(plugin.ConfigCommand); + } } else { - ImGui.AlignTextToFramePadding(); - ImGuiComponents.HelpMarker("Available on official Dalamud Repository"); + if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Globe, "Open Website")) + Util.OpenLink(plugin.WebsiteUri.ToString()); + + ImGui.SameLine(); + if (plugin.DalamudRepositoryUri != null) + { + if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Code, "Open Repository")) + Util.OpenLink(plugin.DalamudRepositoryUri.ToString()); + } + else + { + ImGui.AlignTextToFramePadding(); + ImGuiComponents.HelpMarker("Available on official Dalamud Repository"); + } } } } @@ -285,6 +324,7 @@ internal sealed class OneTimeSetupWindow : LWindow string Details, Uri WebsiteUri, Uri? DalamudRepositoryUri, + string? ConfigCommand = null, List? DetailsToCheck = null); private sealed record PluginDetailInfo(string DisplayName, Func Predicate); -- 2.30.2