Click outside of dialogs to close
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
R.cs
7
R.cs
@@ -99,14 +99,14 @@ namespace UIFixes
|
||||
public void AddDisposable(Action destroy) => AddDisposableActionMethod.Invoke(Value, [destroy]);
|
||||
}
|
||||
|
||||
public class DialogWindow(object value) : Wrapper(value)
|
||||
public class DialogWindow(object value) : UIInputNode(value)
|
||||
{
|
||||
public static Type Type { get; private set; }
|
||||
private static MethodInfo AcceptMethod;
|
||||
|
||||
public static void InitTypes()
|
||||
{
|
||||
Type = typeof(MessageWindow).BaseType;
|
||||
Type = typeof(EFT.UI.MessageWindow).BaseType;
|
||||
AcceptMethod = AccessTools.Method(Type, "Accept");
|
||||
}
|
||||
|
||||
@@ -583,6 +583,8 @@ namespace UIFixes
|
||||
}
|
||||
|
||||
public class RepairerParametersPanel(object value) : UIElement(value) { }
|
||||
|
||||
public class MessageWindow(object value) : UIInputNode(value) { }
|
||||
}
|
||||
|
||||
public static class RExtentensions
|
||||
@@ -606,5 +608,6 @@ namespace UIFixes
|
||||
public static R.GridWindow R(this GridWindow value) => new(value);
|
||||
public static R.GridSortPanel R(this GridSortPanel value) => new(value);
|
||||
public static R.RepairerParametersPanel R(this RepairerParametersPanel value) => new(value);
|
||||
public static R.MessageWindow R(this MessageWindow value) => new(value);
|
||||
}
|
||||
}
|
||||
|
10
Settings.cs
10
Settings.cs
@@ -35,6 +35,7 @@ namespace UIFixes
|
||||
public static ConfigEntry<bool> KeepMessagesOpen { get; set; }
|
||||
public static ConfigEntry<bool> AutofillQuestTurnIns { get; set; }
|
||||
public static ConfigEntry<bool> AutoSwitchTrading { get; set; }
|
||||
public static ConfigEntry<bool> ClickOutOfDialogs { get; set; } // Advanced
|
||||
|
||||
// Input
|
||||
public static ConfigEntry<bool> UseHomeEnd { get; set; }
|
||||
@@ -122,6 +123,15 @@ namespace UIFixes
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ClickOutOfDialogs = config.Bind(
|
||||
GeneralSection,
|
||||
"Click Outside of Dialogs to Close",
|
||||
true,
|
||||
new ConfigDescription(
|
||||
"Clicking outside of a popup dialog will close the dialog",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { IsAdvanced = true })));
|
||||
|
||||
// Input
|
||||
configEntries.Add(UseHomeEnd = config.Bind(
|
||||
InputSection,
|
||||
|
Reference in New Issue
Block a user