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

View File

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

View File

@@ -115,6 +115,7 @@ internal class Settings
public static ConfigEntry<bool> ShowGPCurrency { get; set; } public static ConfigEntry<bool> ShowGPCurrency { get; set; }
public static ConfigEntry<bool> ShowOutOfStockCheckbox { get; set; } public static ConfigEntry<bool> ShowOutOfStockCheckbox { get; set; }
public static ConfigEntry<SortingTableDisplay> SortingTableButton { get; set; } public static ConfigEntry<SortingTableDisplay> SortingTableButton { get; set; }
public static ConfigEntry<bool> TagsOverCaptions { get; set; }
public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced public static ConfigEntry<bool> LoadMagPresetOnBullets { get; set; } // Advanced
// Inspect Panels // Inspect Panels
@@ -648,6 +649,15 @@ internal class Settings
null, null,
new ConfigurationManagerAttributes { }))); 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( configEntries.Add(LoadMagPresetOnBullets = config.Bind(
InventorySection, InventorySection,
"Mag Presets Context Menu on Bullets", "Mag Presets Context Menu on Bullets",