diff --git a/Craftimizer/Service.cs b/Craftimizer/Service.cs index d0519bc..6a4cf90 100644 --- a/Craftimizer/Service.cs +++ b/Craftimizer/Service.cs @@ -5,6 +5,7 @@ using Dalamud.Interface.Windowing; using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Plugin.Services; +using Dalamud.Storage.Assets; namespace Craftimizer.Plugin; @@ -19,6 +20,7 @@ public sealed class Service [PluginService] public static IClientState ClientState { get; private set; } [PluginService] public static IDataManager DataManager { get; private set; } [PluginService] public static ITextureProvider TextureProvider { get; private set; } + [PluginService] public static IDalamudAssetManager DalamudAssetManager { get; private set; } [PluginService] public static ITargetManager TargetManager { get; private set; } [PluginService] public static ICondition Condition { get; private set; } [PluginService] public static IFramework Framework { get; private set; } diff --git a/Craftimizer/Utils/Hooks.cs b/Craftimizer/Utils/Hooks.cs index 355237e..41e6258 100644 --- a/Craftimizer/Utils/Hooks.cs +++ b/Craftimizer/Utils/Hooks.cs @@ -66,7 +66,10 @@ public sealed unsafe class Hooks : IDisposable if (!Service.Configuration.SynthHelperAbilityAnts) return ret; - if (!Service.Plugin.SynthHelperWindow.ShouldDrawAnts) + if (Service.Plugin.SynthHelperWindow is not { } window) + return ret; + + if (!window.ShouldDrawAnts) return ret; if (actionType is not (CSActionType.CraftAction or CSActionType.Action)) @@ -84,7 +87,7 @@ public sealed unsafe class Hooks : IDisposable if (simActionType == null) return ret; - if (Service.Plugin.SynthHelperWindow.NextAction != simActionType) + if (window.NextAction != simActionType) return 0; } catch (Exception ex) diff --git a/Craftimizer/Utils/IconManager.cs b/Craftimizer/Utils/IconManager.cs index 48ddba2..a31f50b 100644 --- a/Craftimizer/Utils/IconManager.cs +++ b/Craftimizer/Utils/IconManager.cs @@ -28,9 +28,6 @@ public sealed class IconManager : IDisposable { private sealed class LoadedIcon : ILoadedTextureIcon { - // 10: DXGI_FORMAT_R16G16B16A16_FLOAT - public static IDalamudTextureWrap EmptyTexture { get; } = Service.TextureProvider.CreateEmpty(new(4, 4, 10), false, false); - public ISharedImmediateTexture Source { get; } public Vector2? Dimensions => GetWrap()?.Size; @@ -54,7 +51,7 @@ public sealed class IconManager : IDisposable return null; } - public IDalamudTextureWrap GetWrapOrEmpty() => GetWrap() ?? EmptyTexture; + public IDalamudTextureWrap GetWrapOrEmpty() => GetWrap() ?? Service.DalamudAssetManager.Empty4X4; public void Dispose() { diff --git a/Craftimizer/Windows/SynthHelper.cs b/Craftimizer/Windows/SynthHelper.cs index 9ff251d..b90ec95 100644 --- a/Craftimizer/Windows/SynthHelper.cs +++ b/Craftimizer/Windows/SynthHelper.cs @@ -46,9 +46,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable public CharacterStats? CharacterStats { get; private set; } public SimulationInput? SimulationInput { get; private set; } public ActionType? NextAction => (ShouldOpen && Macro.Count > 0) ? Macro[0].Action : null; - public bool ShouldDrawAnts => ShouldOpen; + public bool ShouldDrawAnts => ShouldOpen && !IsCollapsed; - public bool IsCrafting { get; private set; } private int CurrentActionCount { get; set; } private ActionStates CurrentActionStates { get; set; } private SimulationState CurrentState @@ -112,6 +111,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable private bool ShouldCalculate => !IsCollapsed && ShouldOpen; private bool WasCalculatable { get; set; } + private bool IsRecalculateQueued { get; set; } + public override void Update() { base.Update(); @@ -121,14 +122,15 @@ public sealed unsafe class SynthHelper : Window, IDisposable if (ShouldCalculate != WasCalculatable) { if (WasCalculatable) - { - IsCrafting = false; SolverTask?.Cancel(); - } else if (Macro.Count == 0) - { OnStateUpdated(); - } + } + + if (Macro.Count == 0) + { + if (ShouldOpen != WasOpen || IsCollapsed != WasCollapsed) + OnStateUpdated(); } if (!ShouldOpen) @@ -188,11 +190,11 @@ public sealed unsafe class SynthHelper : Window, IDisposable if (agent->ActiveCraftRecipeId == 0) return false; - if (!IsCrafting) - { - IsCrafting = true; + if (RecipeData?.RecipeId != agent->ActiveCraftRecipeId) OnStartCrafting(recipeId); - } + + if (IsRecalculateQueued) + OnStateUpdated(); Macro.FlushQueue(); @@ -474,6 +476,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable private void OnStartCrafting(ushort recipeId) { + Log.Debug("On Start craftgin begin!"); + var shouldUpdateInput = false; if (recipeId != RecipeData?.RecipeId) { @@ -504,13 +508,12 @@ public sealed unsafe class SynthHelper : Window, IDisposable CurrentActionCount = 0; CurrentActionStates = new(); CurrentState = GetCurrentState(); + + Log.Debug("On Start craftgin end!"); } private void OnUseAction(ActionType action) { - if (!IsCrafting || !ShouldOpen || IsCollapsed) - return; - (_, CurrentState) = new SimNoRandom().Execute(GetCurrentState(), action); CurrentActionCount = CurrentState.ActionCount; CurrentActionStates = CurrentState.ActionStates; @@ -518,9 +521,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable private void OnFinishedUsingAction() { - if (!IsCrafting || !ShouldOpen || IsCollapsed) - return; - CurrentState = GetCurrentState(); } @@ -575,9 +575,13 @@ public sealed unsafe class SynthHelper : Window, IDisposable private void OnStateUpdated() { - if (!IsCrafting || !ShouldOpen || IsCollapsed) + if (!ShouldOpen || IsCollapsed) + { + IsRecalculateQueued = true; return; + } + IsRecalculateQueued = false; Macro.Clear(); Macro.InitialState = CurrentState; CalculateBestMacro();