Skip to content

Commit

Permalink
Improve handshake popup
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Dec 4, 2023
1 parent 710ca79 commit 4390ea4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Reactor/Networking/HandshakePopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Reactor.Networking;

internal static class HandshakePopup
{
public const string Message =
"""
This server doesn't support modded handshake.
The lobbies shown may be incompatible with your current mods.
For more info see <link=https://reactor.gg/handshake>reactor.gg/handshake</link>
""";

public static void Show()
{
DisconnectPopup.Instance.ShowCustom(Message);
}
}
24 changes: 24 additions & 0 deletions Reactor/Networking/MakePublicDisallowedPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using Object = UnityEngine.Object;

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 https://reactor.gg/handshake
""";

public static void Show()
{
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(Message);
}
}
16 changes: 3 additions & 13 deletions Reactor/Networking/Patches/HttpPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace Reactor.Networking.Patches;

Expand Down Expand Up @@ -85,9 +84,9 @@ public static void Postfix(UnityWebRequest __instance, UnityWebRequestAsyncOpera
if (__instance.GetMethod() == UnityWebRequest.UnityWebRequestMethod.Get)
{
if (responseHeader == null)
if (responseHeader == null && ModList.IsAnyModIsRequiredOnAllClients && !ReactorConfig.IgnoreHandshakePopup.Value)
{
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();
}
}
Expand Down Expand Up @@ -118,16 +117,7 @@ public static void Postfix(GameStartManager __instance)
__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)
{
Expand Down
3 changes: 3 additions & 0 deletions Reactor/ReactorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ internal static class ReactorConfig
{
public const string FeaturesSection = "Features";

public static ConfigEntry<bool> IgnoreHandshakePopup { get; private set; } = null!;

public static void Bind(ConfigFile config)
{
IgnoreHandshakePopup = config.Bind(FeaturesSection, nameof(IgnoreHandshakePopup), false, "Disables the \"This server doesn't support modded handshake\" popup");
}
}

0 comments on commit 4390ea4

Please sign in to comment.