diff --git a/Patches/QuickAccessPanelPatches.cs b/Patches/QuickAccessPanelPatches.cs index 4a3ebae..e5ade8e 100644 --- a/Patches/QuickAccessPanelPatches.cs +++ b/Patches/QuickAccessPanelPatches.cs @@ -16,6 +16,7 @@ namespace UIFixes { new FixWeaponBindsDisplayPatch().Enable(); new FixVisibilityPatch().Enable(); + new TranslateCommandHackPatch().Enable(); } public class FixWeaponBindsDisplayPatch : ModulePatch @@ -46,24 +47,33 @@ namespace UIFixes public class FixVisibilityPatch : ModulePatch { + public static bool Ignorable = false; + protected override MethodBase GetTargetMethod() { return AccessTools.Method(typeof(InventoryScreenQuickAccessPanel), nameof(InventoryScreenQuickAccessPanel.method_4)); } - // BSGs implementation of this method is just straight up wrong, so reimplementing it + // This method is a mess. The visibility setting has to be ignored in some cases, respected in others + // In most calls, visible=true must be followed regardless of setting preference, e.g. mag selection + // When coming from translatecommand, which is when you hit a quickbind key, visible=true can be ignored if the setting is never + // Ironically this is also the only time that autohide matters, since the other places will explicitly call hide + // visible=false can always be ignored if setting is always [PatchPrefix] public static bool Prefix(InventoryScreenQuickAccessPanel __instance, bool visible) { GameSetting quickSlotsVisibility = Singleton.Instance.Game.Settings.QuickSlotsVisibility; - bool disabled = __instance.IsDisabled; - if (visible && !disabled && quickSlotsVisibility != EVisibilityMode.Never) + bool shouldShow = visible && !__instance.IsDisabled; + bool blocked = Ignorable && quickSlotsVisibility == EVisibilityMode.Never; + + if (shouldShow && !blocked) { - __instance.AnimatedShow(quickSlotsVisibility == EVisibilityMode.Autohide); + bool autohide = Ignorable && quickSlotsVisibility == EVisibilityMode.Autohide; + __instance.AnimatedShow(autohide); } - else + else if (!shouldShow && quickSlotsVisibility != EVisibilityMode.Always) { __instance.AnimatedHide(); } @@ -71,5 +81,25 @@ namespace UIFixes return false; } } + + public class TranslateCommandHackPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(InventoryScreenQuickAccessPanel), nameof(InventoryScreenQuickAccessPanel.TranslateCommand)); + } + + [PatchPrefix] + public static void Prefix(ECommand command) + { + FixVisibilityPatch.Ignorable = GClass3032.SlotBySelectCommandDictionary.ContainsKey(command); + } + + [PatchPostfix] + public static void Postfix() + { + FixVisibilityPatch.Ignorable = false; + } + } } }