diff --git a/Patches/ConfirmationDialogKeysPatches.cs b/Patches/ConfirmationDialogKeysPatches.cs index b4d419d..3c35a0c 100644 --- a/Patches/ConfirmationDialogKeysPatches.cs +++ b/Patches/ConfirmationDialogKeysPatches.cs @@ -48,21 +48,21 @@ namespace UIFixes { protected override MethodBase GetTargetMethod() { - return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.TranslateCommand)); + return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.Update)); } - [PatchPrefix] - public static bool Prefix(ECommand command, ref InputNode.ETranslateResult __result, SplitDialog ___splitDialog_0) + [PatchPostfix] + public static void Postfix(SplitDialog ___splitDialog_0) { - // It's wild to me that they implement UI keyboard shortcuts via the in-raid movement keybinds - if (___splitDialog_0 != null && ___splitDialog_0.gameObject.activeSelf && command == ECommand.Jump) + if (___splitDialog_0 == null || !___splitDialog_0.gameObject.activeSelf) { - ___splitDialog_0.Accept(); - __result = InputNode.ETranslateResult.Block; - return false; + return; } - return true; + if (Input.GetKeyDown(KeyCode.Space)) + { + ___splitDialog_0.Accept(); + } } } diff --git a/Patches/ContextMenuShortcutPatch.cs b/Patches/ContextMenuShortcutPatch.cs new file mode 100644 index 0000000..3183bdd --- /dev/null +++ b/Patches/ContextMenuShortcutPatch.cs @@ -0,0 +1,56 @@ +using Aki.Reflection.Patching; +using EFT.InventoryLogic; +using EFT.UI; +using HarmonyLib; +using System.Reflection; + +namespace UIFixes +{ + public class ContextMenuShortcutPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.Update)); + } + + [PatchPostfix] + public static void Postfix(ItemUiContext __instance) + { + ItemContextAbstractClass itemContext = __instance.R().ItemContext; + if (itemContext == null) + { + return; + } + + if (Settings.InspectKeyBind.Value.IsDown()) + { + __instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Inspect); + return; + } + + if (Settings.OpenKeyBind.Value.IsDown()) + { + __instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Open); + return; + } + + if (Settings.TopUpKeyBind.Value.IsDown()) + { + __instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.TopUp); + return; + } + + if (Settings.FilterByKeyBind.Value.IsDown()) + { + __instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.FilterSearch); + return; + } + + if (Settings.LinkedSearchKeyBind.Value.IsDown()) + { + __instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.LinkedSearch); + return; + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 4285863..bd3bfc0 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -46,6 +46,7 @@ namespace UIFixes new GridWindowButtonsPatch().Enable(); new LoadMagPresetsPatch().Enable(); KeepWindowsOnScreenPatches.Enable(); + new ContextMenuShortcutPatch().Enable(); } public static bool InRaid() diff --git a/R.cs b/R.cs index 5aa1094..ffda21b 100644 --- a/R.cs +++ b/R.cs @@ -503,16 +503,19 @@ namespace UIFixes public static Type Type { get; private set; } private static FieldInfo InventoryControllerField; private static FieldInfo GridWindowTemplateField; + private static PropertyInfo ItemContextProperty; public static void InitTypes() { Type = typeof(EFT.UI.ItemUiContext); InventoryControllerField = AccessTools.GetDeclaredFields(Type).Single(t => t.FieldType == typeof(InventoryControllerClass)); GridWindowTemplateField = AccessTools.Field(Type, "_gridWindowTemplate"); + ItemContextProperty = AccessTools.GetDeclaredProperties(Type).Single(p => p.PropertyType == typeof(ItemContextAbstractClass)); } public InventoryControllerClass InventoryController { get { return (InventoryControllerClass)InventoryControllerField.GetValue(Value); } } public EFT.UI.GridWindow GridWindowTemplate { get { return (EFT.UI.GridWindow)GridWindowTemplateField.GetValue(Value); } } + public ItemContextAbstractClass ItemContext { get { return (ItemContextAbstractClass)ItemContextProperty.GetValue(Value); } } } public static class Money @@ -595,7 +598,7 @@ namespace UIFixes public class MessageWindow(object value) : UIInputNode(value) { } - public class RepairStrategy(object value) : Wrapper(value) + public class RepairStrategy(object value) : Wrapper(value) { public static Type Type { get; private set; } private static Type ArmorStrategyType; diff --git a/Settings.cs b/Settings.cs index d0700b8..cbbaa19 100644 --- a/Settings.cs +++ b/Settings.cs @@ -41,6 +41,12 @@ namespace UIFixes public static ConfigEntry UseHomeEnd { get; set; } public static ConfigEntry RebindPageUpDown { get; set; } public static ConfigEntry MouseScrollMulti { get; set; } + + public static ConfigEntry InspectKeyBind { get; set; } + public static ConfigEntry OpenKeyBind { get; set; } + public static ConfigEntry TopUpKeyBind { get; set; } + public static ConfigEntry FilterByKeyBind { get; set; } + public static ConfigEntry LinkedSearchKeyBind { get; set; } public static ConfigEntry UseRaidMouseScrollMulti { get; set; } // Advanced public static ConfigEntry MouseScrollMultiInRaid { get; set; } // Advanced @@ -161,6 +167,51 @@ namespace UIFixes new AcceptableValueRange(1, 10), new ConfigurationManagerAttributes { }))); + configEntries.Add(InspectKeyBind = config.Bind( + InputSection, + "Inspect Shortcut", + new KeyboardShortcut(KeyCode.I), + new ConfigDescription( + "Keybind to inspect an item", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(OpenKeyBind = config.Bind( + InputSection, + "Open Shortcut", + new KeyboardShortcut(KeyCode.O), + new ConfigDescription( + "Keybind to open a container", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(TopUpKeyBind = config.Bind( + InputSection, + "Top Up Ammo Shortcut", + new KeyboardShortcut(KeyCode.T), + new ConfigDescription( + "Keybind to top up an ammo stack", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(FilterByKeyBind = config.Bind( + InputSection, + "Filter by Item Shortcut", + new KeyboardShortcut(KeyCode.F), + new ConfigDescription( + "Keybind to search flea market for this item", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(LinkedSearchKeyBind = config.Bind( + InputSection, + "Linked Search Shortcut", + new KeyboardShortcut(KeyCode.L), + new ConfigDescription( + "Keybind to search flea market for items linked to this item", + null, + new ConfigurationManagerAttributes { }))); + configEntries.Add(UseRaidMouseScrollMulti = config.Bind( InputSection, "Use Different Scrolling Speed in Raid",