Fix add offer window

This commit is contained in:
Tyfon
2024-07-07 16:29:35 -07:00
parent 1ed8b9d7f4
commit 9530cb9f18

View File

@@ -59,24 +59,33 @@ namespace UIFixes
[PatchPrefix] [PatchPrefix]
public static void Prefix(AddOfferWindow __instance, TaskCompletionSource ___taskCompletionSource_0, ref TaskCompletionSource __state) public static void Prefix(AddOfferWindow __instance, TaskCompletionSource ___taskCompletionSource_0, ref TaskCompletionSource __state)
{ {
if (Settings.KeepAddOfferOpen.Value) if (!Settings.KeepAddOfferOpen.Value)
{ {
__state = ___taskCompletionSource_0; return;
}
// Close the window if you're gonna hit max offers __state = ___taskCompletionSource_0;
var ragfair = __instance.R().Ragfair;
if (Settings.KeepAddOfferOpenIgnoreMaxOffers.Value || ragfair.MyOffersCount + 1 < ragfair.GetMaxOffersCount(ragfair.MyRating)) // Close the window if you're gonna hit max offers
{ var ragfair = __instance.R().Ragfair;
BlockClose = true; if (Settings.KeepAddOfferOpenIgnoreMaxOffers.Value || ragfair.MyOffersCount + 1 < ragfair.GetMaxOffersCount(ragfair.MyRating))
} {
BlockClose = true;
} }
} }
[PatchPostfix] [PatchPostfix]
public static void Postfix(RequirementView[] ____requirementViews, TaskCompletionSource ___taskCompletionSource_0, ref TaskCompletionSource __state) public static void Postfix(RequirementView[] ____requirementViews, TaskCompletionSource ___taskCompletionSource_0, ref TaskCompletionSource __state)
{ {
bool isAddingOffer = __state != ___taskCompletionSource_0; // If the taskCompletionSource member was changed, then it's adding an offer :S BlockClose = false;
if (Settings.KeepAddOfferOpen.Value && isAddingOffer)
if (!Settings.KeepAddOfferOpen.Value)
{
return;
}
// If the taskCompletionSource member was changed, then it's adding an offer :S
if (__state != ___taskCompletionSource_0)
{ {
AddOfferTasks.Add(__state.Task); // This is the task completion source passed into the add offer call AddOfferTasks.Add(__state.Task); // This is the task completion source passed into the add offer call
@@ -86,8 +95,6 @@ namespace UIFixes
requirementView.ResetRequirementInformation(); requirementView.ResetRequirementInformation();
} }
} }
BlockClose = false;
} }
} }
@@ -101,7 +108,12 @@ namespace UIFixes
[PatchPrefix] [PatchPrefix]
public static bool Prefix() public static bool Prefix()
{ {
if (!BlockClose && AddOfferTasks.All(t => t.IsCompleted)) if (!Settings.KeepAddOfferOpen.Value)
{
return true;
}
if (!BlockClose && CompletionSource != null && AddOfferTasks.All(t => t.IsCompleted))
{ {
CompletionSource.Complete(); CompletionSource.Complete();
CompletionSource = null; CompletionSource = null;