Set tags with enter; tags over names

This commit is contained in:
Tyfon
2024-08-16 11:54:50 -07:00
parent 1d3a2ac85a
commit 75c60fb09a
4 changed files with 187 additions and 103 deletions

73
Patches/TagPatches.cs Normal file
View File

@@ -0,0 +1,73 @@
using EFT.UI;
using EFT.UI.DragAndDrop;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Reflection;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace UIFixes;
public static class TagPatches
{
public static void Enable()
{
new OnEnterPatch().Enable();
new TagsOverCaptionsPatch().Enable();
}
public class OnEnterPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(EditTagWindow), nameof(EditTagWindow.Show));
}
[PatchPostfix]
public static void Postfix(EditTagWindow __instance, ValidationInputField ____tagInput)
{
____tagInput.onSubmit.AddListener(value => __instance.method_4());
}
}
public class TagsOverCaptionsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.method_21));
}
[PatchPostfix]
public static async void Postfix(GridItemView __instance, TextMeshProUGUI ___TagName, TextMeshProUGUI ___Caption, Image ____tagColor, Task __result)
{
await __result;
// Rerun logic with preferred priority. Running again rather than prefix overwrite because this also fixes the existing race condition
___TagName.gameObject.SetActive(false);
___Caption.gameObject.SetActive(true);
await Task.Yield();
RectTransform tagTransform = ____tagColor.rectTransform;
float tagSpace = __instance.RectTransform.sizeDelta.x - ___Caption.renderedWidth - 2f;
if (tagSpace < 40f)
{
tagTransform.sizeDelta = new Vector2(__instance.RectTransform.sizeDelta.x, tagTransform.sizeDelta.y);
if (Settings.TagsOverCaptions.Value)
{
___TagName.gameObject.SetActive(true);
float tagSize = Mathf.Clamp(___TagName.preferredWidth + 12f, 40f, __instance.RectTransform.sizeDelta.x - 2f);
tagTransform.sizeDelta = new Vector2(tagSize, ____tagColor.rectTransform.sizeDelta.y);
___Caption.gameObject.SetActive(false);
}
}
else
{
___TagName.gameObject.SetActive(true);
float tagSize = Mathf.Clamp(___TagName.preferredWidth + 12f, 40f, tagSpace);
tagTransform.sizeDelta = new Vector2(tagSize, ____tagColor.rectTransform.sizeDelta.y);
}
}
}
}

View File

