From 6da8800d97f0f67a956a38de9594c92e44f9b755 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Fri, 31 May 2024 16:20:59 -0700 Subject: [PATCH] Keep quantity focused after purchase --- Patches/FocusTradeQuantityPatch.cs | 26 ++++++++++++++++++++++++++ Plugin.cs | 1 + 2 files changed, 27 insertions(+) create mode 100644 Patches/FocusTradeQuantityPatch.cs diff --git a/Patches/FocusTradeQuantityPatch.cs b/Patches/FocusTradeQuantityPatch.cs new file mode 100644 index 0000000..54f9778 --- /dev/null +++ b/Patches/FocusTradeQuantityPatch.cs @@ -0,0 +1,26 @@ +using Aki.Reflection.Patching; +using EFT.UI; +using HarmonyLib; +using System.Reflection; +using TMPro; + +namespace UIFixes +{ + public class FocusTradeQuantityPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BarterSchemePanel), nameof(BarterSchemePanel.method_10)); + } + + // Gets called on the TransactionChanged event. + // The reason quantity isn't focused on the 2nd+ purchase is that BSG calls ActivateInputField() and Select() before the transaction is finished + // During the transaction, the whole canvas group is not interactable, and these methods don't work on non-interactable fields + [PatchPostfix] + public static void Postfix(TMP_InputField ____quantity) + { + ____quantity.ActivateInputField(); + ____quantity.Select(); + } + } +} diff --git a/Plugin.cs b/Plugin.cs index f179c89..3dfa222 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -41,6 +41,7 @@ namespace UIFixes TradingAutoSwitchPatches.Enable(); AddOfferRememberAutoselectPatches.Enable(); KeepMessagesOpenPatches.Enable(); + new FocusTradeQuantityPatch().Enable(); } public static bool InRaid()