-
Notifications
You must be signed in to change notification settings - Fork 56
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
Подсветка текста в фильтрах QOL #14
Changes from 7 commits
f6ab374
7104d66
3a548df
740b1b4
8e30fcc
d9ed746
278ddb9
585a4be
96aeabd
b62c91f
4db8eaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Control xmlns="https://spacestation14.io"> | ||
<BoxContainer Orientation="Vertical"> | ||
<Label Name="TitleLabel" Access="Public" /> | ||
<Label Name="ExampleLabel" Access="Public" /> | ||
<ColorSelectorSliders Name="Slider" Access="Public" HorizontalExpand="True" /> | ||
</BoxContainer> | ||
</Control> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface; | ||
|
||
namespace Content.Client.Options.UI; | ||
|
||
/// <summary> | ||
/// Standard UI control used for color sliders in the options menu. Intended for use with <see cref="OptionsTabControlRow"/>. | ||
/// </summary> | ||
/// <seealso cref="OptionsTabControlRow.AddOptionColorSlider"/> | ||
[GenerateTypedNameReferences] | ||
public sealed partial class OptionColorSlider : Control | ||
{ | ||
/// <summary> | ||
/// The text describing what this slider affects. | ||
/// </summary> | ||
public string? Title | ||
{ | ||
get => TitleLabel.Text; | ||
set => TitleLabel.Text = value; | ||
} | ||
|
||
/// <summary> | ||
/// The example text showing the current color of the slider. | ||
/// </summary> | ||
public string? Example | ||
{ | ||
get => ExampleLabel.Text; | ||
set => ExampleLabel.Text = value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,19 @@ public OptionSliderFloatCVar AddOptionPercentSlider( | |
{ | ||
return AddOption(new OptionSliderFloatCVar(this, _cfg, cVar, slider, min, max, scale, FormatPercent)); | ||
} | ||
|
||
/// <summary> | ||
/// Add a color slider option, backed by a simple string CVar. | ||
/// </summary> | ||
/// <param name="cVar">The CVar represented by the slider.</param> | ||
/// <param name="slider">The UI control for the option.</param> | ||
/// <returns>The option instance backing the added option.</returns> | ||
public OptionColorSliderCVar AddOptionColorSlider( | ||
CVarDef<string> cVar, | ||
OptionColorSlider slider) | ||
{ | ||
return AddOption(new OptionColorSliderCVar(this, _cfg, cVar, slider)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в Corvax CVars |
||
} | ||
|
||
/// <summary> | ||
/// Add a slider option, backed by a simple integer CVar. | ||
|
@@ -518,6 +531,58 @@ private void UpdateLabelValue() | |
} | ||
} | ||
|
||
/// <summary> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. закрой тэгами корвакса |
||
/// Implementation of a CVar option that simply corresponds with a string <see cref="OptionColorSlider"/>. | ||
/// </summary> | ||
/// <seealso cref="OptionsTabControlRow"/> | ||
public sealed class OptionColorSliderCVar : BaseOptionCVar<string> | ||
{ | ||
private readonly OptionColorSlider _slider; | ||
|
||
protected override string Value | ||
{ | ||
get => _slider.Slider.Color.ToHex(); | ||
set | ||
{ | ||
_slider.Slider.Color = Color.FromHex(value); | ||
UpdateLabelColor(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of this type. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// It is generally more convenient to call overloads on <see cref="OptionsTabControlRow"/> | ||
/// such as <see cref="OptionsTabControlRow.AddOptionPercentSlider"/> instead of instantiating this type directly. | ||
/// </para> | ||
/// </remarks> | ||
/// <param name="controller">The control row that owns this option.</param> | ||
/// <param name="cfg">The configuration manager to get and set values from.</param> | ||
/// <param name="cVar">The CVar that is being controlled by this option.</param> | ||
/// <param name="slider">The UI control for the option.</param> | ||
public OptionColorSliderCVar( | ||
OptionsTabControlRow controller, | ||
IConfigurationManager cfg, | ||
CVarDef<string> cVar, | ||
OptionColorSlider slider) : base(controller, cfg, cVar) | ||
{ | ||
_slider = slider; | ||
|
||
slider.Slider.OnColorChanged += _ => | ||
{ | ||
ValueChanged(); | ||
UpdateLabelColor(); | ||
}; | ||
} | ||
|
||
private void UpdateLabelColor() | ||
{ | ||
_slider.ExampleLabel.FontColorOverride = Color.FromHex(Value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Implementation of a CVar option that simply corresponds with an integer <see cref="OptionSlider"/>. | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
<CheckBox Name="ColorblindFriendlyCheckBox" Text="{Loc 'ui-options-colorblind-friendly'}" /> | ||
<ui:OptionSlider Name="ChatWindowOpacitySlider" Title="{Loc 'ui-options-chat-window-opacity'}" /> | ||
<ui:OptionSlider Name="ScreenShakeIntensitySlider" Title="{Loc 'ui-options-screen-shake-intensity'}" /> | ||
<CheckBox Name="AutoFillHighlightsCheckBox" Text="{Loc 'ui-options-auto-fill-highlights'}" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. закрой тэгами корвакса |
||
<ui:OptionColorSlider Name="HighlightsColorSlider" | ||
Title="{Loc 'ui-options-highlights-color'}" | ||
Example="{Loc 'ui-options-highlights-color-example'}"/> | ||
</BoxContainer> | ||
</ScrollContainer> | ||
<ui:OptionsTabControlRow Name="Control" Access="Public" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ public AccessibilityTab() | |
Control.AddOptionCheckBox(CCVars.ReducedMotion, ReducedMotionCheckBox); | ||
Control.AddOptionPercentSlider(CCVars.ChatWindowOpacity, ChatWindowOpacitySlider); | ||
Control.AddOptionPercentSlider(CCVars.ScreenShakeIntensity, ScreenShakeIntensitySlider); | ||
Control.AddOptionCheckBox(CCVars.ChatAutoFillHighlights, AutoFillHighlightsCheckBox); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в Corvax CVars, закрой тэгами корвакса |
||
Control.AddOptionColorSlider(CCVars.ChatHighlightsColor, HighlightsColorSlider); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в Corvax CVars |
||
|
||
Control.Initialize(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Numerics; | ||
using Content.Client.CharacterInfo; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. закрой тэгами корвакса, тоже самое со всеми изменениями в этом файле |
||
using Content.Client.Administration.Managers; | ||
using Content.Client.Chat; | ||
using Content.Client.Chat.Managers; | ||
|
@@ -40,10 +41,12 @@ | |
using Robust.Shared.Replays; | ||
using Robust.Shared.Timing; | ||
using Robust.Shared.Utility; | ||
using static Content.Client.CharacterInfo.CharacterInfoSystem; | ||
|
||
|
||
namespace Content.Client.UserInterface.Systems.Chat; | ||
|
||
public sealed class ChatUIController : UIController | ||
public sealed class ChatUIController : UIController, IOnSystemChanged<CharacterInfoSystem> | ||
{ | ||
[Dependency] private readonly IClientAdminManager _admin = default!; | ||
[Dependency] private readonly IChatManager _manager = default!; | ||
|
@@ -65,6 +68,7 @@ public sealed class ChatUIController : UIController | |
[UISystemDependency] private readonly TransformSystem? _transform = default; | ||
[UISystemDependency] private readonly MindSystem? _mindSystem = default!; | ||
[UISystemDependency] private readonly RoleCodewordSystem? _roleCodewordSystem = default!; | ||
[UISystemDependency] private readonly CharacterInfoSystem _characterInfo = default!; | ||
|
||
[ValidatePrototypeId<ColorPalettePrototype>] | ||
private const string ChatNamePalette = "ChatNames"; | ||
|
@@ -149,6 +153,23 @@ private readonly Dictionary<EntityUid, SpeechBubbleQueueData> _queuedSpeechBubbl | |
/// </summary> | ||
private readonly Dictionary<ChatChannel, int> _unreadMessages = new(); | ||
|
||
/// <summary> | ||
/// A list of words to be highlighted in the chatbox. | ||
/// </summary> | ||
private List<string> _highlights = []; | ||
|
||
/// <summary> | ||
/// The color (hex) in witch the words will be highlighted as. | ||
/// </summary> | ||
private string? _highlightsColor; | ||
|
||
private bool _autoFillHighlightsEnabled; | ||
|
||
/// <summary> | ||
/// A bool to keep track if the 'CharacterUpdated' event is a new player attaching or the opening of the character info panel. | ||
/// </summary> | ||
private bool _charInfoIsAttach = false; | ||
|
||
// TODO add a cap for this for non-replays | ||
public readonly List<(GameTick Tick, ChatMessage Msg)> History = new(); | ||
|
||
|
@@ -172,6 +193,7 @@ private readonly Dictionary<EntityUid, SpeechBubbleQueueData> _queuedSpeechBubbl | |
public event Action<ChatSelectChannel>? SelectableChannelsChanged; | ||
public event Action<ChatChannel, int?>? UnreadMessageCountsUpdated; | ||
public event Action<ChatMessage>? MessageAdded; | ||
public event Action<string>? HighlightsUpdated; | ||
|
||
public override void Initialize() | ||
{ | ||
|
@@ -240,6 +262,19 @@ public override void Initialize() | |
|
||
_config.OnValueChanged(CCVars.ChatWindowOpacity, OnChatWindowOpacityChanged); | ||
|
||
_config.OnValueChanged(CCVars.ChatAutoFillHighlights, (value) => { _autoFillHighlightsEnabled = value; }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corvax CVars |
||
_autoFillHighlightsEnabled = _config.GetCVar(CCVars.ChatAutoFillHighlights); | ||
|
||
_config.OnValueChanged(CCVars.ChatHighlightsColor, (value) => { _highlightsColor = value; }); | ||
_highlightsColor = _config.GetCVar(CCVars.ChatHighlightsColor); | ||
|
||
// Load highlights if any were saved. | ||
string highlights = _config.GetCVar(CCVars.ChatHighlights); | ||
|
||
if (!string.IsNullOrEmpty(highlights)) | ||
{ | ||
UpdateHighlights(highlights); | ||
} | ||
} | ||
|
||
public void OnScreenLoad() | ||
|
@@ -257,11 +292,47 @@ public void OnScreenUnload() | |
SetMainChat(false); | ||
} | ||
|
||
public void OnSystemLoaded(CharacterInfoSystem system) | ||
{ | ||
system.OnCharacterUpdate += CharacterUpdated; | ||
} | ||
|
||
public void OnSystemUnloaded(CharacterInfoSystem system) | ||
{ | ||
system.OnCharacterUpdate -= CharacterUpdated; | ||
} | ||
|
||
private void OnChatWindowOpacityChanged(float opacity) | ||
{ | ||
SetChatWindowOpacity(opacity); | ||
} | ||
|
||
private void CharacterUpdated(CharacterData data) | ||
{ | ||
// If the _charInfoIsAttach is false then the character panel created the event, dismiss. | ||
if (!_charInfoIsAttach) | ||
return; | ||
|
||
var (_, job, _, _, entityName) = data; | ||
|
||
// If the character has a normal name (eg. "Name Surname" and not "Name Initial Surname" or a particular species name) | ||
// subdivide it so that the name and surname individually get highlighted. | ||
if (entityName.Count(c => c == ' ') == 1) | ||
entityName = entityName.Replace(' ', '\n'); | ||
|
||
string newHighlights = entityName; | ||
|
||
// Convert the job title to kebab-case and use it as a key for the loc file. | ||
string jobKey = job.Replace(' ', '-').ToLower(); | ||
|
||
if (Loc.TryGetString($"highlights-{jobKey}", out var jobMatches)) | ||
newHighlights += '\n' + jobMatches.Replace(", ", "\n"); | ||
|
||
UpdateHighlights(newHighlights); | ||
HighlightsUpdated?.Invoke(newHighlights); | ||
_charInfoIsAttach = false; | ||
} | ||
|
||
private void SetChatWindowOpacity(float opacity) | ||
{ | ||
var chatBox = UIManager.ActiveScreen?.GetWidget<ChatBox>() ?? UIManager.ActiveScreen?.GetWidget<ResizableChatBox>(); | ||
|
@@ -426,6 +497,12 @@ public void SetSpeechBubbleRoot(LayoutContainer root) | |
private void OnAttachedChanged(EntityUid uid) | ||
{ | ||
UpdateChannelPermissions(); | ||
|
||
if (_autoFillHighlightsEnabled) | ||
{ | ||
_charInfoIsAttach = true; | ||
_characterInfo.RequestCharacterInfo(); | ||
} | ||
} | ||
|
||
private void AddSpeechBubble(ChatMessage msg, SpeechBubble.SpeechType speechType) | ||
|
@@ -584,6 +661,31 @@ public void ClearUnfilteredUnreads(ChatChannel channels) | |
} | ||
} | ||
|
||
public void UpdateHighlights(string highlights) | ||
{ | ||
// Save the newly provided list of highlighs if different. | ||
if (!_config.GetCVar(CCVars.ChatHighlights).Equals(highlights, StringComparison.CurrentCultureIgnoreCase)) | ||
{ | ||
_config.SetCVar(CCVars.ChatHighlights, highlights); | ||
_config.SaveToFile(); | ||
} | ||
|
||
// If the word is surrounded by "" we replace them with a whole-word regex tag. | ||
highlights = highlights.Replace("\"", "\\b"); | ||
|
||
// Fill the array with the highlights separated by newlines, disregarding empty entries. | ||
string[] arrHighlights = highlights.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
_highlights.Clear(); | ||
foreach (var keyword in arrHighlights) | ||
{ | ||
_highlights.Add(keyword); | ||
} | ||
|
||
// Arrange the list in descending order so that when highlighting, | ||
// the full word (eg. "Security") appears before the abbreviation (eg. "Sec"). | ||
_highlights.Sort((x, y) => y.Length.CompareTo(x.Length)); | ||
} | ||
|
||
public override void FrameUpdate(FrameEventArgs delta) | ||
{ | ||
UpdateQueuedSpeechBubbles(delta); | ||
|
@@ -824,6 +926,12 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true) | |
msg.WrappedMessage = SharedChatSystem.InjectTagInsideTag(msg, "Name", "color", GetNameColor(SharedChatSystem.GetStringInsideTag(msg, "Name"))); | ||
} | ||
|
||
// Color any words choosen by the client. | ||
foreach (var highlight in _highlights) | ||
{ | ||
msg.WrappedMessage = SharedChatSystem.InjectTagAroundString(msg, highlight, "color", _highlightsColor); | ||
} | ||
|
||
// Color any codewords for minds that have roles that use them | ||
if (_player.LocalUser != null && _mindSystem != null && _roleCodewordSystem != null) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
<controls:ChannelFilterPopup | ||
xmlns="https://spacestation14.io" | ||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. закрывай изменения тэгами корвакса |
||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Systems.Chat.Controls"> | ||
<PanelContainer Name="FilterPopupPanel" StyleClasses="BorderedWindowPanel"> | ||
<BoxContainer Orientation="Horizontal"> | ||
<Control MinSize="4 0"/> | ||
<BoxContainer Name="FilterVBox" MinWidth="110" Margin="0 10" Orientation="Vertical" SeparationOverride="4"/> | ||
<BoxContainer Orientation="Horizontal" SeparationOverride="8" Margin="10 0"> | ||
<BoxContainer Name="FilterVBox" MinWidth="105" Margin="0 10" Orientation="Vertical" SeparationOverride="4"/> | ||
<BoxContainer Name="HighlightsVBox" MinWidth="120" Margin="0 10" Orientation="Vertical" SeparationOverride="4"> | ||
<Label Text="{Loc 'hud-chatbox-highlights'}"/> | ||
<!-- Custom background for the TextEdit --> | ||
<PanelContainer> | ||
<PanelContainer.PanelOverride> | ||
<gfx:StyleBoxFlat BackgroundColor="#323446"/> | ||
</PanelContainer.PanelOverride> | ||
<TextEdit Name="HighlightEdit" MinHeight="150" Margin="5 5"/> | ||
</PanelContainer> | ||
<Button Name="HighlightButton" Text="{Loc 'hud-chatbox-highlights-button'}" ToolTip="{Loc 'hud-chatbox-highlights-tooltip'}"/> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</PanelContainer> | ||
</controls:ChannelFilterPopup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
закрой тэгами по типу // Corvax-Highlights-Start // Corvax-Highlights-End // Corvax-Highlights