Click outside of dialogs to close

This commit is contained in:
Tyfon
2024-06-03 01:45:12 -07:00
parent 37f14b898e
commit 284e5bd21e
3 changed files with 72 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ using EFT.UI;
using HarmonyLib;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace UIFixes
{
@@ -13,6 +14,8 @@ namespace UIFixes
{
new DialogWindowPatch().Enable();
new SplitDialogPatch().Enable();
new ClickOutPatch().Enable();
new ClickOutSplitDialogPatch().Enable();
}
public class DialogWindowPatch : ModulePatch
@@ -40,6 +43,7 @@ namespace UIFixes
}
}
// Of course SplitDialogs are a *completely different dialog impelementation*
public class SplitDialogPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
@@ -61,5 +65,58 @@ namespace UIFixes
return true;
}
}
public class ClickOutPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(MessageWindow), nameof(MessageWindow.Show));
}
[PatchPostfix]
public static void Postfix(MessageWindow __instance)
{
if (!Settings.ClickOutOfDialogs.Value)
{
return;
}
// Note the space after firewall, because unity doesn't trim names and BSG is incompetent
Button button = __instance.transform.Find("Window/Firewall ")?.gameObject.GetOrAddComponent<Button>();
if (button != null)
{
button.transition = Selectable.Transition.None;
button.onClick.AddListener(__instance.Close);
__instance.R().UI.AddDisposable(button.onClick.RemoveAllListeners);
}
}
}
public class ClickOutSplitDialogPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
// Using method_0 because there's 2 Show(), and they have 10+ args and f that
return AccessTools.Method(typeof(SplitDialog), nameof(SplitDialog.method_0));
}
[PatchPostfix]
public static void Postfix(SplitDialog __instance)
{
if (!Settings.ClickOutOfDialogs.Value)
{
return;
}
// Note the space after firewall, because unity doesn't trim names and BSG is incompetent
Button button = __instance.transform.Find("Background")?.gameObject.GetOrAddComponent<Button>();
if (button != null)
{
button.transition = Selectable.Transition.None;
button.onClick.RemoveAllListeners(); // There's no disposable here so keeping the listener count down
button.onClick.AddListener(__instance.method_2);
}
}
}
}
}