mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Add chat theme option
This commit is contained in:
1 parent
d8dc6c5e62
commit
fde3d9127a
6 files changed
+113
-36
No files matched your search
+2
-1
@@ -1,5 +1,6 @@
|
||||
using AmongUs.Data;
|
||||
using AmongUs.GameOptions;
|
||||
using BetterAmongUs.Patches;
|
||||
using InnerNet;
|
||||
using Sentry.Internal.Extensions;
|
||||
using System.Reflection;
|
||||
@@ -39,7 +40,6 @@ public static class Utils
|
||||
{
|
||||
pooledBubble.transform.SetParent(chat.scroller.Inner);
|
||||
pooledBubble.transform.localScale = Vector3.one;
|
||||
pooledBubble.Background.color = new Color(0.05f, 0.05f, 0.05f, 1f);
|
||||
pooledBubble.SetCosmetics(data);
|
||||
pooledBubble.gameObject.transform.Find("PoolablePlayer").gameObject.SetActive(false);
|
||||
pooledBubble.ColorBlindName.gameObject.SetActive(false);
|
||||
@@ -63,6 +63,7 @@ public static class Utils
|
||||
chat.notificationRoutine = chat.StartCoroutine(chat.BounceDot());
|
||||
}
|
||||
SoundManager.Instance.PlaySound(chat.messageSound, false, 1f, null).pitch = 0.5f + (float)data.PlayerId / 15f;
|
||||
ChatPatch.ChatControllerPatch.SetChatTheme(pooledBubble);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
+97
-34
@@ -51,41 +51,54 @@ class ChatPatch
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ChatController))]
|
||||
class ChatControllerPatch
|
||||
public class ChatControllerPatch
|
||||
{
|
||||
[HarmonyPatch(nameof(ChatController.Toggle))]
|
||||
[HarmonyPostfix]
|
||||
public static void Toggle_Postfix(ChatController __instance)
|
||||
{
|
||||
if (Main.ChatDarkMode.Value)
|
||||
{
|
||||
// Free chat color
|
||||
__instance.freeChatField.background.color = new Color32(40, 40, 40, byte.MaxValue);
|
||||
__instance.freeChatField.textArea.compoText.Color(Color.white);
|
||||
__instance.freeChatField.textArea.outputText.color = Color.white;
|
||||
|
||||
// Quick chat color
|
||||
__instance.quickChatField.background.color = new Color32(40, 40, 40, byte.MaxValue);
|
||||
__instance.quickChatField.text.color = Color.white;
|
||||
|
||||
// Icons
|
||||
__instance.quickChatButton.transform.Find("QuickChatIcon").GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1f);
|
||||
__instance.openKeyboardButton.transform.Find("OpenKeyboardIcon").GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Free chat color
|
||||
__instance.freeChatField.background.color = new Color32(255, 255, 255, byte.MaxValue);
|
||||
__instance.freeChatField.textArea.compoText.Color(Color.black);
|
||||
__instance.freeChatField.textArea.outputText.color = Color.black;
|
||||
|
||||
// Quick chat color
|
||||
__instance.quickChatField.background.color = new Color32(255, 255, 255, byte.MaxValue);
|
||||
__instance.quickChatField.text.color = Color.black;
|
||||
|
||||
// Icons
|
||||
__instance.quickChatButton.transform.Find("QuickChatIcon").GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
|
||||
__instance.openKeyboardButton.transform.Find("OpenKeyboardIcon").GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
|
||||
}
|
||||
|
||||
foreach (var item in HudManager.Instance.Chat.chatBubblePool.activeChildren.ToArray().Select(c => c.GetComponent<ChatBubble>()))
|
||||
{
|
||||
SetChatTheme(item);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(ChatController.Update))]
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
public static void Update_Prefix(ChatController __instance)
|
||||
{
|
||||
for (int i = 0; i < __instance.scroller.Inner.gameObject.transform.childCount; i++)
|
||||
{
|
||||
GameObject chatItem = __instance.scroller.Inner.transform.GetChild(i).gameObject;
|
||||
|
||||
chatItem.transform.Find("ChatText (TMP)").GetComponent<TextMeshPro>().color = new Color(1f, 1f, 1f, 1f);
|
||||
chatItem.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(0.05f, 0.05f, 0.05f, 1f);
|
||||
|
||||
if (chatItem.transform.Find("PoolablePlayer/xMark") != null)
|
||||
{
|
||||
if (chatItem.transform.Find("PoolablePlayer/xMark").GetComponent<SpriteRenderer>().enabled == true)
|
||||
{
|
||||
chatItem.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(0.05f, 0.05f, 0.05f, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Free chat color
|
||||
__instance.freeChatField.background.color = new Color32(40, 40, 40, byte.MaxValue);
|
||||
__instance.freeChatField.textArea.compoText.Color(Color.white);
|
||||
__instance.freeChatField.textArea.outputText.color = Color.white;
|
||||
|
||||
// Quick chat color
|
||||
__instance.quickChatField.background.color = new Color32(40, 40, 40, byte.MaxValue);
|
||||
__instance.quickChatField.text.color = Color.white;
|
||||
|
||||
__instance.quickChatButton.transform.Find("QuickChatIcon").GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1f);
|
||||
__instance.openKeyboardButton.transform.Find("OpenKeyboardIcon").GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1f);
|
||||
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.X))
|
||||
{
|
||||
ClipboardHelper.PutClipboardString(__instance.freeChatField.textArea.text);
|
||||
@@ -112,11 +125,8 @@ class ChatPatch
|
||||
[HarmonyPostfix]
|
||||
public static void AddChat_Postfix(ChatController __instance, [HarmonyArgument(0)] PlayerControl sourcePlayer, [HarmonyArgument(1)] string chatText)
|
||||
{
|
||||
ChatBubble Get() => __instance.chatBubblePool.activeChildren.ToArray()
|
||||
.Select(c => c.GetComponent<ChatBubble>())
|
||||
.Last();
|
||||
ChatBubble chatBubble = SetChatTheme();
|
||||
|
||||
ChatBubble chatBubble = Get();
|
||||
StringBuilder sbTag = new StringBuilder();
|
||||
StringBuilder sbInfo = new StringBuilder();
|
||||
|
||||
@@ -187,9 +197,62 @@ class ChatPatch
|
||||
}
|
||||
|
||||
chatBubble.NameText.text = playerName;
|
||||
chatBubble.ColorBlindName.text = $"<color={Utils.Color32ToHex(Palette.PlayerColors[sourcePlayer.Data.DefaultOutfit.ColorId])}>{chatBubble.ColorBlindName.text}</color>";
|
||||
chatBubble.ColorBlindName.color = Palette.PlayerColors[sourcePlayer.Data.DefaultOutfit.ColorId];
|
||||
Logger.Log($"{sourcePlayer.Data.PlayerName} -> {chatText}", "ChatLog");
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(ChatController.AddChatNote))]
|
||||
[HarmonyPostfix]
|
||||
public static void AddChatNote_Postfix(ChatController __instance)
|
||||
{
|
||||
SetChatTheme();
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(ChatController.AddChatWarning))]
|
||||
[HarmonyPostfix]
|
||||
public static void AddChatWarning_Postfix(ChatController __instance)
|
||||
{
|
||||
SetChatTheme();
|
||||
}
|
||||
|
||||
// Set chat theme
|
||||
public static ChatBubble SetChatTheme(ChatBubble? asChatBubble = null)
|
||||
{
|
||||
ChatBubble Get() => HudManager.Instance.Chat.chatBubblePool.activeChildren.ToArray()
|
||||
.Select(c => c.GetComponent<ChatBubble>())
|
||||
.Last();
|
||||
|
||||
ChatBubble chatBubble = asChatBubble ??= Get();
|
||||
|
||||
if (Main.ChatDarkMode.Value)
|
||||
{
|
||||
chatBubble.transform.Find("ChatText (TMP)").GetComponent<TextMeshPro>().color = new Color(1f, 1f, 1f, 1f);
|
||||
chatBubble.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(0.05f, 0.05f, 0.05f, 1f);
|
||||
|
||||
if (chatBubble.transform.Find("PoolablePlayer/xMark") != null)
|
||||
{
|
||||
if (chatBubble.transform.Find("PoolablePlayer/xMark").GetComponent<SpriteRenderer>().enabled == true)
|
||||
{
|
||||
chatBubble.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(0.05f, 0.05f, 0.05f, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chatBubble.transform.Find("ChatText (TMP)").GetComponent<TextMeshPro>().color = new Color(0f, 0f, 0f, 1f);
|
||||
chatBubble.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
|
||||
|
||||
if (chatBubble.transform.Find("PoolablePlayer/xMark") != null)
|
||||
{
|
||||
if (chatBubble.transform.Find("PoolablePlayer/xMark").GetComponent<SpriteRenderer>().enabled == true)
|
||||
{
|
||||
chatBubble.transform.Find("Background").GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chatBubble;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(FreeChatInputField))]
|
||||
|
||||
@@ -12,6 +12,7 @@ public static class OptionsMenuBehaviourPatch
|
||||
private static ClientOptionItem? BetterHost;
|
||||
private static ClientOptionItem? BetterNotifications;
|
||||
private static ClientOptionItem? ForceOwnLanguage;
|
||||
private static ClientOptionItem? ChatDarkMode;
|
||||
private static ClientOptionItem? ChatInGameplay;
|
||||
private static ClientOptionItem? LobbyPlayerInfo;
|
||||
private static ClientOptionItem? DisableLobbyTheme;
|
||||
@@ -85,6 +86,12 @@ public static class OptionsMenuBehaviourPatch
|
||||
ForceOwnLanguage = ClientOptionItem.Create(title, Main.ForceOwnLanguage, __instance);
|
||||
}
|
||||
|
||||
if (ChatDarkMode == null || ChatDarkMode.ToggleButton == null)
|
||||
{
|
||||
string title = Translator.GetString("BetterOption.ChatDarkMode");
|
||||
ChatDarkMode = ClientOptionItem.Create(title, Main.ChatDarkMode, __instance);
|
||||
}
|
||||
|
||||
if (ChatInGameplay == null || ChatInGameplay.ToggleButton == null)
|
||||
{
|
||||
string title = Translator.GetString("BetterOption.ChatInGame");
|
||||
|
||||
@@ -73,7 +73,10 @@ public static class OnPlayerJoinedPatch
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"BetterOption.BetterHost": "<color=#4f92ff>Better Host</color>",
|
||||
"BetterOption.BetterNotifications": "<color=#4f92ff>Better Notifications</color>",
|
||||
"BetterOption.ForceOwnLanguage": "Force System language",
|
||||
"BetterOption.ChatDarkMode": "Chat Dark Mode",
|
||||
"BetterOption.ChatInGame": "Chat In Gameplay",
|
||||
"BetterOption.LobbyInfo": "Show Lobby Info",
|
||||
"BetterOption.LobbyTheme": "Disable Lobby Theme",
|
||||
|
||||
@@ -206,6 +206,7 @@ public class Main : BasePlugin
|
||||
public static ConfigEntry<bool> BetterHost { get; private set; }
|
||||
public static ConfigEntry<bool> BetterNotifications { get; private set; }
|
||||
public static ConfigEntry<bool> ForceOwnLanguage { get; private set; }
|
||||
public static ConfigEntry<bool> ChatDarkMode { get; private set; }
|
||||
public static ConfigEntry<bool> ChatInGameplay { get; private set; }
|
||||
public static ConfigEntry<bool> LobbyPlayerInfo { get; private set; }
|
||||
public static ConfigEntry<bool> DisableLobbyTheme { get; private set; }
|
||||
@@ -218,6 +219,7 @@ public class Main : BasePlugin
|
||||
BetterHost = Config.Bind("Better Options", "BetterHost", false);
|
||||
BetterNotifications = Config.Bind("Better Options", "BetterNotifications", true);
|
||||
ForceOwnLanguage = Config.Bind("Better Options", "ForceOwnLanguage", false);
|
||||
ChatDarkMode = Config.Bind("Better Options", "ChatDarkMode", true);
|
||||
ChatInGameplay = Config.Bind("Better Options", "ChatInGameplay", true);
|
||||
LobbyPlayerInfo = Config.Bind("Better Options", "LobbyPlayerInfo", true);
|
||||
DisableLobbyTheme = Config.Bind("Better Options", "DisableLobbyTheme", true);
|
||||
|
||||
Reference in new issue
Block a user