diff --git a/Multiselect/DrawMultiSelect.cs b/Multiselect/DrawMultiSelect.cs index b307c09..ca97287 100644 --- a/Multiselect/DrawMultiSelect.cs +++ b/Multiselect/DrawMultiSelect.cs @@ -4,6 +4,7 @@ using EFT.UI.DragAndDrop; using System; using System.Collections.Generic; using System.Linq; +using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -69,7 +70,7 @@ namespace UIFixes foreach (GameObject gameObject in results.Select(r => r.gameObject)) { var draggables = gameObject.GetComponents() - .Where(c => c is IDragHandler || c is IBeginDragHandler) + .Where(c => c is IDragHandler || c is IBeginDragHandler || c is TextMeshProUGUI) // tmp_inputfield is draggable, but textmesh isn't so explicitly include .Where(c => c is not ScrollRectNoDrag) // this disables scrolling, it doesn't add it .Where(c => c.name != "Inner"); // there's a random DragTrigger sitting in ItemInfoWindows diff --git a/Patches/ContextMenuPatches.cs b/Patches/ContextMenuPatches.cs index a47d38f..c92ba59 100644 --- a/Patches/ContextMenuPatches.cs +++ b/Patches/ContextMenuPatches.cs @@ -76,6 +76,8 @@ namespace UIFixes new ChangeInteractionButtonCreationPatch().Enable(); new EnableInsureInnerItemsPatch().Enable(); + + new DisableLoadPresetOnBulletsPatch().Enable(); } public class ContextMenuNamesPatch : ModulePatch @@ -137,6 +139,14 @@ namespace UIFixes ____text.text += " (x" + count + ")"; } } + else if (caption == EItemInfoButton.ApplyMagPreset.ToString()) + { + int count = MultiSelect.InteractionCount(EItemInfoButton.ApplyMagPreset, ItemUiContext.Instance); + if (count > 0) + { + ____text.text += " (x" + count + ")"; + } + } else if (caption == EItemInfoButton.Unpack.ToString()) { int count = MultiSelect.InteractionCount(EItemInfoButton.Unpack, ItemUiContext.Instance); @@ -384,6 +394,31 @@ namespace UIFixes } } + public class DisableLoadPresetOnBulletsPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(MagazineBuildClass), nameof(MagazineBuildClass.TryFindPresetSource)); + } + + [PatchPrefix] + public static bool Prefix(Item selectedItem, ref GStruct416 __result) + { + if (Settings.LoadMagPresetOnBullets.Value) + { + return true; + } + + if (selectedItem is BulletClass) + { + __result = new MagazineBuildClass.Class3135(selectedItem); + return false; + } + + return true; + } + } + private static int GetPlayerRubles(ItemUiContext itemUiContext) { StashClass stash = itemUiContext.R().InventoryController.Inventory.Stash; diff --git a/Patches/LoadMultipleMagazinesPatches.cs b/Patches/LoadMultipleMagazinesPatches.cs index c30dc83..068a705 100644 --- a/Patches/LoadMultipleMagazinesPatches.cs +++ b/Patches/LoadMultipleMagazinesPatches.cs @@ -5,6 +5,7 @@ using HarmonyLib; using System.Linq; using System.Reflection; using System.Threading.Tasks; +using UnityEngine; namespace UIFixes { @@ -15,8 +16,10 @@ namespace UIFixes public static void Enable() { new FindCompatibleAmmoPatch().Enable(); - new CheckCompatibilityPatch().Enable(); + new CheckItemFilterPatch().Enable(); new LoadAmmoPatch().Enable(); + new FilterMagPresetsPatch().Enable(); + new LoadPresetPatch().Enable(); } public class FindCompatibleAmmoPatch : ModulePatch @@ -46,23 +49,22 @@ namespace UIFixes } } - public class CheckCompatibilityPatch : ModulePatch + public class CheckItemFilterPatch : ModulePatch { protected override MethodBase GetTargetMethod() { - return AccessTools.Method(typeof(MagazineClass), nameof(MagazineClass.CheckCompatibility)); + return AccessTools.Method(typeof(GClass2510), nameof(GClass2510.CheckItemFilter)); } [PatchPrefix] - public static bool Prefix(BulletClass ammo, ref bool __result) + public static void Prefix(ref ItemFilter[] filters, Item item) { if (CombinedFilters == null) { - return true; + return; } - __result = CombinedFilters.CheckItemFilter(ammo); - return false; + filters = CombinedFilters; } } @@ -85,5 +87,59 @@ namespace UIFixes return false; } } + + public class FilterMagPresetsPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GClass3044), nameof(GClass3044.method_7)); + } + + [PatchPrefix] + public static void Prefix(MagazineClass magazine) + { + if (MultiSelect.Active) + { + CombinedFilters = MultiSelect.SortedItemContexts() + .Select(itemContext => itemContext.Item) + .OfType() + .SelectMany(mag => mag.Cartridges.Filters) + .ToArray(); + } + } + + [PatchPostfix] + public static void Postfix() + { + CombinedFilters = null; + } + } + + public class LoadPresetPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GClass3044), nameof(GClass3044.method_6)); + } + + [PatchPrefix] + public static bool Prefix(GClass2092 preset, ItemUiContext ___itemUiContext_1) + { + if (!MultiSelect.Active) + { + return true; + } + + if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) + { + return true; + } + + var magazines = MultiSelect.SortedItemContexts().Select(itemContext => itemContext.Item).OfType(); + ___itemUiContext_1.ApplyMagPreset(preset, magazines.ToList()).HandleExceptions(); + + return false; + } + } } } diff --git a/Settings.cs b/Settings.cs index a172913..2550b74 100644 --- a/Settings.cs +++ b/Settings.cs @@ -80,6 +80,7 @@ namespace UIFixes public static ConfigEntry MergeFIRAmmo { get; set; } public static ConfigEntry MergeFIROther { get; set; } public static ConfigEntry AutoOpenSortingTable { get; set; } + public static ConfigEntry LoadMagPresetOnBullets { get; set; } // Advanced // Inspect Panels public static ConfigEntry ShowModStats { get; set; } @@ -426,6 +427,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(LoadMagPresetOnBullets = config.Bind( + InventorySection, + "Mag Presets Context Menu on Bullets", + false, + new ConfigDescription( + "For some reason vanilla EFT shows the Load From Preset context menu on bullets. It serves no purpose", + null, + new ConfigurationManagerAttributes { IsAdvanced = true }))); + // Inspect configEntries.Add(ShowModStats = config.Bind( InspectSection,