Stoppable multi-unload in raid

This commit is contained in:
Tyfon
2024-06-21 11:49:40 -07:00
parent 936c3fad54
commit 26ba6810ad
3 changed files with 53 additions and 5 deletions

View File

@@ -16,6 +16,8 @@ namespace UIFixes
private static readonly Dictionary<ItemContextClass, GridItemView> SelectedItems = []; private static readonly Dictionary<ItemContextClass, GridItemView> SelectedItems = [];
private static readonly Dictionary<ItemContextClass, GridItemView> SecondaryItems = []; private static readonly Dictionary<ItemContextClass, GridItemView> SecondaryItems = [];
private static ItemContextTaskSerializer UnloadSerializer = null;
public static void Initialize() public static void Initialize()
{ {
// Grab the selection objects from ragfair as templates // Grab the selection objects from ragfair as templates
@@ -257,14 +259,29 @@ namespace UIFixes
public static void UnloadAmmoAll(ItemUiContext itemUiContext, bool allOrNothing) public static void UnloadAmmoAll(ItemUiContext itemUiContext, bool allOrNothing)
{ {
StopUnloading();
if (!allOrNothing || InteractionCount(EItemInfoButton.UnloadAmmo, itemUiContext) == Count) if (!allOrNothing || InteractionCount(EItemInfoButton.UnloadAmmo, itemUiContext) == Count)
{ {
// Call Initialize() before setting UnloadSerializer so that the initial synchronous call to StopProcesses()->StopUnloading() doesn't immediately cancel this
var taskSerializer = itemUiContext.GetOrAddComponent<ItemContextTaskSerializer>(); var taskSerializer = itemUiContext.GetOrAddComponent<ItemContextTaskSerializer>();
taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.UnloadAmmo(itemContext.Item)); taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.UnloadAmmo(itemContext.Item));
UnloadSerializer = taskSerializer;
itemUiContext.Tooltip?.Close(); itemUiContext.Tooltip?.Close();
} }
} }
public static void StopUnloading()
{
if (UnloadSerializer == null)
{
return;
}
UnloadSerializer.Cancel();
UnloadSerializer = null;
}
private static void ShowSelection(GridItemView itemView) private static void ShowSelection(GridItemView itemView)
{ {
GameObject selectedMark = itemView.transform.Find("SelectedMark")?.gameObject; GameObject selectedMark = itemView.transform.Find("SelectedMark")?.gameObject;

View File

@@ -1,6 +1,6 @@
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using Comfort.Common; using Comfort.Common;
using EFT;
using EFT.Communications; using EFT.Communications;
using EFT.InventoryLogic; using EFT.InventoryLogic;
using EFT.UI; using EFT.UI;
@@ -55,6 +55,7 @@ namespace UIFixes
// Actions // Actions
new ItemViewClickPatch().Enable(); new ItemViewClickPatch().Enable();
new ContextActionsPatch().Enable(); new ContextActionsPatch().Enable();
new StopProcessesPatch().Enable();
// GridView // GridView
new GridViewCanAcceptPatch().Enable(); new GridViewCanAcceptPatch().Enable();
@@ -296,6 +297,20 @@ namespace UIFixes
} }
} }
public class StopProcessesPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(Player.PlayerInventoryController), nameof(Player.PlayerInventoryController.StopProcesses));
}
[PatchPostfix]
public static void Postfix()
{
MultiSelect.StopUnloading();
}
}
// TradingItemView overrides GridItemView.OnClick and doesn't call base // TradingItemView overrides GridItemView.OnClick and doesn't call base
public class DeselectOnTradingItemViewClickPatch : ModulePatch public class DeselectOnTradingItemViewClickPatch : ModulePatch
{ {

View File

@@ -26,9 +26,20 @@ namespace UIFixes
return totalTask.Task; return totalTask.Task;
} }
public void Cancel()
{
totalTask.TrySetCanceled();
}
public void Update() public void Update()
{ {
if (!currentTask.IsCompleted) if (currentTask.IsCanceled)
{
Complete();
return;
}
if (totalTask.Task.IsCompleted || !currentTask.IsCompleted)
{ {
return; return;
} }
@@ -38,6 +49,12 @@ namespace UIFixes
currentTask = func(items.Dequeue()); currentTask = func(items.Dequeue());
} }
else else
{
Complete();
}
}
private void Complete()
{ {
totalTask.Complete(); totalTask.Complete();
func = null; func = null;
@@ -45,4 +62,3 @@ namespace UIFixes
} }
} }
} }
}