Stoppable multi-unload in raid
This commit is contained in:
@@ -16,6 +16,8 @@ namespace UIFixes
|
||||
private static readonly Dictionary<ItemContextClass, GridItemView> SelectedItems = [];
|
||||
private static readonly Dictionary<ItemContextClass, GridItemView> SecondaryItems = [];
|
||||
|
||||
private static ItemContextTaskSerializer UnloadSerializer = null;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
// Grab the selection objects from ragfair as templates
|
||||
@@ -257,14 +259,29 @@ namespace UIFixes
|
||||
|
||||
public static void UnloadAmmoAll(ItemUiContext itemUiContext, bool allOrNothing)
|
||||
{
|
||||
StopUnloading();
|
||||
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>();
|
||||
taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.UnloadAmmo(itemContext.Item));
|
||||
|
||||
UnloadSerializer = taskSerializer;
|
||||
itemUiContext.Tooltip?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void StopUnloading()
|
||||
{
|
||||
if (UnloadSerializer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UnloadSerializer.Cancel();
|
||||
UnloadSerializer = null;
|
||||
}
|
||||
|
||||
private static void ShowSelection(GridItemView itemView)
|
||||
{
|
||||
GameObject selectedMark = itemView.transform.Find("SelectedMark")?.gameObject;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using Aki.Reflection.Patching;
|
||||
using Aki.Reflection.Utils;
|
||||
using Comfort.Common;
|
||||
using EFT;
|
||||
using EFT.Communications;
|
||||
using EFT.InventoryLogic;
|
||||
using EFT.UI;
|
||||
@@ -55,6 +55,7 @@ namespace UIFixes
|
||||
// Actions
|
||||
new ItemViewClickPatch().Enable();
|
||||
new ContextActionsPatch().Enable();
|
||||
new StopProcessesPatch().Enable();
|
||||
|
||||
// GridView
|
||||
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
|
||||
public class DeselectOnTradingItemViewClickPatch : ModulePatch
|
||||
{
|
||||
|
@@ -26,9 +26,20 @@ namespace UIFixes
|
||||
return totalTask.Task;
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
totalTask.TrySetCanceled();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!currentTask.IsCompleted)
|
||||
if (currentTask.IsCanceled)
|
||||
{
|
||||
Complete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalTask.Task.IsCompleted || !currentTask.IsCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -38,11 +49,16 @@ namespace UIFixes
|
||||
currentTask = func(items.Dequeue());
|
||||
}
|
||||
else
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
|
||||
private void Complete()
|
||||
{
|
||||
totalTask.Complete();
|
||||
func = null;
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user