Skip to content

Commit

Permalink
single commit challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
RedFoxIV committed Feb 28, 2025
1 parent 77656d8 commit 7a5e426
Show file tree
Hide file tree
Showing 30 changed files with 617 additions and 20 deletions.
38 changes: 29 additions & 9 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System.Numerics;
using Content.Client.Chat.Managers;
using Content.Client.UserInterface.Systems.Chat;
using Content.Shared._White;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Speech;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.RichText;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using YamlDotNet.Core.Tokens;

namespace Content.Client.Chat.UI
{
Expand Down Expand Up @@ -62,18 +66,24 @@ public enum SpeechType : byte
// man down
public event Action<EntityUid, SpeechBubble>? OnDied;


public static SpeechBubble CreateSpeechBubble(SpeechType type, ChatMessage message, EntityUid senderEntity)
{
// WWDP EDIT START
Color? color = null;
if(IoCManager.Resolve<IConfigurationManager>().GetCVar(WhiteCVars.ColoredBubbleChat))
color = Color.FromHex(SharedChatSystem.GetNameColor(SharedChatSystem.GetStringInsideTag(message, "Name")));
// WWDP EDIT END
switch (type)
{
case SpeechType.Emote:
return new TextSpeechBubble(message, senderEntity, "emoteBox");
return new TextSpeechBubble(message, senderEntity, "emoteBox", color); // WWDP EDIT

case SpeechType.Say:
return new FancyTextSpeechBubble(message, senderEntity, "sayBox");
return new FancyTextSpeechBubble(message, senderEntity, "sayBox", color); // WWDP EDIT

case SpeechType.Whisper:
return new FancyTextSpeechBubble(message, senderEntity, "whisperBox");
return new FancyTextSpeechBubble(message, senderEntity, "whisperBox", color); // WWDP EDIT

case SpeechType.Looc:
return new TextSpeechBubble(message, senderEntity, "emoteBox", Color.FromHex("#48d1cc"));
Expand Down Expand Up @@ -190,12 +200,22 @@ public void FadeNow()
}
}

protected FormattedMessage FormatSpeech(string message, Color? fontColor = null)

protected FormattedMessage FormatSpeech(string message, string fontId) => FormatSpeech(message, null, fontId); // WWDP
protected FormattedMessage FormatSpeech(string message, Color? fontColor = null) => FormatSpeech(message, fontColor, null); // WWDP
protected FormattedMessage FormatSpeech(string message, Color? fontColor = null, string? fontId = null) // WWDP EDIT
{
var msg = new FormattedMessage();
if (fontColor != null)
msg.PushColor(fontColor.Value);
msg.AddMarkup(message);
if (fontId != null) // WWDP EDIT START
{
msg.AddMarkup($"[font=\"{fontId}\"]");
msg.AddMarkup(message);
msg.AddMarkup($"[/font]");
}
else
msg.AddMarkup(message); // WWDP EDIT END
return msg;
}

Expand All @@ -220,7 +240,7 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
MaxWidth = SpeechMaxWidth,
};

label.SetMessage(FormatSpeech(message.WrappedMessage, fontColor));
label.SetMessage(FormatSpeech(message.WrappedMessage, fontColor, "Bedstead")); // WWDP EDIT

var panel = new PanelContainer
{
Expand Down Expand Up @@ -272,10 +292,10 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
Margin = new Thickness(2, 6, 2, 2),
StyleClasses = { "bubbleContent" }
};

//We'll be honest. *Yes* this is hacky. Doing this in a cleaner way would require a bottom-up refactor of how saycode handles sending chat messages. -Myr
bubbleHeader.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleHeader", fontColor));
bubbleContent.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleContent", fontColor));
bubbleHeader.SetMessage(FormatSpeech(SharedChatSystem.GetStringInsideTag(message, "BubbleHeader"), fontColor, "Bedstead")); // WWDP EDIT // LESS USELESS ONE LINER FUNCS PLS
bubbleContent.SetMessage(FormatSpeech(SharedChatSystem.GetStringInsideTag(message, "BubbleContent"), fontColor, "Bedstead")); // WWDP EDIT

