Hideout scroll position, keybinds work on hideout items
This commit is contained in:
@@ -1,69 +1,97 @@
|
|||||||
using Aki.Reflection.Patching;
|
using Aki.Reflection.Patching;
|
||||||
using EFT.InventoryLogic;
|
using EFT.InventoryLogic;
|
||||||
using EFT.UI;
|
using EFT.UI;
|
||||||
|
using EFT.UI.DragAndDrop;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UIFixes
|
namespace UIFixes
|
||||||
{
|
{
|
||||||
public class ContextMenuShortcutPatch : ModulePatch
|
public static class ContextMenuShortcutPatches
|
||||||
{
|
{
|
||||||
protected override MethodBase GetTargetMethod()
|
public static void Enable()
|
||||||
{
|
{
|
||||||
return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.Update));
|
new ItemUiContextPatch().Enable();
|
||||||
|
new HideoutItemViewRegisterContextPatch().Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
[PatchPostfix]
|
public class ItemUiContextPatch : ModulePatch
|
||||||
public static void Postfix(ItemUiContext __instance)
|
|
||||||
{
|
{
|
||||||
ItemContextAbstractClass itemContext = __instance.R().ItemContext;
|
protected override MethodBase GetTargetMethod()
|
||||||
if (itemContext == null)
|
|
||||||
{
|
{
|
||||||
return;
|
return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.Update));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.InspectKeyBind.Value.IsDown())
|
[PatchPostfix]
|
||||||
|
public static void Postfix(ItemUiContext __instance)
|
||||||
{
|
{
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Inspect);
|
// Need an item context to operate on, and ignore these keypresses if there's a focused textbox somewhere
|
||||||
return;
|
ItemContextAbstractClass itemContext = __instance.R().ItemContext;
|
||||||
}
|
if (itemContext == null || EventSystem.current.currentSelectedGameObject != null)
|
||||||
|
|
||||||
if (Settings.OpenKeyBind.Value.IsDown())
|
|
||||||
{
|
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Open);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.TopUpKeyBind.Value.IsDown())
|
|
||||||
{
|
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.TopUp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.UseKeyBind.Value.IsDown())
|
|
||||||
{
|
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Use);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.UseAllKeyBind.Value.IsDown())
|
|
||||||
{
|
|
||||||
var interactions = __instance.GetItemContextInteractions(itemContext, null);
|
|
||||||
if (!interactions.ExecuteInteraction(EItemInfoButton.UseAll))
|
|
||||||
{
|
{
|
||||||
interactions.ExecuteInteraction(EItemInfoButton.Use);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.InspectKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Inspect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.OpenKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Open);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.TopUpKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.TopUp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.UseKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.Use);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.UseAllKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
var interactions = __instance.GetItemContextInteractions(itemContext, null);
|
||||||
|
if (!interactions.ExecuteInteraction(EItemInfoButton.UseAll))
|
||||||
|
{
|
||||||
|
interactions.ExecuteInteraction(EItemInfoButton.Use);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.FilterByKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.FilterSearch);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.LinkedSearchKeyBind.Value.IsDown())
|
||||||
|
{
|
||||||
|
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.LinkedSearch);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Settings.FilterByKeyBind.Value.IsDown())
|
// HideoutItemViews don't register themselves with ItemUiContext for some reason
|
||||||
|
public class HideoutItemViewRegisterContextPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.FilterSearch);
|
return AccessTools.Method(typeof(HideoutItemView), nameof(HideoutItemView.OnPointerEnter));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.LinkedSearchKeyBind.Value.IsDown())
|
[PatchPostfix]
|
||||||
|
public static void Postfix(HideoutItemView __instance)
|
||||||
{
|
{
|
||||||
__instance.GetItemContextInteractions(itemContext, null).ExecuteInteraction(EItemInfoButton.LinkedSearch);
|
ItemUiContext.Instance.RegisterCurrentItemContext(__instance.ItemContext);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ namespace UIFixes
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PatchPrefix]
|
[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
|
// Create previous button
|
||||||
if (!Settings.EnableFleaHistory.Value)
|
if (!Settings.EnableFleaHistory.Value)
|
||||||
@@ -361,7 +361,7 @@ namespace UIFixes
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PatchPostfix]
|
[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;
|
await __result;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace UIFixes
|
namespace UIFixes
|
||||||
@@ -14,18 +16,21 @@ namespace UIFixes
|
|||||||
{
|
{
|
||||||
private static readonly Dictionary<string, string> LastSearches = [];
|
private static readonly Dictionary<string, string> LastSearches = [];
|
||||||
|
|
||||||
|
private static float LastAbsoluteDownScrollPosition = -1f;
|
||||||
|
|
||||||
public static void Enable()
|
public static void Enable()
|
||||||
{
|
{
|
||||||
new FixHideoutSearchPatch().Enable();
|
new LazyLoadPatch().Enable();
|
||||||
new RestoreHideoutSearchPatch().Enable();
|
new RestoreHideoutSearchPatch().Enable();
|
||||||
new SaveHideoutSearchPatch().Enable();
|
new SaveHideoutSearchPatch().Enable();
|
||||||
new CloseHideoutSearchPatch().Enable();
|
new CloseHideoutSearchPatch().Enable();
|
||||||
new FastHideoutSearchPatch().Enable();
|
new FastHideoutSearchPatch().Enable();
|
||||||
new FixHideoutSearchAgainPatch().Enable();
|
new FixHideoutSearchAgainPatch().Enable();
|
||||||
|
new CancelScrollOnMouseWheelPatch().Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deactivate ProduceViews as they lazy load if they don't match the search
|
// 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()
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
@@ -43,6 +48,27 @@ namespace UIFixes
|
|||||||
{
|
{
|
||||||
view.GameObject.SetActive(false);
|
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;
|
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
|
// Reset the default behavior
|
||||||
AreaScreenSubstrate areaScreenSubstrate = __instance.GetComponentInParent<AreaScreenSubstrate>();
|
AreaScreenSubstrate areaScreenSubstrate = __instance.GetComponentInParent<AreaScreenSubstrate>();
|
||||||
LayoutElement layoutElement = areaScreenSubstrate.R().ContentLayout;
|
LayoutElement layoutElement = areaScreenSubstrate.R().ContentLayout;
|
||||||
@@ -149,6 +183,21 @@ namespace UIFixes
|
|||||||
public static void Postfix()
|
public static void Postfix()
|
||||||
{
|
{
|
||||||
LastSearches.Clear();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using Aki.Reflection.Patching;
|
using Aki.Reflection.Patching;
|
||||||
|
using Aki.Reflection.Utils;
|
||||||
using EFT.InventoryLogic;
|
using EFT.InventoryLogic;
|
||||||
using EFT.UI;
|
using EFT.UI;
|
||||||
using EFT.UI.DragAndDrop;
|
using EFT.UI.DragAndDrop;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -22,11 +24,12 @@ namespace UIFixes
|
|||||||
{
|
{
|
||||||
protected override MethodBase GetTargetMethod()
|
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]
|
[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)
|
if (button != EItemInfoButton.LoadAmmo || !Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace UIFixes
|
|||||||
new GridWindowButtonsPatch().Enable();
|
new GridWindowButtonsPatch().Enable();
|
||||||
new LoadMagPresetsPatch().Enable();
|
new LoadMagPresetsPatch().Enable();
|
||||||
KeepWindowsOnScreenPatches.Enable();
|
KeepWindowsOnScreenPatches.Enable();
|
||||||
new ContextMenuShortcutPatch().Enable();
|
ContextMenuShortcutPatches.Enable();
|
||||||
new OpenSortingTablePatch().Enable();
|
new OpenSortingTablePatch().Enable();
|
||||||
LoadAmmoInRaidPatches.Enable();
|
LoadAmmoInRaidPatches.Enable();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user