mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Improve handshake popup (#77)
This commit is contained in:
1 parent
787b54b8da
commit
014b6e3227
5 files changed
+137
-13
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using Reactor.Utilities.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Networking;
|
||||
|
||||
internal static class HandshakePopup
|
||||
{
|
||||
public const string Message =
|
||||
"""
|
||||
This server doesn't support Reactor's modded handshake.
|
||||
The lobbies shown could be incompatible with your current mods.
|
||||
For more info see <link=https://reactor.gg/handshake>reactor.gg/handshake</link>
|
||||
""";
|
||||
|
||||
private static ReactorPopup? _popup;
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
if (_popup == null)
|
||||
{
|
||||
_popup = ReactorPopup.Create(nameof(HandshakePopup));
|
||||
_popup.Background.transform.localPosition = new Vector3(0, 0.20f, 0);
|
||||
_popup.Background.size = new Vector2(6.5f, 1.7f);
|
||||
_popup.BackButton.transform.SetLocalY(-0.2f);
|
||||
}
|
||||
|
||||
var message = ReactorConfig.HandshakePopupMessage.Value;
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
message = Message;
|
||||
}
|
||||
|
||||
_popup.Show(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Reactor.Utilities.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Networking;
|
||||
|
||||
internal static class MakePublicDisallowedPopup
|
||||
{
|
||||
public const string Message =
|
||||
"""
|
||||
You can't make public lobbies on servers that don't support modded handshake.
|
||||
For more info see <link=https://reactor.gg/handshake>reactor.gg/handshake</link>
|
||||
""";
|
||||
|
||||
private static ReactorPopup? _popup;
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
if (_popup == null)
|
||||
{
|
||||
_popup = ReactorPopup.Create(nameof(MakePublicDisallowedPopup));
|
||||
_popup.Background.transform.localPosition = new Vector3(0, 0.25f, 0);
|
||||
_popup.Background.size = new Vector2(7.5f, 1.5f);
|
||||
_popup.BackButton.transform.SetLocalY(-0.1f);
|
||||
}
|
||||
|
||||
var message = ReactorConfig.MakePublicDisallowedPopupMessage.Value;
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
message = Message;
|
||||
}
|
||||
|
||||
_popup.Show(message);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Reactor.Networking.Patches;
|
||||
|
||||
@@ -85,9 +84,9 @@ internal static class HttpPatches
|
||||
|
||||
if (__instance.GetMethod() == UnityWebRequest.UnityWebRequestMethod.Get)
|
||||
{
|
||||
if (responseHeader == null)
|
||||
if (responseHeader == null && ModList.IsAnyModRequiredOnAllClients)
|
||||
{
|
||||
DisconnectPopup.Instance.ShowCustom("This region doesn't support modded handshake.\nThe lobbies shown may not be compatible with your current mods.\nFor more info see https://reactor.gg/handshake");
|
||||
HandshakePopup.Show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,16 +117,7 @@ internal static class HttpPatches
|
||||
__instance.MakePublicButton.sprite = __instance.PrivateGameImage;
|
||||
|
||||
var onClick = __instance.MakePublicButton.GetComponent<PassiveButton>().OnClick = new Button.ButtonClickedEvent();
|
||||
onClick.AddListener((Action) (() =>
|
||||
{
|
||||
var popup = Object.Instantiate(DiscordManager.Instance.discordPopup, Camera.main!.transform);
|
||||
var background = popup.transform.Find("Background").GetComponent<SpriteRenderer>();
|
||||
var size = background.size;
|
||||
size.x *= 2.5f;
|
||||
background.size = size;
|
||||
popup.TextAreaTMP.fontSizeMin = 2;
|
||||
popup.Show("You can't make public lobbies on regions that don't support modded handshake.\nFor more info see https://reactor.gg/handshake");
|
||||
}));
|
||||
onClick.AddListener((Action) MakePublicDisallowedPopup.Show);
|
||||
|
||||
if (AmongUsClient.Instance.AmHost && AmongUsClient.Instance.IsGamePublic)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,18 @@ namespace Reactor;
|
||||
internal static class ReactorConfig
|
||||
{
|
||||
public const string FeaturesSection = "Features";
|
||||
public const string MessagesSection = "Messages";
|
||||
|
||||
public static ConfigEntry<bool> ForceDisableServerAuthority { get; private set; } = null!;
|
||||
|
||||
public static ConfigEntry<string> HandshakePopupMessage { get; private set; } = null!;
|
||||
public static ConfigEntry<string> MakePublicDisallowedPopupMessage { get; private set; } = null!;
|
||||
|
||||
public static void Bind(ConfigFile config)
|
||||
{
|
||||
ForceDisableServerAuthority = config.Bind(FeaturesSection, nameof(ForceDisableServerAuthority), false, "Enables the DisableServerAuthority flag even when no mods declare it");
|
||||
|
||||
HandshakePopupMessage = config.Bind(MessagesSection, nameof(HandshakePopupMessage), string.Empty);
|
||||
MakePublicDisallowedPopupMessage = config.Bind(MessagesSection, nameof(MakePublicDisallowedPopupMessage), string.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Utilities.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper over <see cref="GenericPopup"/> that adds hyperlink and controller support.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
internal sealed class ReactorPopup : MonoBehaviour
|
||||
{
|
||||
private readonly Il2CppSystem.Collections.Generic.List<SelectableHyperLink> _selectableHyperLinks = new();
|
||||
|
||||
public GenericPopup Popup { get; private set; } = null!;
|
||||
public TextMeshPro TextArea { get; private set; } = null!;
|
||||
public PassiveButton BackButton { get; private set; } = null!;
|
||||
public SpriteRenderer Background { get; private set; } = null!;
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public void Show(string text)
|
||||
{
|
||||
Popup.Show(text);
|
||||
|
||||
ControllerManager.Instance.OpenOverlayMenu(name, BackButton);
|
||||
|
||||
SelectableHyperLinkHelper.AddSelectableUiForHyperlinks(_selectableHyperLinks, name);
|
||||
TextArea.text = SelectableHyperLinkHelper.DecomposeAnnouncementText(TextArea, _selectableHyperLinks, name, TextArea.text);
|
||||
SelectableHyperLinkHelper.UpdateHyperlinkPositions(TextArea, _selectableHyperLinks, name);
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(BackButton, true);
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
ControllerManager.Instance.CloseOverlayMenu(name);
|
||||
}
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public static ReactorPopup Create(string name)
|
||||
{
|
||||
var genericPopup = Instantiate(DiscordManager.Instance.discordPopup, Camera.main!.transform);
|
||||
var gameObject = genericPopup.gameObject;
|
||||
var reactorPopup = gameObject.AddComponent<ReactorPopup>();
|
||||
|
||||
reactorPopup.Popup = genericPopup;
|
||||
reactorPopup.TextArea = genericPopup.TextAreaTMP;
|
||||
reactorPopup.BackButton = gameObject.transform.Find("ExitGame").GetComponent<PassiveButton>();
|
||||
reactorPopup.Background = gameObject.transform.Find("Background").GetComponent<SpriteRenderer>();
|
||||
|
||||
gameObject.name = name;
|
||||
genericPopup.destroyOnClose = true;
|
||||
reactorPopup.TextArea.fontSizeMin = 2;
|
||||
|
||||
return reactorPopup;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user