Add snap buttons and keybinds to container grids
This commit is contained in:
100
Patches/GridWindowButtonsPatch.cs
Normal file
100
Patches/GridWindowButtonsPatch.cs
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
using Aki.Reflection.Patching;
|
||||||
|
using EFT.InventoryLogic;
|
||||||
|
using EFT.UI;
|
||||||
|
using HarmonyLib;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace UIFixes
|
||||||
|
{
|
||||||
|
public class GridWindowButtonsPatch : ModulePatch
|
||||||
|
{
|
||||||
|
protected override MethodBase GetTargetMethod()
|
||||||
|
{
|
||||||
|
return AccessTools.DeclaredMethod(typeof(GridWindow), nameof(GridWindow.Show));
|
||||||
|
}
|
||||||
|
|
||||||
|
[PatchPostfix]
|
||||||
|
public static void Postfix(GridWindow __instance)
|
||||||
|
{
|
||||||
|
if (Settings.AddContainerButtons.Value)
|
||||||
|
{
|
||||||
|
Transform closeButton = __instance.transform.Find("Caption Panel/Close Button");
|
||||||
|
Image sortBackground = __instance.transform.Find("Caption Panel/Sort Button")?.GetComponent<Image>();
|
||||||
|
|
||||||
|
// Left button
|
||||||
|
Button leftButton = CreateButton(closeButton, sortBackground.sprite, EItemAttributeId.RecoilBack);
|
||||||
|
leftButton.onClick.AddListener(() => SnapLeft(__instance));
|
||||||
|
__instance.R().UI.AddDisposable(() => leftButton.onClick.RemoveAllListeners());
|
||||||
|
|
||||||
|
// Right button
|
||||||
|
Button rightButton = CreateButton(closeButton, sortBackground.sprite, EItemAttributeId.RecoilBack);
|
||||||
|
rightButton.transform.Find("X").Rotate(0f, 180f, 0f);
|
||||||
|
rightButton.onClick.AddListener(() => SnapRight(__instance));
|
||||||
|
__instance.R().UI.AddDisposable(() => rightButton.onClick.RemoveAllListeners());
|
||||||
|
|
||||||
|
// Put close back on the end
|
||||||
|
closeButton.SetAsLastSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keybinds
|
||||||
|
LeftRightKeybind leftRightKeybind = __instance.GetOrAddComponent<LeftRightKeybind>();
|
||||||
|
leftRightKeybind.Init(__instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Button CreateButton(Transform template, Sprite backgroundSprite, EItemAttributeId attributeIcon)
|
||||||
|
{
|
||||||
|
Transform transform = UnityEngine.Object.Instantiate(template, template.parent, false);
|
||||||
|
|
||||||
|
Image background = transform.GetComponent<Image>();
|
||||||
|
background.sprite = backgroundSprite;
|
||||||
|
|
||||||
|
Image icon = transform.Find("X").GetComponent<Image>();
|
||||||
|
icon.sprite = EFTHardSettings.Instance.StaticIcons.GetAttributeIcon(attributeIcon);
|
||||||
|
icon.overrideSprite = null;
|
||||||
|
icon.SetNativeSize();
|
||||||
|
|
||||||
|
Button button = transform.GetComponent<Button>();
|
||||||
|
button.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LeftRightKeybind : MonoBehaviour
|
||||||
|
{
|
||||||
|
private GridWindow window;
|
||||||
|
|
||||||
|
public void Init(GridWindow window)
|
||||||
|
{
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
bool isTopWindow = window.transform.GetSiblingIndex() == window.transform.parent.childCount - 1;
|
||||||
|
if (Settings.SnapLeftKeybind.Value.IsDown() && isTopWindow)
|
||||||
|
{
|
||||||
|
SnapLeft(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.SnapRightKeybind.Value.IsDown() && isTopWindow)
|
||||||
|
{
|
||||||
|
SnapRight(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SnapLeft(GridWindow window)
|
||||||
|
{
|
||||||
|
RectTransform inspectRect = (RectTransform)window.transform;
|
||||||
|
inspectRect.anchoredPosition = new Vector2((float)Screen.width / 4f / inspectRect.lossyScale.x, inspectRect.anchoredPosition.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SnapRight(GridWindow window)
|
||||||
|
{
|
||||||
|
RectTransform inspectRect = (RectTransform)window.transform;
|
||||||
|
inspectRect.anchoredPosition = new Vector2((float)Screen.width * 3f / 4f / inspectRect.lossyScale.x, inspectRect.anchoredPosition.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,6 +107,8 @@ namespace UIFixes
|
|||||||
|
|
||||||
Button restoreButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
Button restoreButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
||||||
restoreButton.name = "Restore";
|
restoreButton.name = "Restore";
|
||||||
|
restoreButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
|
||||||
RectTransform restoreRect = (RectTransform)restoreButton.transform;
|
RectTransform restoreRect = (RectTransform)restoreButton.transform;
|
||||||
restoreRect.localPosition = new Vector3(templateRect.localPosition.x - 3 * (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
restoreRect.localPosition = new Vector3(templateRect.localPosition.x - 3 * (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
||||||
|
|
||||||
@@ -152,6 +154,8 @@ namespace UIFixes
|
|||||||
RectTransform templateRect = (RectTransform)template.transform;
|
RectTransform templateRect = (RectTransform)template.transform;
|
||||||
|
|
||||||
Button leftButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
Button leftButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
||||||
|
leftButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
|
||||||
RectTransform leftRect = (RectTransform)leftButton.transform;
|
RectTransform leftRect = (RectTransform)leftButton.transform;
|
||||||
leftRect.localPosition = new Vector3(templateRect.localPosition.x - 2 * (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
leftRect.localPosition = new Vector3(templateRect.localPosition.x - 2 * (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
||||||
|
|
||||||
@@ -172,17 +176,19 @@ namespace UIFixes
|
|||||||
RectTransform templateRect = (RectTransform)template.transform;
|
RectTransform templateRect = (RectTransform)template.transform;
|
||||||
|
|
||||||
Button rightButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
Button rightButton = UnityEngine.Object.Instantiate(template, template.transform.parent, false);
|
||||||
|
rightButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
|
||||||
RectTransform rightRect = (RectTransform)rightButton.transform;
|
RectTransform rightRect = (RectTransform)rightButton.transform;
|
||||||
rightRect.localPosition = new Vector3(templateRect.localPosition.x - (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
rightRect.localPosition = new Vector3(templateRect.localPosition.x - (templateRect.rect.width + ButtonPadding), templateRect.localPosition.y, templateRect.localPosition.z);
|
||||||
|
|
||||||
Image background = rightButton.GetComponent<Image>();
|
Image background = rightButton.GetComponent<Image>();
|
||||||
background.sprite = ButtonBackground.sprite;
|
background.sprite = ButtonBackground.sprite;
|
||||||
|
|
||||||
Image leftImage = rightButton.transform.Find("X").GetComponent<Image>();
|
Image rightImage = rightButton.transform.Find("X").GetComponent<Image>();
|
||||||
leftImage.sprite = EFTHardSettings.Instance.StaticIcons.GetAttributeIcon(EItemAttributeId.RecoilBack);
|
rightImage.sprite = EFTHardSettings.Instance.StaticIcons.GetAttributeIcon(EItemAttributeId.RecoilBack);
|
||||||
leftImage.transform.Rotate(0f, 180f, 0f);
|
rightImage.transform.Rotate(0f, 180f, 0f);
|
||||||
leftImage.overrideSprite = null;
|
rightImage.overrideSprite = null;
|
||||||
leftImage.SetNativeSize();
|
rightImage.SetNativeSize();
|
||||||
|
|
||||||
rightButton.onClick.AddListener(() => SnapRight(inspectPanel));
|
rightButton.onClick.AddListener(() => SnapRight(inspectPanel));
|
||||||
inspectPanel.AddDisposable(() => rightButton.onClick.RemoveAllListeners());
|
inspectPanel.AddDisposable(() => rightButton.onClick.RemoveAllListeners());
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace UIFixes
|
|||||||
KeepMessagesOpenPatches.Enable();
|
KeepMessagesOpenPatches.Enable();
|
||||||
new FocusTradeQuantityPatch().Enable();
|
new FocusTradeQuantityPatch().Enable();
|
||||||
new RememberRepairerPatch().Enable();
|
new RememberRepairerPatch().Enable();
|
||||||
|
new GridWindowButtonsPatch().Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool InRaid()
|
public static bool InRaid()
|
||||||
|
|||||||
2
R.cs
2
R.cs
@@ -554,7 +554,7 @@ namespace UIFixes
|
|||||||
public TraderAssortmentControllerClass TraderAssortmentControler { get { return (TraderAssortmentControllerClass)TraderAssortmentControllerField.GetValue(Value); } }
|
public TraderAssortmentControllerClass TraderAssortmentControler { get { return (TraderAssortmentControllerClass)TraderAssortmentControllerField.GetValue(Value); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GridWindow(object value) : Wrapper(value)
|
public class GridWindow(object value) : UIInputNode(value)
|
||||||
{
|
{
|
||||||
public static Type Type { get; private set; }
|
public static Type Type { get; private set; }
|
||||||
private static FieldInfo GridSortPanelField;
|
private static FieldInfo GridSortPanelField;
|
||||||
|
|||||||
10
Settings.cs
10
Settings.cs
@@ -60,6 +60,7 @@ namespace UIFixes
|
|||||||
public static ConfigEntry<KeyboardShortcut> SnapLeftKeybind { get; set; }
|
public static ConfigEntry<KeyboardShortcut> SnapLeftKeybind { get; set; }
|
||||||
public static ConfigEntry<KeyboardShortcut> SnapRightKeybind { get; set; }
|
public static ConfigEntry<KeyboardShortcut> SnapRightKeybind { get; set; }
|
||||||
public static ConfigEntry<bool> StyleItemPanel { get; set; } // Advanced
|
public static ConfigEntry<bool> StyleItemPanel { get; set; } // Advanced
|
||||||
|
public static ConfigEntry<bool> AddContainerButtons { get; set; } // Advanced
|
||||||
|
|
||||||
// In Raid
|
// In Raid
|
||||||
public static ConfigEntry<bool> RemoveDisabledActions { get; set; }
|
public static ConfigEntry<bool> RemoveDisabledActions { get; set; }
|
||||||
@@ -297,6 +298,15 @@ namespace UIFixes
|
|||||||
null,
|
null,
|
||||||
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
||||||
|
|
||||||
|
configEntries.Add(AddContainerButtons = config.Bind(
|
||||||
|
InspectSection,
|
||||||
|
"Add Left/Right Buttons on Containers",
|
||||||
|
true,
|
||||||
|
new ConfigDescription(
|
||||||
|
"Adds snap left and snap right buttons to container windows too",
|
||||||
|
null,
|
||||||
|
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
||||||
|
|
||||||
// In Raid
|
// In Raid
|
||||||
configEntries.Add(RemoveDisabledActions = config.Bind(
|
configEntries.Add(RemoveDisabledActions = config.Bind(
|
||||||
InRaidSection,
|
InRaidSection,
|
||||||
|
|||||||
Reference in New Issue
Block a user