Stop background tasks when collapsed
This commit is contained in:
@@ -37,7 +37,6 @@ namespace Craftimizer.Windows;
|
|||||||
public sealed unsafe class RecipeNote : Window, IDisposable
|
public sealed unsafe class RecipeNote : Window, IDisposable
|
||||||
{
|
{
|
||||||
private const ImGuiWindowFlags WindowFlagsPinned = WindowFlagsFloating
|
private const ImGuiWindowFlags WindowFlagsPinned = WindowFlagsFloating
|
||||||
| ImGuiWindowFlags.NoDecoration
|
|
||||||
| ImGuiWindowFlags.NoSavedSettings;
|
| ImGuiWindowFlags.NoSavedSettings;
|
||||||
|
|
||||||
private const ImGuiWindowFlags WindowFlagsFloating =
|
private const ImGuiWindowFlags WindowFlagsFloating =
|
||||||
@@ -150,13 +149,24 @@ public sealed unsafe class RecipeNote : Window, IDisposable
|
|||||||
Service.WindowSystem.AddWindow(this);
|
Service.WindowSystem.AddWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool wasOpen;
|
private bool IsCollapsed { get; set; }
|
||||||
public override bool DrawConditions()
|
private bool ShouldOpen { get; set; }
|
||||||
|
|
||||||
|
private bool WasOpen { get; set; }
|
||||||
|
private bool WasCollapsed { get; set; }
|
||||||
|
|
||||||
|
private bool ShouldCalculate => !IsCollapsed && ShouldOpen;
|
||||||
|
private bool WasCalculatable { get; set; }
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
{
|
{
|
||||||
var isOpen = ShouldDraw();
|
base.Update();
|
||||||
if (isOpen != wasOpen)
|
|
||||||
|
ShouldOpen = CalculateShouldOpen();
|
||||||
|
|
||||||
|
if (ShouldCalculate != WasCalculatable)
|
||||||
{
|
{
|
||||||
if (wasOpen)
|
if (WasCalculatable)
|
||||||
{
|
{
|
||||||
SavedMacroTask?.Cancel();
|
SavedMacroTask?.Cancel();
|
||||||
SuggestedMacroTask?.Cancel();
|
SuggestedMacroTask?.Cancel();
|
||||||
@@ -190,12 +200,16 @@ public sealed unsafe class RecipeNote : Window, IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wasOpen = isOpen;
|
WasOpen = ShouldOpen;
|
||||||
return isOpen;
|
WasCollapsed = IsCollapsed;
|
||||||
|
WasCalculatable = ShouldCalculate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool DrawConditions() =>
|
||||||
|
ShouldOpen;
|
||||||
|
|
||||||
private bool StatsChanged { get; set; }
|
private bool StatsChanged { get; set; }
|
||||||
private bool ShouldDraw()
|
private bool CalculateShouldOpen()
|
||||||
{
|
{
|
||||||
if (Service.ClientState.LocalPlayer == null)
|
if (Service.ClientState.LocalPlayer == null)
|
||||||
return false;
|
return false;
|
||||||
@@ -292,6 +306,8 @@ public sealed unsafe class RecipeNote : Window, IDisposable
|
|||||||
{
|
{
|
||||||
base.PreDraw();
|
base.PreDraw();
|
||||||
|
|
||||||
|
IsCollapsed = true;
|
||||||
|
|
||||||
if (Service.Configuration.PinRecipeNoteToWindow)
|
if (Service.Configuration.PinRecipeNoteToWindow)
|
||||||
{
|
{
|
||||||
ref var unit = ref Addon->AtkUnitBase;
|
ref var unit = ref Addon->AtkUnitBase;
|
||||||
@@ -316,6 +332,8 @@ public sealed unsafe class RecipeNote : Window, IDisposable
|
|||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
IsCollapsed = false;
|
||||||
|
|
||||||
var availWidth = ImGui.GetContentRegionAvail().X;
|
var availWidth = ImGui.GetContentRegionAvail().X;
|
||||||
using (var table = ImRaii.Table("stats", 2, ImGuiTableFlags.BordersInnerV | ImGuiTableFlags.SizingFixedSame | ImGuiTableFlags.NoSavedSettings))
|
using (var table = ImRaii.Table("stats", 2, ImGuiTableFlags.BordersInnerV | ImGuiTableFlags.SizingFixedSame | ImGuiTableFlags.NoSavedSettings))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ namespace Craftimizer.Windows;
|
|||||||
public sealed unsafe class SynthHelper : Window, IDisposable
|
public sealed unsafe class SynthHelper : Window, IDisposable
|
||||||
{
|
{
|
||||||
private const ImGuiWindowFlags WindowFlagsPinned = WindowFlagsFloating
|
private const ImGuiWindowFlags WindowFlagsPinned = WindowFlagsFloating
|
||||||
| ImGuiWindowFlags.NoDecoration
|
|
||||||
| ImGuiWindowFlags.NoSavedSettings;
|
| ImGuiWindowFlags.NoSavedSettings;
|
||||||
|
|
||||||
private const ImGuiWindowFlags WindowFlagsFloating =
|
private const ImGuiWindowFlags WindowFlagsFloating =
|
||||||
@@ -106,27 +105,47 @@ public sealed unsafe class SynthHelper : Window, IDisposable
|
|||||||
Service.WindowSystem.AddWindow(this);
|
Service.WindowSystem.AddWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool wasOpen;
|
private bool IsCollapsed { get; set; }
|
||||||
public override bool DrawConditions()
|
private bool ShouldOpen { get; set; }
|
||||||
|
|
||||||
|
private bool WasOpen { get; set; }
|
||||||
|
private bool WasCollapsed { get; set; }
|
||||||
|
|
||||||
|
private bool ShouldCalculate => !IsCollapsed && ShouldOpen;
|
||||||
|
private bool WasCalculatable { get; set; }
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
{
|
{
|
||||||
var isOpen = ShouldDraw();
|
base.Update();
|
||||||
if (isOpen != wasOpen)
|
|
||||||
|
ShouldOpen = CalculateShouldOpen();
|
||||||
|
|
||||||
|
if (ShouldCalculate != WasCalculatable)
|
||||||
{
|
{
|
||||||
if (wasOpen)
|
if (WasCalculatable)
|
||||||
{
|
{
|
||||||
IsCrafting = false;
|
IsCrafting = false;
|
||||||
HelperTaskTokenSource?.Cancel();
|
HelperTaskTokenSource?.Cancel();
|
||||||
}
|
}
|
||||||
|
else if (Macro.Count == 0)
|
||||||
|
{
|
||||||
|
OnStateUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!isOpen)
|
|
||||||
|
if (!ShouldCalculate)
|
||||||
IsSuggestedActionExecutionQueued = false;
|
IsSuggestedActionExecutionQueued = false;
|
||||||
|
|
||||||
wasOpen = isOpen;
|
WasOpen = ShouldOpen;
|
||||||
return isOpen;
|
WasCollapsed = IsCollapsed;
|
||||||
|
WasCalculatable = ShouldCalculate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool DrawConditions() =>
|
||||||
|
ShouldOpen;
|
||||||
|
|
||||||
private bool wasInCraftAction;
|
private bool wasInCraftAction;
|
||||||
private bool ShouldDraw()
|
private bool CalculateShouldOpen()
|
||||||
{
|
{
|
||||||
if (Service.ClientState.LocalPlayer == null)
|
if (Service.ClientState.LocalPlayer == null)
|
||||||
return false;
|
return false;
|
||||||
@@ -174,6 +193,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
|
|||||||
{
|
{
|
||||||
base.PreDraw();
|
base.PreDraw();
|
||||||
|
|
||||||
|
IsCollapsed = true;
|
||||||
|
|
||||||
if (Service.Configuration.PinSynthHelperToWindow)
|
if (Service.Configuration.PinSynthHelperToWindow)
|
||||||
{
|
{
|
||||||
ref var unit = ref Addon->AtkUnitBase;
|
ref var unit = ref Addon->AtkUnitBase;
|
||||||
@@ -197,11 +218,15 @@ public sealed unsafe class SynthHelper : Window, IDisposable
|
|||||||
|
|
||||||
public override void PostDraw()
|
public override void PostDraw()
|
||||||
{
|
{
|
||||||
|
base.PostDraw();
|
||||||
|
|
||||||
IsSuggestedActionExecutionQueued = false;
|
IsSuggestedActionExecutionQueued = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
IsCollapsed = false;
|
||||||
|
|
||||||
DrawMacro();
|
DrawMacro();
|
||||||
|
|
||||||
DrawMacroInfo();
|
DrawMacroInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user