out of stock checkbox
This commit is contained in:
@@ -29,3 +29,16 @@ public static class ExtraTemplatedGridsViewProperties
|
||||
public static bool GetReordered(this TemplatedGridsView gridsView) => properties.GetOrCreateValue(gridsView).Reordered;
|
||||
public static void SetReordered(this TemplatedGridsView gridsView, bool value) => properties.GetOrCreateValue(gridsView).Reordered = value;
|
||||
}
|
||||
|
||||
public static class ExtraTradingGridProperties
|
||||
{
|
||||
private static readonly ConditionalWeakTable<TradingGridView, Properties> properties = new();
|
||||
|
||||
private class Properties
|
||||
{
|
||||
public bool ShowOutOfStock = true;
|
||||
}
|
||||
|
||||
public static bool GetShowOutOfStock(this TradingGridView gridView) => properties.GetOrCreateValue(gridView).ShowOutOfStock;
|
||||
public static void SetShowOutOfStock(this TradingGridView gridView, bool value) => properties.GetOrCreateValue(gridView).ShowOutOfStock = value;
|
||||
}
|
||||
|
||||
143
Patches/FilterOutOfStockPatches.cs
Normal file
143
Patches/FilterOutOfStockPatches.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using EFT;
|
||||
using EFT.InventoryLogic;
|
||||
using EFT.UI;
|
||||
using EFT.UI.DragAndDrop;
|
||||
using HarmonyLib;
|
||||
using SPT.Reflection.Patching;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UIFixes;
|
||||
|
||||
public static class FilterOutOfStockPatches
|
||||
{
|
||||
private static bool ShowOutOfStockItems = true;
|
||||
private static GameObject OutOfStockPanel;
|
||||
|
||||
public static void Enable()
|
||||
{
|
||||
new CreateButtonPatch().Enable();
|
||||
new ShowButtonPatch().Enable();
|
||||
|
||||
new FilterPanelPatch().Enable();
|
||||
new FilterOutOfStockGridItemsPatch().Enable();
|
||||
}
|
||||
|
||||
public class CreateButtonPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(TraderDealScreen), nameof(TraderDealScreen.Awake));
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void Postfix(TraderDealScreen __instance, DefaultUIButton ____updateAssort, TradingGridView ____traderGridView)
|
||||
{
|
||||
OutOfStockPanel = new GameObject("OutOfStockPanel", [typeof(RectTransform)]);
|
||||
OutOfStockPanel.transform.parent = __instance.transform.Find("Left Person/Possessions Grid");
|
||||
OutOfStockPanel.transform.SetAsLastSibling();
|
||||
OutOfStockPanel.SetActive(true);
|
||||
|
||||
RectTransform panelTranform = OutOfStockPanel.RectTransform();
|
||||
panelTranform.pivot = new Vector2(1f, 1f);
|
||||
panelTranform.anchorMin = panelTranform.anchorMax = new Vector2(1f, 0f);
|
||||
panelTranform.anchoredPosition = new Vector2(0f, 0f);
|
||||
panelTranform.sizeDelta = new Vector2(200, 30);
|
||||
|
||||
HorizontalLayoutGroup layoutGroup = OutOfStockPanel.AddComponent<HorizontalLayoutGroup>();
|
||||
layoutGroup.childForceExpandHeight = layoutGroup.childForceExpandWidth = false;
|
||||
layoutGroup.childControlHeight = layoutGroup.childControlWidth = false;
|
||||
layoutGroup.childAlignment = TextAnchor.MiddleRight;
|
||||
|
||||
Image checkbox = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Default/Icon_Box").GetComponent<Image>(), OutOfStockPanel.transform, false);
|
||||
checkbox.SetNativeSize();
|
||||
Image check = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Checkmark").GetComponent<Image>(), checkbox.transform, false);
|
||||
check.SetNativeSize();
|
||||
check.RectTransform().anchoredPosition = Vector2.zero;
|
||||
check.transform.localScale = new Vector3(.7f, .7f, .7f);
|
||||
check.gameObject.SetActive(ShowOutOfStockItems);
|
||||
|
||||
LocalizedText text = UnityEngine.Object.Instantiate(____updateAssort.transform.Find("TextWhite").GetComponent<LocalizedText>(), OutOfStockPanel.transform, false);
|
||||
text.LocalizationKey = "OUT OF STOCK";
|
||||
text.R().StringCase = EStringCase.Upper;
|
||||
|
||||
TextMeshProUGUI textMesh = text.GetComponent<TextMeshProUGUI>();
|
||||
textMesh.enableAutoSizing = false;
|
||||
textMesh.fontSize = 18f;
|
||||
|
||||
Image background = OutOfStockPanel.AddComponent<Image>();
|
||||
background.color = Color.clear;
|
||||
|
||||
Button button = OutOfStockPanel.AddComponent<Button>();
|
||||
button.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
ShowOutOfStockItems = !ShowOutOfStockItems;
|
||||
check.gameObject.SetActive(ShowOutOfStockItems);
|
||||
|
||||
____traderGridView.SetShowOutOfStock(ShowOutOfStockItems);
|
||||
____traderGridView.method_19(); // Refreshes the grid
|
||||
____traderGridView.method_21(); // Resets scrolling position, which has the necessary side effect of refreshing what the scrollview is masking
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ShowButtonPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(TraderDealScreen), nameof(TraderDealScreen.Show));
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void Postfix()
|
||||
{
|
||||
OutOfStockPanel.SetActive(Settings.ShowOutOfStockCheckbox.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public class FilterPanelPatch : ModulePatch
|
||||
{
|
||||
public static bool ShowOutOfStock = true;
|
||||
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.DeclaredMethod(typeof(HandbookFilterPanel), nameof(HandbookFilterPanel.GetFilteredItems));
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void Postfix(ref IEnumerable<Item> __result)
|
||||
{
|
||||
if (ShowOutOfStock)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__result = __result.Where(item => item.StackObjectsCount > 0);
|
||||
ShowOutOfStock = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class FilterOutOfStockGridItemsPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
return AccessTools.Method(typeof(TradingGridView), nameof(TraderDealScreen.method_20));
|
||||
}
|
||||
|
||||
[PatchPrefix]
|
||||
public static void Prefix(TradingGridView __instance)
|
||||
{
|
||||
if (!Settings.ShowOutOfStockCheckbox.Value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FilterPanelPatch.ShowOutOfStock = __instance.GetShowOutOfStock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@ public class Plugin : BaseUnityPlugin
|
||||
GPCoinPatches.Enable();
|
||||
FleaSlotSearchPatches.Enable();
|
||||
MoveSortingTablePatches.Enable();
|
||||
FilterOutOfStockPatches.Enable();
|
||||
}
|
||||
|
||||
public static bool InRaid()
|
||||
|
||||
21
R.cs
21
R.cs
@@ -1,4 +1,5 @@
|
||||
using Comfort.Common;
|
||||
using EFT;
|
||||
using EFT.Hideout;
|
||||
using EFT.InputSystem;
|
||||
using EFT.InventoryLogic;
|
||||
@@ -65,6 +66,7 @@ public static class R
|
||||
TransferInteractions.InitTypes();
|
||||
InventoryScreen.InitTypes();
|
||||
ScavengerInventoryScreen.InitTypes();
|
||||
LocalizedText.InitTypes();
|
||||
}
|
||||
|
||||
public abstract class Wrapper(object value)
|
||||
@@ -847,6 +849,24 @@ public static class R
|
||||
|
||||
public SimpleStashPanel SimpleStashPanel { get { return (SimpleStashPanel)SimpleStashPanelField.GetValue(Value); } }
|
||||
}
|
||||
|
||||
public class LocalizedText(object value) : UIElement(value)
|
||||
{
|
||||
public static Type Type { get; private set; }
|
||||
private static FieldInfo StringCaseField;
|
||||
|
||||
public static void InitTypes()
|
||||
{
|
||||
Type = typeof(EFT.UI.LocalizedText);
|
||||
StringCaseField = AccessTools.Field(Type, "_stringCase");
|
||||
}
|
||||
|
||||
public EStringCase StringCase
|
||||
{
|
||||
get { return (EStringCase)StringCaseField.GetValue(Value); }
|
||||
set { StringCaseField.SetValue(Value, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RExtentensions
|
||||
@@ -877,4 +897,5 @@ public static class RExtentensions
|
||||
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);
|
||||
public static R.LocalizedText R(this LocalizedText value) => new(value);
|
||||
}
|
||||
|
||||
10
Settings.cs
10
Settings.cs
@@ -91,6 +91,7 @@ internal class Settings
|
||||
public static ConfigEntry<bool> AutoOpenSortingTable { get; set; }
|
||||
public static ConfigEntry<bool> ContextMenuOnRight { get; set; }
|
||||
public static ConfigEntry<bool> ShowGPCurrency { get; set; }
|
||||
public static ConfigEntry<bool> ShowOutOfStockCheckbox { get; set; }
|
||||
public static ConfigEntry<SortingTableDisplay> SortingTableButton { get; set; }
|
||||
public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced
|
||||
|
||||
@@ -486,6 +487,15 @@ internal class Settings
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ShowOutOfStockCheckbox = config.Bind(
|
||||
InventorySection,
|
||||
"Show Out of Stock Toggle",
|
||||
true,
|
||||
new ConfigDescription(
|
||||
"Whether the show the Out of Stock toggle on the trading screen",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(SortingTableButton = config.Bind(
|
||||
InventorySection,
|
||||
"Sorting Table Button",
|
||||
|
||||
Reference in New Issue
Block a user