//As for below: Some day this could probably be converted to xaml. But that is not today. -Myr
var mainPanel = new PanelContainer
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/Tabs/MiscTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<CheckBox Name="ShowOocPatronColor" Text="{Loc 'ui-options-show-ooc-patron-color'}" />
<CheckBox Name="ShowLoocAboveHeadCheckBox" Text="{Loc 'ui-options-show-looc-on-head'}" />
<CheckBox Name="FancySpeechBubblesCheckBox" Text="{Loc 'ui-options-fancy-speech'}" />
<CheckBox Name="EnableColorBubbleChatCheckBox" Text="{Loc 'ui-options-enable-color-in-bubble-chat'}" /> <!-- WD EDIT -->
<CheckBox Name="EnableChatFancyFontCheckBox" Text="{Loc 'ui-options-enable-chat-fancy-font'}" /> <!-- WD EDIT -->
<CheckBox Name="FancyNameBackgroundsCheckBox" Text="{Loc 'ui-options-fancy-name-background'}" />
<CheckBox Name="LogInChatCheckBox" Text="{Loc 'ui-options-log-in-chat'}" /> <!-- WD EDIT -->
<Label Text="{Loc 'ui-options-general-cursor'}"
Expand Down
12 changes: 11 additions & 1 deletion Content.Client/Options/UI/Tabs/MiscTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Client.UserInterface.Screens;
using Content.Shared._White;
using Content.Shared.CCVar;
Expand Down Expand Up @@ -87,6 +87,8 @@ public MiscTab()
FancySpeechBubblesCheckBox.OnToggled += OnCheckBoxToggled;
FancyNameBackgroundsCheckBox.OnToggled += OnCheckBoxToggled;
EnableColorNameCheckBox.OnToggled += OnCheckBoxToggled;
EnableColorBubbleChatCheckBox.OnToggled += OnCheckBoxToggled; // WWDP EDIT
EnableChatFancyFontCheckBox.OnToggled += OnCheckBoxToggled; // WWDP EDIT
ColorblindFriendlyCheckBox.OnToggled += OnCheckBoxToggled;
ReducedMotionCheckBox.OnToggled += OnCheckBoxToggled;
ChatWindowOpacitySlider.OnValueChanged += OnChatWindowOpacitySliderChanged;
Expand All @@ -108,6 +110,8 @@ public MiscTab()
FancySpeechBubblesCheckBox.Pressed = _cfg.GetCVar(CCVars.ChatEnableFancyBubbles);
FancyNameBackgroundsCheckBox.Pressed = _cfg.GetCVar(CCVars.ChatFancyNameBackground);
EnableColorNameCheckBox.Pressed = _cfg.GetCVar(CCVars.ChatEnableColorName);
EnableColorBubbleChatCheckBox.Pressed = _cfg.GetCVar(WhiteCVars.ColoredBubbleChat); // WWDP EDIT
EnableChatFancyFontCheckBox.Pressed = _cfg.GetCVar(WhiteCVars.ChatFancyFont); // WWDP EDIT
ColorblindFriendlyCheckBox.Pressed = _cfg.GetCVar(CCVars.AccessibilityColorblindFriendly);
ReducedMotionCheckBox.Pressed = _cfg.GetCVar(CCVars.ReducedMotion);
ChatWindowOpacitySlider.Value = _cfg.GetCVar(CCVars.ChatWindowOpacity);
Expand Down Expand Up @@ -167,6 +171,8 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
_cfg.SetCVar(CCVars.ChatEnableFancyBubbles, FancySpeechBubblesCheckBox.Pressed);
_cfg.SetCVar(CCVars.ChatFancyNameBackground, FancyNameBackgroundsCheckBox.Pressed);
_cfg.SetCVar(CCVars.ChatEnableColorName, EnableColorNameCheckBox.Pressed);
_cfg.SetCVar(WhiteCVars.ColoredBubbleChat, EnableColorBubbleChatCheckBox.Pressed); // WWDP EDIT
_cfg.SetCVar(WhiteCVars.ChatFancyFont, EnableChatFancyFontCheckBox.Pressed); // WWDP EDIT
_cfg.SetCVar(CCVars.AccessibilityColorblindFriendly, ColorblindFriendlyCheckBox.Pressed);
_cfg.SetCVar(CCVars.ReducedMotion, ReducedMotionCheckBox.Pressed);
_cfg.SetCVar(CCVars.ChatWindowOpacity, ChatWindowOpacitySlider.Value);
Expand Down Expand Up @@ -201,6 +207,8 @@ private void UpdateApplyButton()
var isFancyChatSame = FancySpeechBubblesCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatEnableFancyBubbles);
var isFancyBackgroundSame = FancyNameBackgroundsCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatFancyNameBackground);
var isEnableColorNameSame = EnableColorNameCheckBox.Pressed == _cfg.GetCVar(CCVars.ChatEnableColorName);
var isEnableColorBubbleChatSame = EnableColorBubbleChatCheckBox.Pressed == _cfg.GetCVar(WhiteCVars.ColoredBubbleChat); // WWDP EDIT
var isEnableFancyChatFontSame = EnableChatFancyFontCheckBox.Pressed == _cfg.GetCVar(WhiteCVars.ChatFancyFont); // WWDP EDIT
var isColorblindFriendly = ColorblindFriendlyCheckBox.Pressed == _cfg.GetCVar(CCVars.AccessibilityColorblindFriendly);
var isReducedMotionSame = ReducedMotionCheckBox.Pressed == _cfg.GetCVar(CCVars.ReducedMotion);
var isChatWindowOpacitySame = Math.Abs(ChatWindowOpacitySlider.Value - _cfg.GetCVar(CCVars.ChatWindowOpacity)) < 0.01f;
Expand All @@ -224,6 +232,8 @@ private void UpdateApplyButton()
isFancyChatSame &&
isFancyBackgroundSame &&
isEnableColorNameSame &&
isEnableColorBubbleChatSame && // WWDP EDIT
isEnableFancyChatFontSame && // WWDP EDIT
isColorblindFriendly &&
isReducedMotionSame &&
isChatWindowOpacitySame &&
Expand Down
16 changes: 11 additions & 5 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public sealed class ChatUIController : UIController
[UISystemDependency] private readonly RoleCodewordSystem? _roleCodewordSystem = default!;

