diff --git a/.gitmodules b/.gitmodules index 09d13a6..ecdd355 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "ChatPlexSDK-BS"] - path = ChatPlexSDK-BS + path = ChatPlexSDK_BS url = https://github.com/hardcpp/ChatPlexSDK-BS.git diff --git a/ChatPlexSDK-BS b/ChatPlexSDK-BS deleted file mode 160000 index 54c5096..0000000 --- a/ChatPlexSDK-BS +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 54c50963f480a18e52def12cc95ac569b0ea4269 diff --git a/ChatPlexSDK_BS b/ChatPlexSDK_BS new file mode 160000 index 0000000..ba5905c --- /dev/null +++ b/ChatPlexSDK_BS @@ -0,0 +1 @@ +Subproject commit ba5905c042ddffa8be31d1c2c8ac6cc808bc9f36 diff --git a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/CConfig.cs b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/CConfig.cs index 899a875..c43d9a8 100644 --- a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/CConfig.cs +++ b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/CConfig.cs @@ -64,6 +64,7 @@ internal class CConfig : CP_SDK.Config.JsonConfig [JsonProperty] internal bool ShowChannelPointsEvent = true; [JsonProperty] internal bool FilterViewersCommands = false; [JsonProperty] internal bool FilterBroadcasterCommands = false; + [JsonProperty] internal bool OnlyShowTwitchLoginNames = false; [JsonProperty] internal Color BackgroundColor = new Color(0.00f, 0.00f, 0.00f, 0.90f); [JsonProperty] internal Color HighlightColor = new Color(0.57f, 0.28f, 1.00f, 0.12f); diff --git a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/UI/SettingsMainView.cs b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/UI/SettingsMainView.cs index 592f3a5..082c649 100644 --- a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/UI/SettingsMainView.cs +++ b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/UI/SettingsMainView.cs @@ -6,8 +6,10 @@ namespace ChatPlexMod_Chat.UI /// /// Settings main view /// - internal sealed class SettingsMainView : CP_SDK.UI.ViewController + internal sealed class SettingsMainView : CP_SDK.UI.ViewController { + private XUITabControl m_TabControl; + public XUISlider m_ChatWidth; public XUISlider m_ChatHeight; private XUISlider m_ChatFontSize; @@ -18,6 +20,8 @@ internal sealed class SettingsMainView : CP_SDK.UI.ViewController protected override void OnViewCreation() { - var l_Config = CConfig.Instance; - Templates.FullRectLayoutMainView( Templates.TitleBar("Chat | Settings"), - XUIHLayout.Make( - XUIVLayout.Make( - XUIText.Make("Width"), - XUISlider.Make().SetMinValue(80.0f).SetMaxValue(300.0f).SetIncrements(1.0f).SetInteger(true).SetValue(l_Config.ChatSize.x).Bind(ref m_ChatWidth), - - XUIText.Make("Height"), - XUISlider.Make().SetMinValue(80.0f).SetMaxValue(300.0f).SetIncrements(1.0f).SetInteger(true).SetValue(l_Config.ChatSize.y).Bind(ref m_ChatHeight), - - XUIText.Make("Font size"), - XUISlider.Make().SetMinValue(1.0f).SetMaxValue(10.0f).SetIncrements(0.1f).SetValue(l_Config.FontSize).Bind(ref m_ChatFontSize), - - XUIText.Make("Reverse chat order"), - XUIToggle.Make().SetValue(l_Config.ReverseChatOrder).Bind(ref m_ChatReverse), - - XUIText.Make("Show platform origin color"), - XUIToggle.Make().SetValue(l_Config.PlatformOriginColor).Bind(ref m_ChatPlatformOriginColor) - ) - .SetSpacing(1) - .SetWidth(40.0f) - .OnReady(x => x.HOrVLayoutGroup.childAlignment = UnityEngine.TextAnchor.UpperCenter) - .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) - .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())) - .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())), - - XUIVLayout.Make( - XUIText.Make("Background color"), - XUIColorInput.Make() - .SetAlphaSupport(true).SetValue(l_Config.BackgroundColor) - .Bind(ref m_ChatBackgroundColor), - - XUIText.Make("Highlight color"), - XUIColorInput.Make() - .SetAlphaSupport(true).SetValue(l_Config.HighlightColor) - .Bind(ref m_ChatHighlightColor), - - XUIText.Make("Text color"), - XUIColorInput.Make() - .SetValue(l_Config.TextColor) - .Bind(ref m_ChatTextColor), - - XUIText.Make("Ping color"), - XUIColorInput.Make() - .SetAlphaSupport(true).SetValue(l_Config.PingColor) - .Bind(ref m_ChatPingColor) - ) - .SetSpacing(1) - .SetWidth(40.0f) - .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) - .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())) - ) - .SetSpacing(10f) + XUITabControl.Make( + ("General", BuildGeneralTab()), + ("Twitch", BuildTwitchTab()) + ).Bind(ref m_TabControl) ) .SetBackground(true, null, true) .BuildUI(transform); @@ -103,6 +58,95 @@ protected override void OnViewDeactivation() //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// + /// + /// Build general chat settings tab + /// + private IXUIElement BuildGeneralTab() + { + var l_Config = CConfig.Instance; + + return XUIHLayout.Make( + XUIVLayout.Make( + XUIText.Make("Width"), + XUISlider.Make().SetMinValue(80.0f).SetMaxValue(300.0f).SetIncrements(1.0f).SetInteger(true) + .SetValue(l_Config.ChatSize.x).Bind(ref m_ChatWidth), + + XUIText.Make("Height"), + XUISlider.Make().SetMinValue(80.0f).SetMaxValue(300.0f).SetIncrements(1.0f).SetInteger(true) + .SetValue(l_Config.ChatSize.y).Bind(ref m_ChatHeight), + + XUIText.Make("Font size"), + XUISlider.Make().SetMinValue(1.0f).SetMaxValue(10.0f).SetIncrements(0.1f) + .SetValue(l_Config.FontSize).Bind(ref m_ChatFontSize) + ) + .SetSpacing(1) + .SetWidth(40.0f) + .OnReady(x => x.HOrVLayoutGroup.childAlignment = UnityEngine.TextAnchor.UpperCenter) + .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())), + + XUIVLayout.Make( + XUIText.Make("Reverse chat order"), + XUIToggle.Make().SetValue(l_Config.ReverseChatOrder).Bind(ref m_ChatReverse), + + XUIText.Make("Show platform origin color"), + XUIToggle.Make().SetValue(l_Config.PlatformOriginColor).Bind(ref m_ChatPlatformOriginColor) + ) + .SetSpacing(1) + .SetWidth(40.0f) + .OnReady(x => x.HOrVLayoutGroup.childAlignment = UnityEngine.TextAnchor.UpperCenter) + .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())), + + XUIVLayout.Make( + XUIText.Make("Background color"), + XUIColorInput.Make() + .SetAlphaSupport(true).SetValue(l_Config.BackgroundColor) + .Bind(ref m_ChatBackgroundColor), + + XUIText.Make("Highlight color"), + XUIColorInput.Make() + .SetAlphaSupport(true).SetValue(l_Config.HighlightColor) + .Bind(ref m_ChatHighlightColor), + + XUIText.Make("Text color"), + XUIColorInput.Make() + .SetValue(l_Config.TextColor) + .Bind(ref m_ChatTextColor), + + XUIText.Make("Ping color"), + XUIColorInput.Make() + .SetAlphaSupport(true).SetValue(l_Config.PingColor) + .Bind(ref m_ChatPingColor) + ) + .SetSpacing(1) + .SetWidth(40.0f) + .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())) + ) + .SetSpacing(10f); + } + + /// + /// Build tab for Twitch-specific settings + /// + private IXUIElement BuildTwitchTab() + { + var l_Config = CConfig.Instance; + + return XUIVLayout.Make( + XUIText.Make("Do not show international usernames"), + XUIToggle.Make().SetValue(l_Config.OnlyShowTwitchLoginNames).Bind(ref m_OnlyShowTwitchLoginNames) + ) + .ForEachDirect(x => x.SetAlign(TMPro.TextAlignmentOptions.Center)) + .ForEachDirect(x => x.OnValueChanged((_) => OnSettingChanged())); + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + /// /// When settings are changed /// @@ -114,15 +158,17 @@ private void OnSettingChanged() var l_Config = CConfig.Instance; /// Update config - l_Config.ChatSize = new Vector2((int)m_ChatWidth.Element.GetValue(), (int)m_ChatHeight.Element.GetValue()); - l_Config.FontSize = m_ChatFontSize.Element.GetValue(); - l_Config.ReverseChatOrder = m_ChatReverse.Element.GetValue(); - l_Config.PlatformOriginColor = m_ChatPlatformOriginColor.Element.GetValue(); - - l_Config.BackgroundColor = m_ChatBackgroundColor.Element.GetValue(); - l_Config.HighlightColor = m_ChatHighlightColor.Element.GetValue(); - l_Config.TextColor = m_ChatTextColor.Element.GetValue(); - l_Config.PingColor = m_ChatPingColor.Element.GetValue(); + l_Config.ChatSize = new Vector2((int)m_ChatWidth.Element.GetValue(), (int)m_ChatHeight.Element.GetValue()); + l_Config.FontSize = m_ChatFontSize.Element.GetValue(); + l_Config.ReverseChatOrder = m_ChatReverse.Element.GetValue(); + l_Config.PlatformOriginColor = m_ChatPlatformOriginColor.Element.GetValue(); + + l_Config.BackgroundColor = m_ChatBackgroundColor.Element.GetValue(); + l_Config.HighlightColor = m_ChatHighlightColor.Element.GetValue(); + l_Config.TextColor = m_ChatTextColor.Element.GetValue(); + l_Config.PingColor = m_ChatPingColor.Element.GetValue(); + + l_Config.OnlyShowTwitchLoginNames = m_OnlyShowTwitchLoginNames.Element.GetValue(); /// Update floating view Chat.Instance.UpdateFloatingPanels(); @@ -140,16 +186,18 @@ internal void RefreshSettings() var l_Config = CConfig.Instance; - m_ChatWidth .SetValue(l_Config.ChatSize.x); - m_ChatHeight .SetValue(l_Config.ChatSize.y); - m_ChatReverse .SetValue(l_Config.ReverseChatOrder); - m_ChatPlatformOriginColor.SetValue(l_Config.PlatformOriginColor); - m_ChatFontSize .SetValue(l_Config.FontSize); - - m_ChatBackgroundColor .SetValue(l_Config.BackgroundColor); - m_ChatHighlightColor .SetValue(l_Config.HighlightColor); - m_ChatTextColor .SetValue(l_Config.TextColor); - m_ChatPingColor .SetValue(l_Config.PingColor); + m_ChatWidth .SetValue(l_Config.ChatSize.x); + m_ChatHeight .SetValue(l_Config.ChatSize.y); + m_ChatReverse .SetValue(l_Config.ReverseChatOrder); + m_ChatPlatformOriginColor .SetValue(l_Config.PlatformOriginColor); + m_ChatFontSize .SetValue(l_Config.FontSize); + + m_ChatBackgroundColor .SetValue(l_Config.BackgroundColor); + m_ChatHighlightColor .SetValue(l_Config.HighlightColor); + m_ChatTextColor .SetValue(l_Config.TextColor); + m_ChatPingColor .SetValue(l_Config.PingColor); + + m_OnlyShowTwitchLoginNames.SetValue(l_Config.OnlyShowTwitchLoginNames); m_PreventChanges = false; } diff --git a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/Utils/ChatMessageBuilder.cs b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/Utils/ChatMessageBuilder.cs index 1f01c38..5601c1b 100644 --- a/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/Utils/ChatMessageBuilder.cs +++ b/Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/Utils/ChatMessageBuilder.cs @@ -140,17 +140,27 @@ public static async Task BuildMessage(IChatMessage p_Message, Extensions l_StringBuilder.Insert(0, $""); l_StringBuilder.Append(""); } - else - { + else { + var l_UsernameDisplay = p_Message.Sender.PaintedName; + + /// Twitch-specific, username display for users with international names + if (p_Message.Sender.GetType() == typeof(TwitchUser)) + { + if (!p_Message.Sender.UserName.Equals(p_Message.Sender.DisplayName.ToLower())) + l_UsernameDisplay = ($"{p_Message.Sender.DisplayName} ({p_Message.Sender.UserName})"); + if (CConfig.Instance.OnlyShowTwitchLoginNames) + l_UsernameDisplay = p_Message.Sender.UserName; + } + /// Message becomes the color of their name if it's an action message if (p_Message.IsActionMessage) { - l_StringBuilder.Insert(0, $"{p_Message.Sender.PaintedName} "); + l_StringBuilder.Insert(0, $"{l_UsernameDisplay} "); l_StringBuilder.Append(""); } /// Insert username w/ color else - l_StringBuilder.Insert(0, $"{p_Message.Sender.PaintedName}: "); + l_StringBuilder.Insert(0, $"{l_UsernameDisplay}: "); if (p_Message.Sender.Badges != null) {