old sorting table button; fix auto-sorting table open on scav screen

This commit is contained in:
Tyfon
2024-07-12 16:06:24 -07:00
parent e9fc7f6bf2
commit 29b6094b20
7 changed files with 176 additions and 4 deletions

23
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"label": "dotnet: build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
}
]
}

View File

@@ -0,0 +1,90 @@
using Comfort.Common;
using EFT.UI;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Reflection;
using UnityEngine;
namespace UIFixes;
public static class MoveSortingTablePatches
{
private static Transform SelectedBackground;
public static void Enable()
{
new ButtonsPatch().Enable();
new ToggleBackgroundPatch().Enable();
}
public class ButtonsPatch : ModulePatch
{
private static Tab OldSortingTableTab;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.Show));
}
[PatchPostfix]
public static void Postfix(SimpleStashPanel __instance, ItemUiContext ___itemUiContext_0, Tab ____sortingTableTab, LootItemClass ___lootItemClass)
{
if (Settings.SortingTableButton.Value == SortingTableDisplay.New || ____sortingTableTab == null || ___itemUiContext_0.ContextType != EItemUiContextType.InventoryScreen)
{
return;
}
if (___lootItemClass.Parent.GetOwner() is not InventoryControllerClass inventoryController)
{
return;
}
if (OldSortingTableTab == null)
{
Transform scavScreenSortingTableButton = Singleton<CommonUI>.Instance.transform.Find("Common UI/Scavenger Inventory Screen/Items Panel/Stash Panel/Simple Panel/Sorting Panel/SortTableButton");
OldSortingTableTab = UnityEngine.Object.Instantiate(scavScreenSortingTableButton.GetComponent<Tab>(), ____sortingTableTab.transform.parent, false);
OldSortingTableTab.transform.SetAsFirstSibling();
OldSortingTableTab.OnSelectionChanged += __instance.method_1;
SelectedBackground = OldSortingTableTab.transform.Find("Selected");
if (!inventoryController.SortingTableActive)
{
SelectedBackground.gameObject.SetActive(false);
}
__instance.R().UI.AddDisposable(() =>
{
OldSortingTableTab.OnSelectionChanged -= __instance.method_1;
UnityEngine.Object.Destroy(OldSortingTableTab.gameObject);
OldSortingTableTab = null;
SelectedBackground = null;
});
}
OldSortingTableTab.gameObject.SetActive(____sortingTableTab.isActiveAndEnabled);
if (Settings.SortingTableButton.Value == SortingTableDisplay.Old)
{
____sortingTableTab.gameObject.SetActive(false);
}
}
}
public class ToggleBackgroundPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.ChangeSortingTableTabState));
}
[PatchPostfix]
public static void Postfix(bool isVisible)
{
if (SelectedBackground?.gameObject != null)
{
SelectedBackground.gameObject.SetActive(isVisible);
}
}
}
}

View File

@@ -323,7 +323,7 @@ namespace UIFixes
if (__instance.Profile == PatchConstants.BackEndSession.Profile)
{
MultiSelect.StopLoading();
}
}
}
}

View File

@@ -35,7 +35,16 @@ namespace UIFixes
SortingTableClass sortingTable = __instance.R().InventoryController.Inventory.SortingTable;
if (sortingTable != null && !sortingTable.IsVisible)
{
Singleton<CommonUI>.Instance.InventoryScreen.method_6();
if (__instance.ContextType == EItemUiContextType.InventoryScreen)
{
Singleton<CommonUI>.Instance.InventoryScreen.method_6();
Singleton<CommonUI>.Instance.InventoryScreen.R().SimpleStashPanel.ChangeSortingTableTabState(true);
}
else if (__instance.ContextType == EItemUiContextType.ScavengerInventoryScreen)
{
Singleton<CommonUI>.Instance.ScavengerInventoryScreen.method_7();
Singleton<CommonUI>.Instance.ScavengerInventoryScreen.R().SimpleStashPanel.ChangeSortingTableTabState(true);
}
}
}
}

View File

@@ -62,6 +62,7 @@ namespace UIFixes
NoRandomGrenadesPatch.Init();
GPCoinPatches.Enable();
FleaSlotSearchPatches.Enable();
MoveSortingTablePatches.Enable();
}
public static bool InRaid()

34
R.cs
View File

@@ -63,6 +63,8 @@ namespace UIFixes
InventoryInteractions.InitTypes();
TradingInteractions.InitTypes();
TransferInteractions.InitTypes();
InventoryScreen.InitTypes();
ScavengerInventoryScreen.InitTypes();
}
public abstract class Wrapper(object value)
@@ -781,7 +783,7 @@ namespace UIFixes
ItemField = AccessTools.Field(Type, "item_0");
}
public Item Item { get { return (Item) ItemField.GetValue(Value); } }
public Item Item { get { return (Item)ItemField.GetValue(Value); } }
}
public class TransferInteractions(object value) : Wrapper(value)
@@ -817,6 +819,34 @@ namespace UIFixes
});
}
}
public class InventoryScreen(object value) : UIInputNode(value)
{
public static Type Type { get; private set; }
private static FieldInfo SimpleStashPanelField;
public static void InitTypes()
{
Type = typeof(EFT.UI.InventoryScreen);
SimpleStashPanelField = AccessTools.Field(Type, "_simpleStashPanel");
}
public SimpleStashPanel SimpleStashPanel { get { return (SimpleStashPanel)SimpleStashPanelField.GetValue(Value); } }
}
public class ScavengerInventoryScreen(object value) : UIInputNode(value)
{
public static Type Type { get; private set; }
private static FieldInfo SimpleStashPanelField;
public static void InitTypes()
{
Type = typeof(EFT.UI.ScavengerInventoryScreen);
SimpleStashPanelField = AccessTools.Field(Type, "_simpleStashPanel");
}
public SimpleStashPanel SimpleStashPanel { get { return (SimpleStashPanel)SimpleStashPanelField.GetValue(Value); } }
}
}
public static class RExtentensions
@@ -845,5 +875,7 @@ namespace UIFixes
public static R.MessageWindow R(this MessageWindow value) => new(value);
public static R.RagfairNewOfferItemView R(this RagfairNewOfferItemView value) => new(value);
public static R.TradingTableGridView R(this TradingTableGridView value) => new(value);
public static R.InventoryScreen R(this InventoryScreen value) => new(value);
public static R.ScavengerInventoryScreen R(this ScavengerInventoryScreen value) => new(value);
}
}

View File

@@ -30,6 +30,13 @@ namespace UIFixes
OriginalSpacing
}
internal enum SortingTableDisplay
{
New,
Old,
Both
}
internal class Settings
{
// Categories
@@ -85,6 +92,7 @@ namespace UIFixes
public static ConfigEntry<bool> AutoOpenSortingTable { get; set; }
public static ConfigEntry<bool> ContextMenuOnRight { get; set; }
public static ConfigEntry<bool> ShowGPCurrency { get; set; }
public static ConfigEntry<SortingTableDisplay> SortingTableButton { get; set; }
public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced
// Inspect Panels
@@ -479,6 +487,15 @@ namespace UIFixes
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(SortingTableButton = config.Bind(
InventorySection,
"Sorting Table Button",
SortingTableDisplay.New,
new ConfigDescription(
"What position to show the sorting table button",
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(LoadMagPresetOnBullets = config.Bind(
InventorySection,
"Mag Presets Context Menu on Bullets",
@@ -709,7 +726,7 @@ namespace UIFixes
if (allowSecondaryToDisablePrimary)
{
priorityConfig.Value = false;
}
}
else if (priorityConfig.Value)
{
secondaryConfig.Value = false;