Synchronize stash scrolling
This commit is contained in:
85
Patches/ScrollSyncPatches.cs
Normal file
85
Patches/ScrollSyncPatches.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using Aki.Reflection.Patching;
|
||||||
|
using EFT.UI;
|
||||||
|
using EFT.UI.Ragfair;
|
||||||
|
using HarmonyLib;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace UIFixes
|
||||||
|
{
|
||||||
|
public class ScrollSyncPatches
|
||||||
|
{
|
||||||
|
private static float StashScrollPosition = 1f;
|
||||||
|
|
||||||
|
public static void Enable()
|
||||||
|
{
|
||||||
|
new SimpleStashPanelPatch().Enable();
|
||||||
|
new TraderDealScreenPatch().Enable();
|
||||||
|
new AddOfferWindowPatch().Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateScrollPosition(Vector2 position)
|
||||||
|
{
|
||||||
|
StashScrollPosition = position.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SynchronizeScrollRect(UIElement element, ScrollRect scrollRect = null)
|
||||||
|
{
|
||||||
|
if (!Settings.SynchronizeStashScrolling.Value || element == null || (scrollRect ??= element.GetComponentInChildren<ScrollRect>()) == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollRect.verticalNormalizedPosition = StashScrollPosition;
|
||||||
|
scrollRect.onValueChanged.AddListener(UpdateScrollPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SimpleStashPanelPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(typeof(SimpleStashPanel), "Show");
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPostfix]
|
||||||
|
private static void Postfix(SimpleStashPanel __instance)
|
||||||
|
{
|
||||||
|
SynchronizeScrollRect(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TraderDealScreenPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(typeof(TraderDealScreen), "method_3");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TraderDealScreen is a monstrosity that loads multiple times and isn't done loading when Show() is done
|
||||||
|
// method_3 shows the stash grid, if method_5() returned true
|
||||||
|
[PatchPostfix]
|
||||||
|
private static void Postfix(TraderDealScreen __instance, ScrollRect ____stashScroll)
|
||||||
|
{
|
||||||
|
if (__instance.method_5())
|
||||||
|
{
|
||||||
|
SynchronizeScrollRect(__instance, ____stashScroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AddOfferWindowPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.Method(typeof(AddOfferWindow), "Show");
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPostfix]
|
||||||
|
private static void Postfix(AddOfferWindow __instance)
|
||||||
|
{
|
||||||
|
SynchronizeScrollRect(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ namespace UIFixes
|
|||||||
DialogPatches.Enable();
|
DialogPatches.Enable();
|
||||||
ItemPanelResizePatches.Enable();
|
ItemPanelResizePatches.Enable();
|
||||||
ProductionPanelPatches.Enable();
|
ProductionPanelPatches.Enable();
|
||||||
|
ScrollSyncPatches.Enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
Settings.cs
10
Settings.cs
@@ -40,6 +40,7 @@ namespace UIFixes
|
|||||||
// Inventory
|
// Inventory
|
||||||
public static ConfigEntry<bool> SwapItems { get; set; }
|
public static ConfigEntry<bool> SwapItems { get; set; }
|
||||||
public static ConfigEntry<bool> SwapImpossibleContainers { get; set; }
|
public static ConfigEntry<bool> SwapImpossibleContainers { get; set; }
|
||||||
|
public static ConfigEntry<bool> SynchronizeStashScrolling { get; set; }
|
||||||
public static ConfigEntry<bool> MergeFIRMoney { get; set; }
|
public static ConfigEntry<bool> MergeFIRMoney { get; set; }
|
||||||
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; }
|
||||||
@@ -126,6 +127,15 @@ namespace UIFixes
|
|||||||
null,
|
null,
|
||||||
new ConfigurationManagerAttributes { })));
|
new ConfigurationManagerAttributes { })));
|
||||||
|
|
||||||
|
configEntries.Add(SynchronizeStashScrolling = config.Bind(
|
||||||
|
InventorySection,
|
||||||
|
"Synchronize Stash Scroll Position",
|
||||||
|
false,
|
||||||
|
new ConfigDescription(
|
||||||
|
"Remember your scroll position all the places you see your stash - inventory, trading screen, mail screen, etc.",
|
||||||
|
null,
|
||||||
|
new ConfigurationManagerAttributes { })));
|
||||||
|
|
||||||
configEntries.Add(MergeFIRMoney = config.Bind(
|
configEntries.Add(MergeFIRMoney = config.Bind(
|
||||||
InventorySection,
|
InventorySection,
|
||||||
"Autostack Money with FiR Money",
|
"Autostack Money with FiR Money",
|
||||||
|
|||||||
Reference in New Issue
Block a user