From 7de23734d06fb357a0629a7017b3e8cfd3c72655 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:13:44 -0700 Subject: [PATCH] Keep all windows on screen --- Patches/KeepWindowsOnScreenPatches.cs | 41 +++++++++++++++++++++++++++ Plugin.cs | 2 ++ 2 files changed, 43 insertions(+) create mode 100644 Patches/KeepWindowsOnScreenPatches.cs diff --git a/Patches/KeepWindowsOnScreenPatches.cs b/Patches/KeepWindowsOnScreenPatches.cs new file mode 100644 index 0000000..8bb8d8f --- /dev/null +++ b/Patches/KeepWindowsOnScreenPatches.cs @@ -0,0 +1,41 @@ +using Aki.Reflection.Patching; +using EFT.InputSystem; +using EFT.UI; +using HarmonyLib; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace UIFixes.Patches +{ + public static class KeepWindowsOnScreenPatches + { + public static void Enable() + { + new KeepWindowOnScreenPatch(nameof(ItemUiContext.Inspect)).Enable(); + new KeepWindowOnScreenPatch(nameof(ItemUiContext.EditTag)).Enable(); + new KeepWindowOnScreenPatch(nameof(ItemUiContext.OpenInsuranceWindow)).Enable(); + new KeepWindowOnScreenPatch(nameof(ItemUiContext.OpenRepairWindow)).Enable(); + new KeepWindowOnScreenPatch(nameof(ItemUiContext.method_2)).Enable(); // grids + } + + private static void FixNewestWindow(List windows) + { + UIInputNode newWindow = windows.Last() as UIInputNode; + newWindow?.CorrectPosition(); + } + + public class KeepWindowOnScreenPatch(string methodName) : ModulePatch + { + private string methodName = methodName; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(ItemUiContext), methodName); + } + + [PatchPostfix] + public static void Postfix(List ____children) => FixNewestWindow(____children); + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 7fed687..9c88417 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,6 +1,7 @@ using BepInEx; using Comfort.Common; using EFT; +using UIFixes.Patches; namespace UIFixes { @@ -45,6 +46,7 @@ namespace UIFixes RememberRepairerPatches.Enable(); new GridWindowButtonsPatch().Enable(); new LoadMagPresetsPatch().Enable(); + KeepWindowsOnScreenPatches.Enable(); } public static bool InRaid()