diff --git a/Patches/DialogPatches.cs b/Patches/DialogPatches.cs new file mode 100644 index 0000000..9ce3c82 --- /dev/null +++ b/Patches/DialogPatches.cs @@ -0,0 +1,66 @@ +using Aki.Reflection.Patching; +using EFT.InventoryLogic; +using EFT.UI; +using EFT.UI.Ragfair; +using HarmonyLib; +using System; +using System.Linq; +using System.Reflection; +using TMPro; +using UnityEngine; + +namespace UIFixes +{ + public class DialogPatches + { + public static void Enable() + { + new DialogWindowPatch().Enable(); + new FleaPurchaseDialogPatch().Enable(); + } + + private class DialogWindowPatch : ModulePatch + { + private static MethodInfo AcceptMethod; + + protected override MethodBase GetTargetMethod() + { + Type dialogWindowType = typeof(MessageWindow).BaseType; + AcceptMethod = AccessTools.Method(dialogWindowType, "Accept"); + + return AccessTools.Method(dialogWindowType, "Update"); + } + + [PatchPostfix] + private static void Postfix(object __instance, bool ___bool_0) + { + if (!___bool_0) + { + return; + } + + if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) + { + AcceptMethod.Invoke(__instance, []); + return; + } + } + } + + private class FleaPurchaseDialogPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + // The parent has a Show() so need to be specific + return typeof(HandoverRagfairMoneyWindow).GetMethods().First(m => m.Name == "Show" && m.GetParameters()[0].ParameterType == typeof(Inventory)); + } + + [PatchPostfix] + private static void Postfix(TMP_InputField ____inputField) + { + ____inputField.Select(); + ____inputField.ActivateInputField(); + } + } + } +} diff --git a/Patches/EditBuildScreenPatch.cs b/Patches/EditBuildScreenPatch.cs index 13b4079..1dbdc4a 100644 --- a/Patches/EditBuildScreenPatch.cs +++ b/Patches/EditBuildScreenPatch.cs @@ -19,6 +19,7 @@ namespace UIFixes new ConfirmDiscardPatch().Enable(); } + // This patch just caches whether this navigation is a forward navigation, which determines if the preset is actually closing public class CloseScreenInterruptionPatch : ModulePatch { protected override MethodBase GetTargetMethod() @@ -45,12 +46,12 @@ namespace UIFixes [PatchPrefix] private static bool Prefix(ref Task __result) { - if (MoveForward && Settings.WeaponPresetConfirmOnNavigate.Value) + if (MoveForward && Settings.ShowPresetConfirmations.Value == WeaponPresetConfirmationOption.Always) { return true; } - if (!MoveForward && Settings.WeaponPresetConfirmOnClose.Value) + if (!MoveForward && Settings.ShowPresetConfirmations.Value != WeaponPresetConfirmationOption.Never) { return true; } diff --git a/Patches/TransferConfirmPatch.cs b/Patches/TransferConfirmPatch.cs index 5535c56..ce630d1 100644 --- a/Patches/TransferConfirmPatch.cs +++ b/Patches/TransferConfirmPatch.cs @@ -17,7 +17,7 @@ namespace UIFixes [PatchPrefix] private static bool Prefix(ref Task __result) { - if (Settings.TransferConfirmOnClose.Value) + if (Settings.ShowTransferConfirmations.Value == TransferConfirmationOption.Always) { return true; } diff --git a/Plugin.cs b/Plugin.cs index 3fd0c43..ac79d31 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -20,6 +20,7 @@ namespace UIFixes new TooltipPatch().Enable(); ItemPanelPatches.Enable(); new ContainerStackPatch().Enable(); + DialogPatches.Enable(); } } } diff --git a/Settings.cs b/Settings.cs index 95b5909..72308a3 100644 --- a/Settings.cs +++ b/Settings.cs @@ -1,44 +1,173 @@ using BepInEx.Configuration; +using System.Collections.Generic; +using System.ComponentModel; namespace UIFixes { + internal enum WeaponPresetConfirmationOption + { + Never, + [Description("On Close")] + OnClose, + Always + } + + internal enum TransferConfirmationOption + { + Never, + Always + } + internal class Settings { // Categories - private const string WeaponPresets = "Weapon Presets"; - private const string TransferItems = "Transfer Items"; - private const string Inventory = "Inventory"; - private const string InRaid = "In Raid"; - private const string Items = "Items"; - private const string ContainerStacking = "Containers autostack FiR and non-FiR"; + private const string GeneralSection = "1. General"; + private const string InputSection = "2. Input"; + private const string InventorySection = "3. Inventory"; + private const string InRaidSection = "4. In Raid"; - public static ConfigEntry WeaponPresetConfirmOnNavigate { get; set; } - public static ConfigEntry WeaponPresetConfirmOnClose { get; set; } - public static ConfigEntry TransferConfirmOnClose { get; set; } + // General + public static ConfigEntry ShowPresetConfirmations { get; set; } + public static ConfigEntry ShowTransferConfirmations { get; set; } + public static ConfigEntry ShowModStats { get; set; } + + // Input public static ConfigEntry UseHomeEnd { get; set; } public static ConfigEntry RebindPageUpDown { get; set; } public static ConfigEntry MouseScrollMulti { get; set; } - public static ConfigEntry RemoveDisabledActions { get; set; } + + // Inventory public static ConfigEntry SwapItems { get; set; } - public static ConfigEntry ShowModStats { get; set; } public static ConfigEntry MergeFIRMoney { get; set; } public static ConfigEntry MergeFIRAmmo { get; set; } public static ConfigEntry MergeFIROther { get; set; } + // In Raid + public static ConfigEntry RemoveDisabledActions { get; set; } + public static void Init(ConfigFile config) { - WeaponPresetConfirmOnNavigate = config.Bind(WeaponPresets, "Confirm on screen change", false, "Whether to confirm unsaved changes when you change screens without closing the preset"); - WeaponPresetConfirmOnClose = config.Bind(WeaponPresets, "Confirm on close", true, "Whether to still confirm unsaved changes when you actually close the preset"); - TransferConfirmOnClose = config.Bind(TransferItems, "Confirm untransfered items", false, "Whether to pointlessly confirm that you're leaving the item transfer with literally no consequences"); - UseHomeEnd = config.Bind(Inventory, "Add support for Home and End", true, "Home and End will scroll to the top and bottom of lists"); - RebindPageUpDown = config.Bind(Inventory, "Use normal PageUp and PageDown (requires restart)", true, "Changes PageUp and PageDown to simply page up and down, not scroll all the way to top and bottom"); - MouseScrollMulti = config.Bind(Inventory, "Mousewheel scrolling multiplier", 1, "How many rows to scroll with the mousewheel"); - SwapItems = config.Bind(Inventory, "In-place item swapping", true); - RemoveDisabledActions = config.Bind(InRaid, "Hide unimplemented actions", false, "Hides actions you can't actually do, like \"Bang and Clear\", etc from locked doors and other interactable objects"); - ShowModStats = config.Bind(Items, "Show total mod stats", true, "Item mods will show stats that include mods attached to them (you can also control this from a mod's inspect window)"); - MergeFIRMoney = config.Bind(ContainerStacking, "Money", true, "Allows automatic stacking of Found In Raid money with other money, making container interaction easier"); - MergeFIRAmmo = config.Bind(ContainerStacking, "Ammo", false, "Allows automatic stacking of Found In Raid ammo with other ammo, making container interaction easier"); - MergeFIROther = config.Bind(ContainerStacking, "Other", false, "Allows automatic stacking of all other Found In Raid items with other items, making container interaction easier"); + var configEntries = new List(); + + // General + configEntries.Add(ShowPresetConfirmations = config.Bind( + GeneralSection, + "Show Weapon Preset Confirmation Dialog", + WeaponPresetConfirmationOption.OnClose, + new ConfigDescription( + "When to show a confirmation dialog when you leave and/or close an unsaved weapon preset", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(ShowTransferConfirmations = config.Bind( + GeneralSection, + "Show Transfer Items Confirmation Dialog", + TransferConfirmationOption.Never, + new ConfigDescription( + "When to show the confirmation dialog when you close the item transfer screen without taking all the items", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(ShowModStats = config.Bind( + GeneralSection, + "Show Total Stats on Mods", + true, + new ConfigDescription( + "Item mods will show stats that include mods attached to them (you can also control this from a mod's inspect window)", + null, + new ConfigurationManagerAttributes { }))); + + // Input + configEntries.Add(UseHomeEnd = config.Bind( + InputSection, + "Enable Home/End Keys", + true, + new ConfigDescription( + "Use the Home and End keys to scroll to the top and bottom of inventories", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(RebindPageUpDown = config.Bind( + InputSection, + "Rebind PageUp/PageDown (requires restart)", + true, + new ConfigDescription( + "Change PageUp and PageDown to scroll up and down one page", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(MouseScrollMulti = config.Bind( + InputSection, + "Mousewheel Scrolling Speed", + 1, + new ConfigDescription( + "How many rows to scroll with the mousewheel", + new AcceptableValueRange(1, 10), + new ConfigurationManagerAttributes { }))); + + // Inventory + configEntries.Add(SwapItems = config.Bind( + InventorySection, + "Enable In-Place Item Swapping", + true, + new ConfigDescription( + "Drag one item onto another to swap their positions, if possible", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(MergeFIRMoney = config.Bind( + InventorySection, + "Autostack Money with FiR Money", + true, + new ConfigDescription( + "Allows automatic stacking of Found In Raid money with other money, making container interaction easier", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(MergeFIRAmmo = config.Bind( + InventorySection, + "Autostack Ammo with FiR Ammo", + false, + new ConfigDescription( + "Allows automatic stacking of Found In Raid ammo with other money, making container interaction easier", + null, + new ConfigurationManagerAttributes { }))); + + configEntries.Add(MergeFIROther = config.Bind( + InventorySection, + "Autostack Items with FiR Items", + false, + new ConfigDescription( + "Allows automatic stacking of Found In Raid items with other items, making container interaction easier", + null, + new ConfigurationManagerAttributes { }))); + + // In Raid + configEntries.Add(RemoveDisabledActions = config.Bind( + InRaidSection, + "Hide Unimplemented Door Actions", + true, + new ConfigDescription( + "Hides actions you can't actually do, like \"Bang and Clear\", etc from locked doors", + null, + new ConfigurationManagerAttributes { }))); + + RecalcOrder(configEntries); + } + private static void RecalcOrder(List configEntries) + { + // Set the Order field for all settings, to avoid unnecessary changes when adding new settings + int settingOrder = configEntries.Count; + foreach (var entry in configEntries) + { + ConfigurationManagerAttributes attributes = entry.Description.Tags[0] as ConfigurationManagerAttributes; + if (attributes != null) + { + attributes.Order = settingOrder; + } + + settingOrder--; + } } } }