Skip to content

Twitch username display in BS+ Chat now shows display names with usernames #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ChatPlexSDK-BS"]
path = ChatPlexSDK-BS
path = ChatPlexSDK_BS
url = https://github.com/hardcpp/ChatPlexSDK-BS.git
1 change: 0 additions & 1 deletion ChatPlexSDK-BS
Submodule ChatPlexSDK-BS deleted from 54c509
1 change: 1 addition & 0 deletions ChatPlexSDK_BS
Submodule ChatPlexSDK_BS added at ba5905
1 change: 1 addition & 0 deletions Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/CConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal class CConfig : CP_SDK.Config.JsonConfig<CConfig>
[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);
Expand Down
194 changes: 121 additions & 73 deletions Modules/BeatSaberPlus_Chat/ChatPlexMod_Chat/UI/SettingsMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace ChatPlexMod_Chat.UI
/// <summary>
/// Settings main view
/// </summary>
internal sealed class SettingsMainView : CP_SDK.UI.ViewController<SettingsMainView>
internal sealed class SettingsMainView : CP_SDK.UI.ViewController<SettingsMainView>
{
private XUITabControl m_TabControl;

public XUISlider m_ChatWidth;
public XUISlider m_ChatHeight;
private XUISlider m_ChatFontSize;
Expand All @@ -18,6 +20,8 @@ internal sealed class SettingsMainView : CP_SDK.UI.ViewController<SettingsMainVi
private XUIColorInput m_ChatHighlightColor;
private XUIColorInput m_ChatTextColor;
private XUIColorInput m_ChatPingColor;

private XUIToggle m_OnlyShowTwitchLoginNames;

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
Expand All @@ -32,62 +36,13 @@ internal sealed class SettingsMainView : CP_SDK.UI.ViewController<SettingsMainVi
/// </summary>
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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUISlider>(x => x.OnValueChanged((_) => OnSettingChanged()))
.ForEachDirect<XUIToggle>(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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUIColorInput>(x => x.OnValueChanged((_) => OnSettingChanged()))
)
.SetSpacing(10f)
XUITabControl.Make(
("General", BuildGeneralTab()),
("Twitch", BuildTwitchTab())
).Bind(ref m_TabControl)
)
.SetBackground(true, null, true)
.BuildUI(transform);
Expand All @@ -103,6 +58,95 @@ protected override void OnViewDeactivation()
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////

/// <summary>
/// Build general chat settings tab
/// </summary>
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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUISlider>(x => x.OnValueChanged((_) => OnSettingChanged()))
.ForEachDirect<XUIToggle>(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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUISlider>(x => x.OnValueChanged((_) => OnSettingChanged()))
.ForEachDirect<XUIToggle>(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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUIColorInput>(x => x.OnValueChanged((_) => OnSettingChanged()))
)
.SetSpacing(10f);
}

/// <summary>
/// Build tab for Twitch-specific settings
/// </summary>
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<XUIText>(x => x.SetAlign(TMPro.TextAlignmentOptions.Center))
.ForEachDirect<XUIToggle>(x => x.OnValueChanged((_) => OnSettingChanged()));
}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////

/// <summary>
/// When settings are changed
/// </summary>
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,27 @@ public static async Task<string> BuildMessage(IChatMessage p_Message, Extensions
l_StringBuilder.Insert(0, $"<color=#bbbbbbbb>");
l_StringBuilder.Append("</color>");
}
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, $"<color={p_Message.Sender.Color}><b>{p_Message.Sender.PaintedName}</b> ");
l_StringBuilder.Insert(0, $"<color={p_Message.Sender.Color}><b>{l_UsernameDisplay}</b> ");
l_StringBuilder.Append("</color>");
}
/// Insert username w/ color
else
l_StringBuilder.Insert(0, $"<color={p_Message.Sender.Color}><b>{p_Message.Sender.PaintedName}</b></color>: ");
l_StringBuilder.Insert(0, $"<color={p_Message.Sender.Color}><b>{l_UsernameDisplay}</b></color>: ");

if (p_Message.Sender.Badges != null)
{
Expand Down