[ValidatePrototypeId<ColorPalettePrototype>]
private const string ChatNamePalette = "ChatNames";
private string[] _chatNameColors = default!;
// private const string ChatNamePalette = "ChatNames"; // WWDP EDIT - DEFUNCT - Moved to SharedChatSystem
// private string[] _chatNameColors = default!; // WWDP EDIT - DEFUNCT - Moved to SharedChatSystem
private bool _chatNameColorsEnabled;

private ISawmill _sawmill = default!;
Expand Down Expand Up @@ -191,7 +191,6 @@ public override void Initialize()
SubscribeNetworkEvent<DamageForceSayEvent>(OnDamageForceSay);
_config.OnValueChanged(CCVars.ChatEnableColorName, (value) => { _chatNameColorsEnabled = value; });
_chatNameColorsEnabled = _config.GetCVar(CCVars.ChatEnableColorName);

_speechBubbleRoot = new LayoutContainer();

UpdateChannelPermissions();
Expand Down Expand Up @@ -236,13 +235,14 @@ public override void Initialize()
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
gameplayStateLoad.OnScreenUnload += OnScreenUnload;

/* // WWDP EDIT - DEFUNCT - Moved to SharedChatSystem
var nameColors = _prototypeManager.Index<ColorPalettePrototype>(ChatNamePalette).Colors.Values.ToArray();
_chatNameColors = new string[nameColors.Length];
for (var i = 0; i < nameColors.Length; i++)
{
_chatNameColors[i] = nameColors[i].ToHex();
}

*/
_config.OnValueChanged(CCVars.ChatWindowOpacity, OnChatWindowOpacityChanged);

}
Expand Down Expand Up @@ -835,7 +835,10 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true)
{
var grammar = _ent.GetComponentOrNull<GrammarComponent>(_ent.GetEntity(msg.SenderEntity));
if (grammar != null && grammar.ProperNoun == true)
msg.WrappedMessage = SharedChatSystem.InjectTagInsideTag(msg, "Name", "color", GetNameColor(SharedChatSystem.GetStringInsideTag(msg, "Name")));
{ // WWDP EDIT START
string hex = SharedChatSystem.GetNameColor(SharedChatSystem.GetStringInsideTag(msg, "Name"));
msg.WrappedMessage = SharedChatSystem.InjectTagAroundTag(msg, "Name", "color", hex);
} // WWDP EDIT END
}

// Color any codewords for minds that have roles that use them
Expand Down Expand Up @@ -939,6 +942,8 @@ public void Repopulate()
}
}

/* WWDP EDIT - DEFUNCT
// Moved to SharedChatSystem.GetNameColor(string).
/// <summary>
/// Returns the chat name color for a mob
/// </summary>
Expand All @@ -949,6 +954,7 @@ public string GetNameColor(string name)
var colorIdx = Math.Abs(name.GetHashCode() % _chatNameColors.Length);
return _chatNameColors[colorIdx];
}
*/

private readonly record struct SpeechBubbleData(ChatMessage Message, SpeechBubble.SpeechType Type);

Expand Down
16 changes: 16 additions & 0 deletions Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Client.UserInterface.Systems.Chat.Controls;
using Content.Shared._White;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Input;
Expand Down Expand Up @@ -35,6 +36,8 @@ public partial class ChatBox : UIWidget
private int _chatStackAmount = 0;
private bool _chatStackEnabled => _chatStackAmount > 0;
private List<ChatStackData> _chatStackList;

private bool _chatFontEnabled; // WWDP EDIT


public ChatBox()
Expand All @@ -60,6 +63,7 @@ public ChatBox()
// _chatStackAmount = 0;
_chatStackList = new(_chatStackAmount);
_cfg.OnValueChanged(CCVars.ChatStackLastLines, UpdateChatStack, true);
_cfg.OnValueChanged(WhiteCVars.ChatFancyFont, value => { _chatFontEnabled = value; Repopulate(); }, true); // WWDP EDIT

}

Expand Down Expand Up @@ -175,6 +179,18 @@ private void OnChannelFilter(ChatChannel channel, bool active)

public void AddLine(string message, Color color, int repeat = 0)
{
// WWDP EDIT START // I FUCKING HATE THIS ENGINE
if (_chatFontEnabled)
{
message = $"[font=\"Chat\"]{message}[/font]";
message = message.Replace("[font size=", "[font=\"Chat\" size="); // AAAAAAAAAAAAAAAA
message = message.Replace("[font=\"Default\"", "[font=\"Chat\""); // AAAAAAAAAAAAAAAA
message = message.Replace("[bold]", "[cb]");
message = message.Replace("[/bold]", "[/cb]");
message = message.Replace("[italic]", "[ci]");
message = message.Replace("[/italic]", "[/ci]");
}
// WWDP EDIT END
var formatted = new FormattedMessage(4);
formatted.PushColor(color);
formatted.AddMarkup(message);
Expand Down
Loading

0 comments on commit 7a5e426

Please sign in to comment.