Stop background tasks when collapsed

This commit is contained in:
Asriel Camora
2024-06-19 14:35:11 -07:00
parent 236da6c947
commit 42a692aca0
2 changed files with 62 additions and 19 deletions
+27 -9
View File
@@ -37,7 +37,6 @@ namespace Craftimizer.Windows;
public sealed unsafe class RecipeNote : Window, IDisposable
{
private const ImGuiWindowFlags WindowFlagsPinned = WindowFlagsFloating
| ImGuiWindowFlags.NoDecoration
| ImGuiWindowFlags.NoSavedSettings;
private const ImGuiWindowFlags WindowFlagsFloating =
@@ -150,13 +149,24 @@ public sealed unsafe class RecipeNote : Window, IDisposable
Service.WindowSystem.AddWindow(this);
}
private bool wasOpen;
public override bool DrawConditions()
private bool IsCollapsed { get; set; }
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();
if (isOpen != wasOpen)
base.Update();
ShouldOpen = CalculateShouldOpen();
if (ShouldCalculate != WasCalculatable)
{
if (wasOpen)
if (WasCalculatable)
{
SavedMacroTask?.Cancel();
SuggestedMacroTask?.Cancel();
@@ -190,12 +200,16 @@ public sealed unsafe class RecipeNote : Window, IDisposable
}
}
wasOpen = isOpen;
return isOpen;
WasOpen = ShouldOpen;
WasCollapsed = IsCollapsed;
WasCalculatable = ShouldCalculate;
}
public override bool DrawConditions() =>
ShouldOpen;
private bool StatsChanged { get; set; }
private bool ShouldDraw()
private bool CalculateShouldOpen()
{
if (Service.ClientState.LocalPlayer == null)
return false;
@@ -292,6 +306,8 @@ public sealed unsafe class RecipeNote : Window, IDisposable
{
base.PreDraw();
IsCollapsed = true;
if (Service.Configuration.PinRecipeNoteToWindow)
{
ref var unit = ref Addon->AtkUnitBase;
@@ -316,6 +332,8 @@ public sealed unsafe class RecipeNote : Window, IDisposable
public override void Draw()
{
IsCollapsed = false;
var availWidth = ImGui.GetContentRegionAvail().X;
using (var table = ImRaii.Table("stats", 2, ImGuiTableFlags.BordersInnerV | ImGuiTableFlags.SizingFixedSame | ImGuiTableFlags.NoSavedSettings))
{