multiselect apply mag preset; remove bullet apply mag preset

This commit is contained in:
Tyfon
2024-07-02 03:20:39 -07:00
parent 30ecbc333d
commit d21d981125
4 changed files with 110 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ using EFT.UI.DragAndDrop;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
@@ -69,7 +70,7 @@ namespace UIFixes
foreach (GameObject gameObject in results.Select(r => r.gameObject)) foreach (GameObject gameObject in results.Select(r => r.gameObject))
{ {
var draggables = gameObject.GetComponents<MonoBehaviour>() var draggables = gameObject.GetComponents<MonoBehaviour>()
.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 is not ScrollRectNoDrag) // this disables scrolling, it doesn't add it
.Where(c => c.name != "Inner"); // there's a random DragTrigger sitting in ItemInfoWindows .Where(c => c.name != "Inner"); // there's a random DragTrigger sitting in ItemInfoWindows

View File

@@ -76,6 +76,8 @@ namespace UIFixes
new ChangeInteractionButtonCreationPatch().Enable(); new ChangeInteractionButtonCreationPatch().Enable();
new EnableInsureInnerItemsPatch().Enable(); new EnableInsureInnerItemsPatch().Enable();
new DisableLoadPresetOnBulletsPatch().Enable();
} }
public class ContextMenuNamesPatch : ModulePatch public class ContextMenuNamesPatch : ModulePatch
@@ -137,6 +139,14 @@ namespace UIFixes
____text.text += " (x" + count + ")"; ____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()) else if (caption == EItemInfoButton.Unpack.ToString())
{ {
int count = MultiSelect.InteractionCount(EItemInfoButton.Unpack, ItemUiContext.Instance); 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<Item> __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) private static int GetPlayerRubles(ItemUiContext itemUiContext)
{ {
StashClass stash = itemUiContext.R().InventoryController.Inventory.Stash; StashClass stash = itemUiContext.R().InventoryController.Inventory.Stash;

View File

@@ -5,6 +5,7 @@ using HarmonyLib;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine;
namespace UIFixes namespace UIFixes
{ {
@@ -15,8 +16,10 @@ namespace UIFixes
public static void Enable() public static void Enable()
{ {
new FindCompatibleAmmoPatch().Enable(); new FindCompatibleAmmoPatch().Enable();
new CheckCompatibilityPatch().Enable(); new CheckItemFilterPatch().Enable();
new LoadAmmoPatch().Enable(); new LoadAmmoPatch().Enable();
new FilterMagPresetsPatch().Enable();
new LoadPresetPatch().Enable();
} }
public class FindCompatibleAmmoPatch : ModulePatch public class FindCompatibleAmmoPatch : ModulePatch
@@ -46,23 +49,22 @@ namespace UIFixes
} }
} }
public class CheckCompatibilityPatch : ModulePatch public class CheckItemFilterPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(MagazineClass), nameof(MagazineClass.CheckCompatibility)); return AccessTools.Method(typeof(GClass2510), nameof(GClass2510.CheckItemFilter));
} }
[PatchPrefix] [PatchPrefix]
public static bool Prefix(BulletClass ammo, ref bool __result) public static void Prefix(ref ItemFilter[] filters, Item item)
{ {
if (CombinedFilters == null) if (CombinedFilters == null)
{ {
return true; return;
} }
__result = CombinedFilters.CheckItemFilter(ammo); filters = CombinedFilters;
return false;
} }
} }
@@ -85,5 +87,59 @@ namespace UIFixes
return false; 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<MagazineClass>()
.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<MagazineClass>();
___itemUiContext_1.ApplyMagPreset(preset, magazines.ToList()).HandleExceptions();
return false;
}
}
} }
} }

View File

@@ -80,6 +80,7 @@ namespace UIFixes
public static ConfigEntry<bool> MergeFIRAmmo { get; set; } public static ConfigEntry<bool> MergeFIRAmmo { get; set; }
public static ConfigEntry<bool> MergeFIROther { get; set; } public static ConfigEntry<bool> MergeFIROther { get; set; }
public static ConfigEntry<bool> AutoOpenSortingTable { get; set; } public static ConfigEntry<bool> AutoOpenSortingTable { get; set; }
public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced
// Inspect Panels // Inspect Panels
public static ConfigEntry<bool> ShowModStats { get; set; } public static ConfigEntry<bool> ShowModStats { get; set; }
@@ -426,6 +427,15 @@ namespace UIFixes
null, null,
new ConfigurationManagerAttributes { }))); 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 // Inspect
configEntries.Add(ShowModStats = config.Bind( configEntries.Add(ShowModStats = config.Bind(
InspectSection, InspectSection,