From f8d0b0cba33ef8518bd2ec4d403e31a5b3858e95 Mon Sep 17 00:00:00 2001 From: vitopigno <103512727+VitusVeit@users.noreply.github.com> Date: Wed, 4 Jun 2025 12:12:37 +0200 Subject: [PATCH] Add text highlighting (#31442) Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Co-authored-by: Hans Larsson Co-authored-by: Tobias Berger --- .../Options/UI/OptionColorSlider.xaml | 7 + .../Options/UI/OptionColorSlider.xaml.cs | 31 ++++ .../Options/UI/OptionsTabControlRow.xaml.cs | 65 ++++++++ .../Options/UI/Tabs/AccessibilityTab.xaml | 4 + .../Options/UI/Tabs/AccessibilityTab.xaml.cs | 2 + .../Chat/ChatUIController.Highlighting.cs | 156 ++++++++++++++++++ .../Systems/Chat/ChatUIController.cs | 12 +- .../Chat/Controls/ChannelFilterPopup.xaml | 18 +- .../Chat/Controls/ChannelFilterPopup.xaml.cs | 27 +++ .../Systems/Chat/Widgets/ChatBox.xaml.cs | 13 +- Content.Shared/CCVar/CCVars.Chat.cs | 18 ++ Resources/Locale/en-US/chat/highlights.ftl | 57 +++++++ Resources/Locale/en-US/chat/ui/chat-box.ftl | 9 + .../en-US/escape-menu/ui/options-menu.ftl | 3 + 14 files changed, 417 insertions(+), 5 deletions(-) create mode 100644 Content.Client/Options/UI/OptionColorSlider.xaml create mode 100644 Content.Client/Options/UI/OptionColorSlider.xaml.cs create mode 100644 Content.Client/UserInterface/Systems/Chat/ChatUIController.Highlighting.cs create mode 100644 Resources/Locale/en-US/chat/highlights.ftl diff --git a/Content.Client/Options/UI/OptionColorSlider.xaml b/Content.Client/Options/UI/OptionColorSlider.xaml new file mode 100644 index 0000000000..4f5f082350 --- /dev/null +++ b/Content.Client/Options/UI/OptionColorSlider.xaml @@ -0,0 +1,7 @@ + + + + diff --git a/Content.Client/Options/UI/OptionColorSlider.xaml.cs b/Content.Client/Options/UI/OptionColorSlider.xaml.cs new file mode 100644 index 0000000000..6f8f46a3b4 --- /dev/null +++ b/Content.Client/Options/UI/OptionColorSlider.xaml.cs @@ -0,0 +1,31 @@ +using Content.Client.Options.UI; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface; + +namespace Content.Client.Options.UI; + +/// +/// Standard UI control used for color sliders in the options menu. Intended for use with . +/// +/// +[GenerateTypedNameReferences] +public sealed partial class OptionColorSlider : Control +{ + /// + /// The text describing what this slider affects. + /// + public string? Title + { + get => TitleLabel.Text; + set => TitleLabel.Text = value; + } + + /// + /// The example text showing the current color of the slider. + /// + public string? Example + { + get => ExampleLabel.Text; + set => ExampleLabel.Text = value; + } +} diff --git a/Content.Client/Options/UI/OptionsTabControlRow.xaml.cs b/Content.Client/Options/UI/OptionsTabControlRow.xaml.cs index 31dd9897f4..ad262f94a2 100644 --- a/Content.Client/Options/UI/OptionsTabControlRow.xaml.cs +++ b/Content.Client/Options/UI/OptionsTabControlRow.xaml.cs @@ -121,6 +121,19 @@ public sealed partial class OptionsTabControlRow : Control return AddOption(new OptionSliderFloatCVar(this, _cfg, cVar, slider, min, max, scale, FormatPercent)); } + /// + /// Add a color slider option, backed by a simple string CVar. + /// + /// The CVar represented by the slider. + /// The UI control for the option. + /// The option instance backing the added option. + public OptionColorSliderCVar AddOptionColorSlider( + CVarDef cVar, + OptionColorSlider slider) + { + return AddOption(new OptionColorSliderCVar(this, _cfg, cVar, slider)); + } + /// /// Add a slider option, backed by a simple integer CVar. /// @@ -518,6 +531,58 @@ public sealed class OptionSliderFloatCVar : BaseOptionCVar } } +/// +/// Implementation of a CVar option that simply corresponds with a string . +/// +/// +public sealed class OptionColorSliderCVar : BaseOptionCVar +{ + private readonly OptionColorSlider _slider; + + protected override string Value + { + get => _slider.Slider.Color.ToHex(); + set + { + _slider.Slider.Color = Color.FromHex(value); + UpdateLabelColor(); + } + } + + /// + /// Creates a new instance of this type. + /// + /// + /// + /// It is generally more convenient to call overloads on + /// such as instead of instantiating this type directly. + /// + /// + /// The control row that owns this option. + /// The configuration manager to get and set values from. + /// The CVar that is being controlled by this option. + /// The UI control for the option. + public OptionColorSliderCVar( + OptionsTabControlRow controller, + IConfigurationManager cfg, + CVarDef cVar, + OptionColorSlider slider) : base(controller, cfg, cVar) + { + _slider = slider; + + slider.Slider.OnColorChanged += _ => + { + ValueChanged(); + UpdateLabelColor(); + }; + } + + private void UpdateLabelColor() + { + _slider.ExampleLabel.FontColorOverride = Color.FromHex(Value); + } +} + /// /// Implementation of a CVar option that simply corresponds with an integer . /// diff --git a/Content.Client/Options/UI/Tabs/AccessibilityTab.xaml b/Content.Client/Options/UI/Tabs/AccessibilityTab.xaml index 5041b498a0..41fac83c59 100644 --- a/Content.Client/Options/UI/Tabs/AccessibilityTab.xaml +++ b/Content.Client/Options/UI/Tabs/AccessibilityTab.xaml @@ -14,6 +14,10 @@ + +