Hideout scroll position, keybinds work on hideout items

This commit is contained in:
Tyfon
2024-06-12 16:54:02 -07:00
parent 1163d08c30
commit 0ceada0db9
5 changed files with 128 additions and 48 deletions

View File

@@ -1,12 +1,23 @@
using Aki.Reflection.Patching;
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.DragAndDrop;
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine.EventSystems;
namespace UIFixes
{
public class ContextMenuShortcutPatch : ModulePatch
public static class ContextMenuShortcutPatches
{
public static void Enable()
{
new ItemUiContextPatch().Enable();
new HideoutItemViewRegisterContextPatch().Enable();
}
public class ItemUiContextPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
@@ -16,8 +27,9 @@ namespace UIFixes
[PatchPostfix]
public static void Postfix(ItemUiContext __instance)
{
// Need an item context to operate on, and ignore these keypresses if there's a focused textbox somewhere
ItemContextAbstractClass itemContext = __instance.R().ItemContext;
if (itemContext == null)
if (itemContext == null || EventSystem.current.currentSelectedGameObject != null)
{
return;
}
@@ -67,4 +79,20 @@ namespace UIFixes
}
}
}
// HideoutItemViews don't register themselves with ItemUiContext for some reason
public class HideoutItemViewRegisterContextPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(HideoutItemView), nameof(HideoutItemView.OnPointerEnter));
}
[PatchPostfix]
public static void Postfix(HideoutItemView __instance)
{
ItemUiContext.Instance.RegisterCurrentItemContext(__instance.ItemContext);
}
}
}
}

View File

@@ -269,7 +269,7 @@ namespace UIFixes
}
[PatchPrefix]
public static void Prefix(RagfairScreen __instance, ISession session, DefaultUIButton ____addOfferButton, ref PreviousFilterButton __state)
public static void Prefix(DefaultUIButton ____addOfferButton, ref PreviousFilterButton __state)
{
// Create previous button
if (!Settings.EnableFleaHistory.Value)
@@ -361,7 +361,7 @@ namespace UIFixes
}
[PatchPostfix]
public static async void Postfix(OfferViewList __instance, Task __result, LightScroller ____scroller, EViewListType ___eviewListType_0)
public static async void Postfix(OfferViewList __instance, Task __result, EViewListType ___eviewListType_0)
{
await __result;

View File

@@ -6,6 +6,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UIFixes
@@ -14,18 +16,21 @@ namespace UIFixes
{
private static readonly Dictionary<string, string> LastSearches = [];
private static float LastAbsoluteDownScrollPosition = -1f;
public static void Enable()
{
new FixHideoutSearchPatch().Enable();
new LazyLoadPatch().Enable();
new RestoreHideoutSearchPatch().Enable();
new SaveHideoutSearchPatch().Enable();
new CloseHideoutSearchPatch().Enable();
new FastHideoutSearchPatch().Enable();
new FixHideoutSearchAgainPatch().Enable();
new CancelScrollOnMouseWheelPatch().Enable();
}
// Deactivate ProduceViews as they lazy load if they don't match the search
public class FixHideoutSearchPatch : ModulePatch
public class LazyLoadPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
@@ -43,6 +48,27 @@ namespace UIFixes
{
view.GameObject.SetActive(false);
}
// As the objects load in, try to restore the old scroll position
if (LastAbsoluteDownScrollPosition >= 0f)
{
ScrollRect scrollRect = view.GetComponentInParent<ScrollRect>();
if (scrollRect != null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(scrollRect.RectTransform());
float currentAbsoluteDownScrollPosition = (1f - scrollRect.verticalNormalizedPosition) * (scrollRect.content.rect.height - scrollRect.viewport.rect.height);
if (LastAbsoluteDownScrollPosition > currentAbsoluteDownScrollPosition + 112f) // 112 is about the height of each item
{
scrollRect.verticalNormalizedPosition = 0f;
}
else
{
// Last one, try to set it exactly
scrollRect.verticalNormalizedPosition = 1f - (LastAbsoluteDownScrollPosition / (scrollRect.content.rect.height - scrollRect.viewport.rect.height));
LastAbsoluteDownScrollPosition = -1f;
}
}
}
}
}
@@ -130,6 +156,14 @@ namespace UIFixes
{
LastSearches[__instance.AreaData.ToString()] = ____searchInputField.text;
ScrollRect scrollRect = __instance.GetComponentInParent<ScrollRect>();
if (scrollRect != null)
{
// Need to save the absolute DOWN position, because that's the direction the scrollbox will grow.
// Subtract the viewport height from content heigh because that's the actual RANGE of the scroll position
LastAbsoluteDownScrollPosition = (1f - scrollRect.verticalNormalizedPosition) * (scrollRect.content.rect.height - scrollRect.viewport.rect.height);
}
// Reset the default behavior
AreaScreenSubstrate areaScreenSubstrate = __instance.GetComponentInParent<AreaScreenSubstrate>();
LayoutElement layoutElement = areaScreenSubstrate.R().ContentLayout;
@@ -149,6 +183,21 @@ namespace UIFixes
public static void Postfix()
{
LastSearches.Clear();
LastAbsoluteDownScrollPosition = -1f;
}
}
public class CancelScrollOnMouseWheelPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ScrollRectNoDrag), nameof(ScrollRectNoDrag.OnScroll));
}
[PatchPostfix]
public static void Postfix()
{
LastAbsoluteDownScrollPosition = -1f;
}
}
}

View File

@@ -1,8 +1,10 @@
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.DragAndDrop;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -22,11 +24,12 @@ namespace UIFixes
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GClass3052), nameof(GClass3052.IsActive));
Type type = PatchConstants.EftTypes.Single(t => t.GetProperty("IsOwnedByPlayer") != null);
return AccessTools.Method(type, "IsActive");
}
[PatchPrefix]
public static bool Prefix(GClass3052 __instance, EItemInfoButton button, ref bool __result, Item ___item_0)
public static bool Prefix(EItemInfoButton button, ref bool __result, Item ___item_0)
{
if (button != EItemInfoButton.LoadAmmo || !Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
{

View File

@@ -46,7 +46,7 @@ namespace UIFixes
new GridWindowButtonsPatch().Enable();
new LoadMagPresetsPatch().Enable();
KeepWindowsOnScreenPatches.Enable();
new ContextMenuShortcutPatch().Enable();
ContextMenuShortcutPatches.Enable();
new OpenSortingTablePatch().Enable();
LoadAmmoInRaidPatches.Enable();
}