Misc fixes and move lifecycles
This commit is contained in:
@@ -78,11 +78,12 @@ public unsafe class AddonInventoryWindow : InventoryAddonBase
|
||||
|
||||
LayoutContent();
|
||||
|
||||
Services.AddonLifecycle.RegisterListener(AddonEvent.PostRequestedUpdate, "Inventory", OnInventoryUpdate);
|
||||
addon->SubscribeAtkArrayData(1, (int)NumberArrayType.Inventory);
|
||||
|
||||
_isSetupComplete = true;
|
||||
|
||||
_inventoryState.RefreshFromGame();
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
|
||||
base.OnSetup(addon);
|
||||
}
|
||||
@@ -107,12 +108,6 @@ public unsafe class AddonInventoryWindow : InventoryAddonBase
|
||||
FooterNode.RefreshCurrencies();
|
||||
}
|
||||
|
||||
private void OnInventoryUpdate(AddonEvent type, AddonArgs args)
|
||||
{
|
||||
_inventoryState.RefreshFromGame();
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
}
|
||||
|
||||
protected override void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArrayData, StringArrayData** stringArrayData)
|
||||
{
|
||||
base.OnRequestedUpdate(addon, numberArrayData, stringArrayData);
|
||||
@@ -146,9 +141,9 @@ public unsafe class AddonInventoryWindow : InventoryAddonBase
|
||||
RaptureAtkModule.Instance()->CloseAddon(blockingAddonId);
|
||||
}
|
||||
|
||||
Services.AddonLifecycle.UnregisterListener(OnInventoryUpdate);
|
||||
addon->UnsubscribeAtkArrayData(1, (int)NumberArrayType.Inventory);
|
||||
|
||||
_isSetupComplete = false;
|
||||
base.OnFinalize(addon);
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,9 @@ public unsafe class AddonRetainerWindow : InventoryAddonBase
|
||||
|
||||
LayoutContent();
|
||||
|
||||
Services.AddonLifecycle.RegisterListener(AddonEvent.PostRequestedUpdate, ["InventoryRetainer", "InventoryRetainerLarge"], OnRetainerInventoryUpdate);
|
||||
|
||||
_inventoryState.RefreshFromGame();
|
||||
_isSetupComplete = true;
|
||||
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
|
||||
base.OnSetup(addon);
|
||||
@@ -119,7 +119,10 @@ public unsafe class AddonRetainerWindow : InventoryAddonBase
|
||||
|
||||
protected override void RefreshCategoriesCore(bool autosize)
|
||||
{
|
||||
_slotCounterNode. String = _inventoryState.GetEmptySlotsString();
|
||||
if (!_isSetupComplete)
|
||||
return;
|
||||
|
||||
_slotCounterNode.String = _inventoryState.GetEmptySlotsString();
|
||||
_retainerNameNode.String = RetainerState.CurrentRetainerName;
|
||||
|
||||
base.RefreshCategoriesCore(autosize);
|
||||
@@ -165,12 +168,6 @@ public unsafe class AddonRetainerWindow : InventoryAddonBase
|
||||
agent->SendCommand(0, [0]);
|
||||
}
|
||||
|
||||
private void OnRetainerInventoryUpdate(AddonEvent type, AddonArgs args)
|
||||
{
|
||||
_inventoryState.RefreshFromGame();
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
}
|
||||
|
||||
protected override void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArrayData, StringArrayData** stringArrayData)
|
||||
{
|
||||
base.OnRequestedUpdate(addon, numberArrayData, stringArrayData);
|
||||
@@ -190,8 +187,7 @@ public unsafe class AddonRetainerWindow : InventoryAddonBase
|
||||
|
||||
protected override void OnFinalize(AtkUnitBase* addon)
|
||||
{
|
||||
Services.AddonLifecycle.UnregisterListener(OnRetainerInventoryUpdate);
|
||||
|
||||
_isSetupComplete = false;
|
||||
base.OnFinalize(addon);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,6 @@ using AetherBags.Inventory.State;
|
||||
using AetherBags.Nodes.Input;
|
||||
using AetherBags.Nodes.Inventory;
|
||||
using AetherBags.Nodes.Layout;
|
||||
using Dalamud.Game.Addon.Lifecycle;
|
||||
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using KamiToolKit.Classes;
|
||||
using KamiToolKit.Nodes;
|
||||
@@ -84,9 +81,10 @@ public unsafe class AddonSaddleBagWindow : InventoryAddonBase
|
||||
|
||||
LayoutContent();
|
||||
|
||||
Services.AddonLifecycle.RegisterListener(AddonEvent.PostRequestedUpdate, "InventoryBuddy", OnSaddleBagUpdate);
|
||||
|
||||
_inventoryState.RefreshFromGame();
|
||||
|
||||
_isSetupComplete = true;
|
||||
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
|
||||
base.OnSetup(addon);
|
||||
@@ -94,6 +92,9 @@ public unsafe class AddonSaddleBagWindow : InventoryAddonBase
|
||||
|
||||
protected override void RefreshCategoriesCore(bool autosize)
|
||||
{
|
||||
if (!_isSetupComplete)
|
||||
return;
|
||||
|
||||
_slotCounterNode.String = _inventoryState.GetEmptySlotsString();
|
||||
|
||||
base.RefreshCategoriesCore(autosize);
|
||||
@@ -113,12 +114,6 @@ public unsafe class AddonSaddleBagWindow : InventoryAddonBase
|
||||
base.OnUpdate(addon);
|
||||
}
|
||||
|
||||
private void OnSaddleBagUpdate(AddonEvent type, AddonArgs args)
|
||||
{
|
||||
_inventoryState.RefreshFromGame();
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
}
|
||||
|
||||
protected override void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArrayData, StringArrayData** stringArrayData)
|
||||
{
|
||||
base.OnRequestedUpdate(addon, numberArrayData, stringArrayData);
|
||||
@@ -138,8 +133,7 @@ public unsafe class AddonSaddleBagWindow : InventoryAddonBase
|
||||
|
||||
protected override void OnFinalize(AtkUnitBase* addon)
|
||||
{
|
||||
Services.AddonLifecycle.UnregisterListener(OnSaddleBagUpdate);
|
||||
|
||||
_isSetupComplete = false;
|
||||
base.OnFinalize(addon);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public abstract unsafe class InventoryAddonBase : NativeAddon
|
||||
protected bool RefreshQueued;
|
||||
protected bool RefreshAutosizeQueued;
|
||||
private bool _isRefreshing;
|
||||
protected bool _isSetupComplete;
|
||||
|
||||
protected abstract InventoryStateBase InventoryState { get; }
|
||||
|
||||
@@ -50,6 +51,8 @@ public abstract unsafe class InventoryAddonBase : NativeAddon
|
||||
if (!IsOpen) return;
|
||||
if (!Services.ClientState.IsLoggedIn) return;
|
||||
if (_isRefreshing) return;
|
||||
if (!_isSetupComplete) return;
|
||||
|
||||
try
|
||||
{
|
||||
_isRefreshing = true;
|
||||
@@ -72,8 +75,29 @@ public abstract unsafe class InventoryAddonBase : NativeAddon
|
||||
}, delayTicks: 2);
|
||||
}
|
||||
|
||||
public void RefreshFromLifecycle()
|
||||
{
|
||||
if (!_isSetupComplete) return;
|
||||
if (!IsOpen) return;
|
||||
if (_isRefreshing) return;
|
||||
|
||||
try
|
||||
{
|
||||
_isRefreshing = true;
|
||||
InventoryState.RefreshFromGame();
|
||||
RefreshCategoriesCore(autosize: true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RefreshCategoriesCore(bool autosize)
|
||||
{
|
||||
if (!_isSetupComplete)
|
||||
return;
|
||||
|
||||
if (HasFooter)
|
||||
{
|
||||
FooterNode.SlotAmountText = InventoryState.GetEmptySlotsString();
|
||||
|
||||
Reference in New Issue
Block a user