From 83e276f884061cc5af7489221675a1f9159c172b Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Tue, 28 Nov 2023 15:16:11 -0800 Subject: [PATCH] Add /craftaction command --- Craftimizer/Plugin.cs | 8 ++++++++ Craftimizer/Windows/SynthHelper.cs | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Craftimizer/Plugin.cs b/Craftimizer/Plugin.cs index 0c06ef4..981e0bc 100644 --- a/Craftimizer/Plugin.cs +++ b/Craftimizer/Plugin.cs @@ -78,6 +78,10 @@ public sealed class Plugin : IDalamudPlugin { HelpMessage = "Open the crafting macro editor.", }); + Service.CommandManager.AddHandler("/craftaction", new CommandInfo((_, _) => ExecuteSuggestedSynthHelperAction()) + { + HelpMessage = "Execute the suggested action in the synthesis helper. This command mostly exists for controller players.", + }); } public (CharacterStats? Character, RecipeData? Recipe, MacroEditor.CrafterBuffs? Buffs) GetOpenedStats() @@ -122,6 +126,9 @@ public sealed class Plugin : IDalamudPlugin EditorWindow = new(characterStats, recipeData, buffs, actions, setter); } + public void ExecuteSuggestedSynthHelperAction() => + SynthHelperWindow.QueueSuggestedActionExecution(); + public void OpenSettingsWindow() { if (SettingsWindow.IsOpen ^= true) @@ -159,6 +166,7 @@ public sealed class Plugin : IDalamudPlugin Service.CommandManager.RemoveHandler("/craftimizer"); Service.CommandManager.RemoveHandler("/craftmacros"); Service.CommandManager.RemoveHandler("/crafteditor"); + Service.CommandManager.RemoveHandler("/craftaction"); SettingsWindow.Dispose(); RecipeNoteWindow.Dispose(); SynthHelperWindow.Dispose(); diff --git a/Craftimizer/Windows/SynthHelper.cs b/Craftimizer/Windows/SynthHelper.cs index 66ada5d..a31f71d 100644 --- a/Craftimizer/Windows/SynthHelper.cs +++ b/Craftimizer/Windows/SynthHelper.cs @@ -59,6 +59,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable private SimulationState currentState; private SimulatedMacro Macro { get; } = new(); + private bool IsSuggestedActionExecutionQueued { get; set; } + private CancellationTokenSource? HelperTaskTokenSource { get; set; } private Exception? HelperTaskException { get; set; } private Solver.Solver? HelperTaskObject { get; set; } @@ -86,7 +88,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable Service.WindowSystem.AddWindow(this); } - private bool wasOpen; public override bool DrawConditions() { @@ -99,6 +100,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable HelperTaskTokenSource?.Cancel(); } } + if (!isOpen) + IsSuggestedActionExecutionQueued = false; wasOpen = isOpen; return isOpen; @@ -114,7 +117,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable return false; if (Service.Configuration.DisableSynthHelperOnMacro && - RaptureShellModule.Instance()->MacroCurrentLine >= 0) + RaptureShellModule.Instance()->MacroCurrentLine >= 0 && + !IsSuggestedActionExecutionQueued) return false; Addon = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis"); @@ -160,6 +164,11 @@ public sealed unsafe class SynthHelper : Window, IDisposable Position = ImGuiHelpers.MainViewport.Pos + pos + new Vector2(size.X, offset * scale); } + public override void PostDraw() + { + IsSuggestedActionExecutionQueued = false; + } + public override void Draw() { DrawMacro(); @@ -226,7 +235,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable isPressed = ImGuiExtras.ButtonBehavior(bb, id, out isHovered, out isHeld, ImGuiButtonFlags.None); } ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize), default, Vector2.One, 0, default, failedAction ? new(1, 1, 1, ImGui.GetStyle().DisabledAlpha) : Vector4.One); - if (isPressed) + if (isPressed || IsSuggestedActionExecutionQueued) { if (canExecute && i == 0) { @@ -562,6 +571,11 @@ public sealed unsafe class SynthHelper : Window, IDisposable HelperTaskTokenSource?.Cancel(); } + public void QueueSuggestedActionExecution() + { + IsSuggestedActionExecutionQueued = true; + } + private static Sim CreateSim(in SimulationState state) => Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state };