From 9295d85b134f84acf0dcde1db2c5f714c8599acf Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:12:47 -0700 Subject: [PATCH] adjust multiselect clickable detection; make modify equipped weapons not advanced --- Multiselect/DrawMultiSelect.cs | 38 ++++++++++++++++++++++++---------- Patches/SwapPatches.cs | 2 +- Settings.cs | 4 ++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Multiselect/DrawMultiSelect.cs b/Multiselect/DrawMultiSelect.cs index eaefc31..bb3852e 100644 --- a/Multiselect/DrawMultiSelect.cs +++ b/Multiselect/DrawMultiSelect.cs @@ -188,23 +188,39 @@ public class DrawMultiSelect : MonoBehaviour }; List results = []; + preloaderRaycaster.Raycast(eventData, results); // preload objects are on top, so check that first localRaycaster.Raycast(eventData, results); - preloaderRaycaster.Raycast(eventData, results); - foreach (GameObject gameObject in results.Select(r => r.gameObject)) + GameObject gameObject = results.FirstOrDefault().gameObject; + if (gameObject == null) { - var draggables = gameObject.GetComponents() - .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 + return false; + } - var clickables = gameObject.GetComponents() - .Where(c => c is IPointerClickHandler || c is IPointerDownHandler || c is IPointerUpHandler); + var draggables = gameObject.GetComponentsInParent() + .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 - if (draggables.Any() || clickables.Any()) + var clickables = gameObject.GetComponentsInParent() + .Where(c => c is IPointerClickHandler || c is IPointerDownHandler || c is IPointerUpHandler) + .Where(c => c is not EmptySlotMenuTrigger); // ignore empty slots that are right-clickable due to UIFixes + + // Windows are clickable to focus them, but that shouldn't block selection + var windows = clickables + .Where(c => c is UIInputNode) // Windows<>'s parent, cheap check + .Where(c => { - return true; - } + // Most window types implement IPointerClickHandler and inherit directly from Window<> + Type baseType = c.GetType().BaseType; + return baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(Window<>); + }); + + clickables = clickables.Except(windows); + + if (draggables.Any() || clickables.Any()) + { + return true; } return false; diff --git a/Patches/SwapPatches.cs b/Patches/SwapPatches.cs index 9869e1e..87b07d0 100644 --- a/Patches/SwapPatches.cs +++ b/Patches/SwapPatches.cs @@ -146,7 +146,7 @@ public static class SwapPatches { protected override MethodBase GetTargetMethod() { - return AccessTools.Method(typeof(ItemView), nameof(ItemView.OnDrag)); + return AccessTools.Method(typeof(ItemView), nameof(ItemView.OnBeginDrag)); } [PatchPrefix] diff --git a/Settings.cs b/Settings.cs index 39faa1d..36f2a7f 100644 --- a/Settings.cs +++ b/Settings.cs @@ -123,7 +123,7 @@ internal class Settings public static ConfigEntry AlwaysSwapMags { get; set; } public static ConfigEntry UnloadAmmoBoxInPlace { get; set; } // Advanced public static ConfigEntry SwapImpossibleContainers { get; set; } - public static ConfigEntry ModifyEquippedWeapons { get; set; } // Advanced + public static ConfigEntry ModifyEquippedWeapons { get; set; } public static ConfigEntry ModifyRaidWeapons { get; set; } public static ConfigEntry ReorderGrids { get; set; } public static ConfigEntry PrioritizeSmallerGrids { get; set; } @@ -609,7 +609,7 @@ internal class Settings new ConfigDescription( "Enable the modification of equipped weapons, including vital parts, out of raid", null, - new ConfigurationManagerAttributes { IsAdvanced = true }))); + new ConfigurationManagerAttributes { }))); configEntries.Add(ModifyRaidWeapons = config.Bind( InventorySection,