@@ -192,124 +192,124 @@ public static class WeaponModdingPatches
}
}
public class ModdingMoveToSortingTablePatch : ModulePatch
{
private static bool InPatch = false;
// public class ModdingMoveToSortingTablePatch : ModulePatch
// {
// private static bool InPatch = false;
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(GClass2848), nameof(GClass2848.Select));
}
// protected override MethodBase GetTargetMethod()
// {
// return AccessTools.DeclaredMethod(typeof(GClass2848), nameof(GClass2848.Select));
// }
[PatchPostfix]
public static void Postfix(GClass2848 __instance, Item item, ItemAddress itemAddress, bool simulate, ref Error error, ref bool __result)
{
if (!Settings.MoveBuildsToSortingTable.Value || InPatch || __result || error is not InteractionsHandlerClass.GClass3363)
{
return;
}
// [PatchPostfix]
// public static void Postfix(GClass2848 __instance, Item item, ItemAddress itemAddress, bool simulate, ref Error error, ref bool __result)
// {
// if (!Settings.MoveBuildsToSortingTable.Value || InPatch || __result || error is not InteractionsHandlerClass.GClass3363)
// {
// return;
// }
// get top level item (weapon)
Item rootItem = itemAddress.Container.ParentItem.GetRootMergedItem();
if (rootItem == null)
{
return;
}
// // get top level item (weapon)
// Item rootItem = itemAddress.Container.ParentItem.GetRootMergedItem();
// if (rootItem == null)
// {
// return;
// }
// move it to sorting table
SortingTableClass sortingTable = __instance.InventoryControllerClass.Inventory.SortingTable;
if (sortingTable == null)
{
return;
}
// // move it to sorting table
// SortingTableClass sortingTable = __instance.InventoryControllerClass.Inventory.SortingTable;
// if (sortingTable == null)
// {
// return;
// }
ItemAddressClass sortingTableAddress = sortingTable.Grid.FindLocationForItem(rootItem);
if (sortingTableAddress == null)
{
return;
}
// ItemAddressClass sortingTableAddress = sortingTable.Grid.FindLocationForItem(rootItem);
// if (sortingTableAddress == null)
// {
// return;
// }
var sortingTableMove = InteractionsHandlerClass.Move(rootItem, sortingTableAddress, __instance.InventoryControllerClass, simulate);
if (sortingTableMove.Failed || sortingTableMove.Value == null)
{
return;
}
// var sortingTableMove = InteractionsHandlerClass.Move(rootItem, sortingTableAddress, __instance.InventoryControllerClass, simulate);
// if (sortingTableMove.Failed || sortingTableMove.Value == null)
// {
// return;
// }
if (simulate)
{
// Just testing, and it was moveable to sorting table, so assume everything is fine.
error = null;
__result = true;
return;
}
// if (simulate)
// {
// // Just testing, and it was moveable to sorting table, so assume everything is fine.
// error = null;
// __result = true;
// return;
// }
// Actually selecting it, so do it and then redo the select
__instance.InventoryControllerClass.RunNetworkTransaction(sortingTableMove.Value);
// // Actually selecting it, so do it and then redo the select
// __instance.InventoryControllerClass.RunNetworkTransaction(sortingTableMove.Value);
InPatch = true;
__result = __instance.Select(item, itemAddress, simulate, out error);
InPatch = false;
}
}
// InPatch = true;
// __result = __instance.Select(item, itemAddress, simulate, out error);
// InPatch = false;
// }
// }
public class PresetMoveToSortingTablePatch : ModulePatch
{
private static bool InPatch = false;
// public class PresetMoveToSortingTablePatch : ModulePatch
// {
// private static bool InPatch = false;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GClass2849), nameof(GClass2849.method_2));
}
// protected override MethodBase GetTargetMethod()
// {
// return AccessTools.Method(typeof(GClass2849), nameof(GClass2849.method_2));
// }
[PatchPostfix]
public static void Postfix(
GClass2849 __instance,
Item item,
List<GClass2849.Class2174> modsWithSlots,
TraderControllerClass itemController,
bool simulate,
ref GStruct416<List<GStruct414<GClass2802>>> __result)
{
if (!Settings.MoveBuildsToSortingTable.Value ||
InPatch ||
__result.Succeeded ||
__result.Error is not InteractionsHandlerClass.GClass3363 ||
itemController is not InventoryControllerClass inventoryController)
{
return;
}
// [PatchPostfix]
// public static void Postfix(
// GClass2849 __instance,
// Item item,
// List<GClass2849.Class2174> modsWithSlots,
// TraderControllerClass itemController,
// bool simulate,
// ref GStruct416<List<GStruct414<GClass2802>>> __result)
// {
// if (!Settings.MoveBuildsToSortingTable.Value ||
// InPatch ||
// __result.Succeeded ||
// __result.Error is not InteractionsHandlerClass.GClass3363 ||
// itemController is not InventoryControllerClass inventoryController)
// {
// return;
// }
// move it to sorting table
SortingTableClass sortingTable = inventoryController.Inventory.SortingTable;
if (sortingTable == null)
{
return;
}
// // move it to sorting table
// SortingTableClass sortingTable = inventoryController.Inventory.SortingTable;
// if (sortingTable == null)
// {
// return;
// }
ItemAddressClass sortingTableAddress = sortingTable.Grid.FindLocationForItem(item);
if (sortingTableAddress == null)
{
return;
}
// ItemAddressClass sortingTableAddress = sortingTable.Grid.FindLocationForItem(item);
// if (sortingTableAddress == null)
// {
// return;
// }
var sortingTableMove = InteractionsHandlerClass.Move(item, sortingTableAddress, inventoryController, simulate); // only called with simulate = false
if (sortingTableMove.Failed || sortingTableMove.Value == null)
{
return;
}
// var sortingTableMove = InteractionsHandlerClass.Move(item, sortingTableAddress, inventoryController, simulate); // only called with simulate = false
// if (sortingTableMove.Failed || sortingTableMove.Value == null)
// {
// return;
// }
InPatch = true;
__result = __instance.method_2(item, modsWithSlots, itemController, simulate);
InPatch = false;
// InPatch = true;
// __result = __instance.method_2(item, modsWithSlots, itemController, simulate);
// InPatch = false;
if (__result.Succeeded)
{
__result.Value.Prepend(sortingTableMove);
}
else
{
sortingTableMove.Value.RollBack();
}
}
}
// if (__result.Succeeded)
// {
// __result.Value.Prepend(sortingTableMove);
// }
// else
// {
// sortingTableMove.Value.RollBack();
// }
// }
// }
}

View File

@@ -73,6 +73,7 @@ public class Plugin : BaseUnityPlugin
LimitDragPatches.Enable();
new HideoutCameraPatch().Enable();
WeaponModdingPatches.Enable();
TagPatches.Enable();
}
public static bool InRaid()

View File

@@ -115,6 +115,7 @@ internal class Settings
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> TagsOverCaptions { get; set; }
public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced
// Inspect Panels
@@ -648,6 +649,15 @@ internal class Settings
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(TagsOverCaptions = config.Bind(
InventorySection,
"Prioritize Tags Over Names",
true,
new ConfigDescription(
"When there isn't enough space to show both the tag and the name of an item, show the tag",
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(LoadMagPresetOnBullets = config.Bind(
InventorySection,
"Mag Presets Context Menu on Bullets",