From bd004aea9fefc958b4d46ca969eaac4328b167ba Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:20:34 -0700 Subject: [PATCH] advanced setting for multiselect in raid; unload ammo more places --- DrawMultiSelect.cs | 2 +- MultiSelect.cs | 8 ++++++ MultiSelectDebug.cs | 2 +- Patches/MultiSelectPatches.cs | 6 ++--- Patches/UnloadAmmoPatches.cs | 50 +++++++++++++++++++++++++++++++++++ Plugin.cs | 1 + Settings.cs | 48 +++++++++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 Patches/UnloadAmmoPatches.cs diff --git a/DrawMultiSelect.cs b/DrawMultiSelect.cs index 67f2664..b56b764 100644 --- a/DrawMultiSelect.cs +++ b/DrawMultiSelect.cs @@ -49,7 +49,7 @@ namespace UIFixes public void Update() { - if (!Settings.EnableMultiSelect.Value) + if (!MultiSelect.Enabled) { return; } diff --git a/MultiSelect.cs b/MultiSelect.cs index c44e419..5a5e9bf 100644 --- a/MultiSelect.cs +++ b/MultiSelect.cs @@ -18,6 +18,14 @@ namespace UIFixes private static ItemContextTaskSerializer UnloadSerializer = null; + public static bool Enabled + { + get + { + return Settings.EnableMultiSelect.Value && (!Plugin.InRaid() || Settings.EnableMultiSelectInRaid.Value); + } + } + public static void Initialize() { // Grab the selection objects from ragfair as templates diff --git a/MultiSelectDebug.cs b/MultiSelectDebug.cs index ba5ca55..b238adf 100644 --- a/MultiSelectDebug.cs +++ b/MultiSelectDebug.cs @@ -13,7 +13,7 @@ namespace UIFixes public void OnGUI() { - if (!Settings.EnableMultiSelect.Value || !Settings.ShowMultiSelectDebug.Value) + if (!MultiSelect.Enabled || !Settings.ShowMultiSelectDebug.Value) { return; } diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index 79e02a7..54b86ac 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -92,7 +92,7 @@ namespace UIFixes [PatchPostfix] public static void Postfix(CommonUI __instance) { - if (!Settings.EnableMultiSelect.Value) + if (!MultiSelect.Enabled) { return; } @@ -131,7 +131,7 @@ namespace UIFixes [PatchPostfix] public static void Postfix(MenuUI __instance) { - if (!Settings.EnableMultiSelect.Value) + if (!MultiSelect.Enabled) { return; } @@ -150,7 +150,7 @@ namespace UIFixes [PatchPostfix] public static void Postfix(ItemView __instance, PointerEventData eventData) { - if (!Settings.EnableMultiSelect.Value || __instance is RagfairNewOfferItemView || __instance is InsuranceItemView) + if (!MultiSelect.Enabled || __instance is RagfairNewOfferItemView || __instance is InsuranceItemView) { return; } diff --git a/Patches/UnloadAmmoPatches.cs b/Patches/UnloadAmmoPatches.cs new file mode 100644 index 0000000..26e586f --- /dev/null +++ b/Patches/UnloadAmmoPatches.cs @@ -0,0 +1,50 @@ +using Aki.Reflection.Patching; +using EFT.InventoryLogic; +using HarmonyLib; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace UIFixes +{ + public static class UnloadAmmoPatches + { + public static void Enable() + { + new TradingPlayerPatch().Enable(); + new TransferPlayerPatch().Enable(); + } + + public class TradingPlayerPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.DeclaredProperty(typeof(GClass3032), nameof(GClass3032.AvailableInteractions)).GetMethod; + } + + [PatchPostfix] + public static void Postfix(ref IEnumerable __result) + { + var list = __result.ToList(); + list.Insert(list.IndexOf(EItemInfoButton.Repair), EItemInfoButton.UnloadAmmo); + __result = list; + } + } + + public class TransferPlayerPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.DeclaredProperty(typeof(GClass3035), nameof(GClass3035.AvailableInteractions)).GetMethod; + } + + [PatchPostfix] + public static void Postfix(ref IEnumerable __result) + { + var list = __result.ToList(); + list.Insert(list.IndexOf(EItemInfoButton.Fold), EItemInfoButton.UnloadAmmo); + __result = list; + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 505505f..9186fd3 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -52,6 +52,7 @@ namespace UIFixes MultiSelectPatches.Enable(); new FixUnloadLastBulletPatch().Enable(); StackMoveGreedyPatches.Enable(); + UnloadAmmoPatches.Enable(); } public static bool InRaid() diff --git a/Settings.cs b/Settings.cs index 2beeca7..5efb857 100644 --- a/Settings.cs +++ b/Settings.cs @@ -66,6 +66,7 @@ namespace UIFixes // Inventory public static ConfigEntry EnableMultiSelect { get; set; } + public static ConfigEntry EnableMultiSelectInRaid { get; set; } public static ConfigEntry SelectionBoxKey { get; set; } public static ConfigEntry MultiSelectStrat { get; set; } public static ConfigEntry ShowMultiSelectDebug { get; set; } // Advanced @@ -306,6 +307,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(EnableMultiSelectInRaid = config.Bind( + InventorySection, + "Enable Multiselect In Raid", + true, + new ConfigDescription( + "Enable multiselect functionality in raid.", + null, + new ConfigurationManagerAttributes { IsAdvanced = true }))); + configEntries.Add(SelectionBoxKey = config.Bind( InventorySection, "Selection Box Key", @@ -564,6 +574,9 @@ namespace UIFixes RecalcOrder(configEntries); MakeExclusive(EnableMultiSelect, AutoOpenSortingTable); + + MakeDependent(EnableMultiSelect, EnableMultiSelectInRaid); + MakeDependent(EnableMultiSelect, ShowMultiSelectDebug, false); } private static void RecalcOrder(List configEntries) @@ -604,5 +617,40 @@ namespace UIFixes } }; } + + private static void MakeDependent(ConfigEntry primaryConfig, ConfigEntry dependentConfig, bool primaryEnablesDependent = true) + { + if (!primaryConfig.Value) + { + dependentConfig.Value = false; + if (dependentConfig.Description.Tags[0] is ConfigurationManagerAttributes attributes) + { + attributes.ReadOnly = true; + } + } + + primaryConfig.SettingChanged += (_, _) => + { + if (primaryConfig.Value) + { + if (primaryEnablesDependent) + { + dependentConfig.Value = true; + } + } + else + { + dependentConfig.Value = false; + } + }; + + dependentConfig.SettingChanged += (_, _) => + { + if (!primaryConfig.Value) + { + dependentConfig.Value = false; + } + }; + } } }