From e194bc1fe3cdaca6ed6c7a0d151b77343453cbf3 Mon Sep 17 00:00:00 2001
From: ThereDrD <88589686+ThereDrD0@users.noreply.github.com>
Date: Wed, 22 Jan 2025 00:57:20 +0300
Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BA=D0=BE=D0=BD=D0=BA=D0=B8=20=D0=B2?=
=?UTF-8?q?=20=D1=87=D0=B0=D1=82=D0=B5=20(#1168)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* init
* refactor: move scale to tag argument
* fix: chatbox rebuild fix
* tweak: add icons for non-humanoid roles like ai and borgs
* add: switch option for radio icons
* blyat commit
* fix
---
Content.Client/Options/UI/Tabs/ExtraTab.xaml | 1 +
.../Options/UI/Tabs/ExtraTab.xaml.cs | 2 +
.../Systems/Chat/Widgets/ChatBox.xaml.cs | 20 +++-
.../_Sunrise/ChatIcons/RadioIconsSystem.cs | 31 ++++++
.../UserInterface/RichText/RadioIconTag.cs | 100 ++++++++++++++++++
.../UserInterface/RichText/TextureTag.cs | 42 ++++++++
.../Radio/EntitySystems/RadioSystem.cs | 46 +++++++-
.../_Sunrise/SunriseCCVars/SunriseCCVars.cs | 7 ++
.../_sunrise/escape-menu/ui/options-menu.ftl | 2 +
.../_strings/_sunrise/tags/radio_icon.ftl | 2 +
.../ru-RU/_strings/_sunrise/tags/texture.ftl | 2 +
11 files changed, 251 insertions(+), 4 deletions(-)
create mode 100644 Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs
create mode 100644 Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs
create mode 100644 Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs
create mode 100644 Resources/Locale/ru-RU/_strings/_sunrise/tags/radio_icon.ftl
create mode 100644 Resources/Locale/ru-RU/_strings/_sunrise/tags/texture.ftl
diff --git a/Content.Client/Options/UI/Tabs/ExtraTab.xaml b/Content.Client/Options/UI/Tabs/ExtraTab.xaml
index 9bed634b1a1..a03abf8baa1 100644
--- a/Content.Client/Options/UI/Tabs/ExtraTab.xaml
+++ b/Content.Client/Options/UI/Tabs/ExtraTab.xaml
@@ -32,6 +32,7 @@
+
diff --git a/Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs b/Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs
index 0e0e1a88231..c7bd607e3d3 100644
--- a/Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs
+++ b/Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs
@@ -92,6 +92,8 @@ public ExtraTab()
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlaySelf, DamageOverlaySelfCheckBox);
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlayStructures, DamageOverlayStructuresCheckBox);
+ Control.AddOptionCheckBox(SunriseCCVars.ChatIconsEnable, ChatIconsEnableCheckBox);
+
Control.Initialize();
}
diff --git a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
index d55b3f01dfa..bb5505d3c47 100644
--- a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
+++ b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
@@ -13,6 +13,7 @@
using Robust.Shared.Input;
using Robust.Shared.Player;
using Robust.Shared.Utility;
+using System.Linq;
using static Robust.Client.UserInterface.Controls.LineEdit;
namespace Content.Client.UserInterface.Systems.Chat.Widgets;
@@ -81,7 +82,7 @@ private void OnChannelSelect(ChatSelectChannel channel)
public void Repopulate()
{
- Contents.Clear();
+ ClearChatContents(); // Sunrise
foreach (var message in _controller.History)
{
@@ -91,7 +92,7 @@ public void Repopulate()
private void OnChannelFilter(ChatChannel channel, bool active)
{
- Contents.Clear();
+ ClearChatContents(); // Sunrise
foreach (var message in _controller.History)
{
@@ -104,6 +105,21 @@ private void OnChannelFilter(ChatChannel channel, bool active)
}
}
+ // Sunrise start
+ private void ClearChatContents()
+ {
+ Contents.Clear();
+
+ foreach (var child in Contents.Children.ToArray())
+ {
+ if (child.Name != "_v_scroll")
+ {
+ Contents.RemoveChild(child);
+ }
+ }
+ }
+ // Sunrise end
+
public void AddLine(string message, Color color)
{
var formatted = new FormattedMessage(3);
diff --git a/Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs b/Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs
new file mode 100644
index 00000000000..3ea44b18cfe
--- /dev/null
+++ b/Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs
@@ -0,0 +1,31 @@
+using Content.Client.UserInterface.Systems.Chat;
+using Content.Shared._Sunrise.SunriseCCVars;
+using Robust.Client.UserInterface;
+using Robust.Shared.Configuration;
+
+namespace Content.Client._Sunrise.ChatIcons;
+
+public sealed class ChatIconsSystem : EntitySystem
+{
+ [Dependency] private readonly IConfigurationManager _cfg = default!;
+ [Dependency] private readonly IUserInterfaceManager _uiMan = default!;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ _cfg.OnValueChanged(SunriseCCVars.ChatIconsEnable, OnRadioIconsChanged, true);
+ }
+
+ public override void Shutdown()
+ {
+ base.Shutdown();
+
+ _cfg.UnsubValueChanged(SunriseCCVars.ChatIconsEnable, OnRadioIconsChanged);
+ }
+
+ private void OnRadioIconsChanged(bool enable)
+ {
+ _uiMan.GetUIController().Repopulate();
+ }
+}
diff --git a/Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs b/Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs
new file mode 100644
index 00000000000..c62dad41d0a
--- /dev/null
+++ b/Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs
@@ -0,0 +1,100 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Numerics;
+using Content.Shared._Sunrise.SunriseCCVars;
+using Robust.Client.Graphics;
+using Robust.Client.ResourceManagement;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+using Robust.Client.UserInterface.RichText;
+using Robust.Shared.Configuration;
+using Robust.Shared.Utility;
+
+namespace Content.Client._Sunrise.UserInterface.RichText;
+
+public sealed class RadioIconTag : IMarkupTag
+{
+ [Dependency] private readonly IConfigurationManager _cfg = default!;
+ [Dependency] private readonly IResourceCache _cache = default!;
+
+ public string Name => "radicon";
+
+ ///
+ public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
+ {
+ if (_cfg.GetCVar(SunriseCCVars.ChatIconsEnable))
+ {
+ if (!node.Attributes.TryGetValue("path", out var rawPath))
+ {
+ control = null;
+ return false;
+ }
+
+ if (!node.Attributes.TryGetValue("scale", out var scale) || !scale.TryGetLong(out var scaleValue))
+ {
+ scaleValue = 1;
+ }
+
+ control = DrawIcon(rawPath.ToString(), scaleValue.Value);
+ }
+ else
+ {
+ if (!node.Attributes.TryGetValue("text", out var text))
+ {
+ control = null;
+ return false;
+ }
+
+ if (!node.Attributes.TryGetValue("color", out var color))
+ {
+ control = null;
+ return false;
+ }
+
+ control = DrawText(text.ToString(), color.ToString());
+ }
+
+ return true;
+ }
+
+ private Control DrawIcon(string path, long scaleValue)
+ {
+ var texture = new TextureRect();
+
+ path = ClearString(path);
+
+ texture.TexturePath = path;
+ texture.TextureScale = new Vector2(scaleValue, scaleValue);
+
+ return texture;
+ }
+
+ private Control DrawText(string text, string color)
+ {
+ var label = new Label();
+
+ color = ClearString(color);
+ text = ClearString(text);
+
+ label.Text = text;
+ label.FontColorOverride = Color.FromHex(color);
+ label.FontOverride = new VectorFont(_cache.GetResource("/Fonts/NotoSans/NotoSans-Bold.ttf"), 13);
+
+ return label;
+ }
+
+ ///
+ /// Очищает строку от мусора, который приходит вместе с ней
+ ///
+ ///
+ /// Почему мне приходят строки в говне
+ ///
+ private static string ClearString(string str)
+ {
+ str = str.Replace("=", "");
+ str = str.Replace(" ", "");
+ str = str.Replace("\"", "");
+
+ return str;
+ }
+
+}
diff --git a/Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs b/Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs
new file mode 100644
index 00000000000..34d1a380d21
--- /dev/null
+++ b/Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs
@@ -0,0 +1,42 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Numerics;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+using Robust.Client.UserInterface.RichText;
+
+using Robust.Shared.Utility;
+
+namespace Content.Client._Sunrise.UserInterface.RichText;
+
+public sealed class TextureTag : IMarkupTag
+{
+ public string Name => "tex";
+
+ ///
+ public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
+ {
+ if (!node.Attributes.TryGetValue("path", out var rawPath))
+ {
+ control = null;
+ return false;
+ }
+
+ if (!node.Attributes.TryGetValue("scale", out var scale) || !scale.TryGetLong(out var scaleValue))
+ {
+ scaleValue = 1;
+ }
+
+ var texture = new TextureRect();
+
+ var path = rawPath.ToString();
+ path = path.Replace("=", "");
+ path = path.Replace(" ", "");
+ path = path.Replace("\"", "");
+
+ texture.TexturePath = path;
+ texture.TextureScale = new Vector2(scaleValue.Value, scaleValue.Value);
+
+ control = texture;
+ return true;
+ }
+}
diff --git a/Content.Server/Radio/EntitySystems/RadioSystem.cs b/Content.Server/Radio/EntitySystems/RadioSystem.cs
index 9ba10252e5c..be84179f48a 100644
--- a/Content.Server/Radio/EntitySystems/RadioSystem.cs
+++ b/Content.Server/Radio/EntitySystems/RadioSystem.cs
@@ -11,6 +11,8 @@
using Content.Shared.PDA;
using Content.Shared.Radio;
using Content.Shared.Radio.Components;
+using Content.Shared.Silicons.Borgs.Components;
+using Content.Shared.Silicons.StationAi;
using Content.Shared.Speech;
using Robust.Shared.Map;
using Robust.Shared.Network;
@@ -40,6 +42,12 @@ public sealed class RadioSystem : EntitySystem
private EntityQuery _exemptQuery;
+ // Sunrise start
+ private const string NoIdIconPath = "/Textures/Interface/Misc/job_icons.rsi/NoId.png";
+ private const string StationAiIconPath = "/Textures/Interface/Misc/job_icons.rsi/StationAi.png";
+ private const string BorgIconPath = "/Textures/Interface/Misc/job_icons.rsi/Borg.png";
+ // Sunrise end
+
public override void Initialize()
{
base.Initialize();
@@ -90,7 +98,14 @@ public void SendRadioMessage(EntityUid messageSource, string message, RadioChann
name = FormattedMessage.EscapeText(name);
// Sunrise-Start
- var formattedName = $"[color={GetIdCardColor(messageSource)}]{GetIdCardName(messageSource)}{name}[/color]";
+ var tag = Loc.GetString("radio-icon-tag",
+ ("path", GetIdSprite(messageSource)),
+ ("scale", "3"),
+ ("text", GetIdCardName(messageSource)),
+ ("color", GetIdCardColor(messageSource))
+ );
+
+ var formattedName = $"{tag} {name}";
// Sunrise-End
SpeechVerbPrototype speech;
@@ -204,7 +219,7 @@ private string GetIdCardName(EntityUid senderUid)
var textInfo = CultureInfo.CurrentCulture.TextInfo;
idCardTitle = textInfo.ToTitleCase(idCardTitle);
- return $"\\[{idCardTitle}\\] ";
+ return $"[{idCardTitle}] ";
}
private string GetIdCardColor(EntityUid senderUid)
@@ -213,6 +228,33 @@ private string GetIdCardColor(EntityUid senderUid)
return (!string.IsNullOrEmpty(color)) ? color : "#9FED58";
}
+ private string GetIdSprite(EntityUid senderUid)
+ {
+ if (HasComp(senderUid))
+ return BorgIconPath;
+
+ if (HasComp(senderUid))
+ return StationAiIconPath;
+
+ var protoId = GetIdCard(senderUid)?.JobIcon;
+ var sprite = NoIdIconPath;
+
+ if (_prototype.TryIndex(protoId, out var prototype))
+ {
+ switch (prototype.Icon)
+ {
+ case SpriteSpecifier.Texture tex:
+ sprite = tex.TexturePath.CanonPath;
+ break;
+ case SpriteSpecifier.Rsi rsi:
+ sprite = rsi.RsiPath.CanonPath + "/" + rsi.RsiState + ".png";
+ break;
+ }
+ }
+
+ return sprite;
+ }
+
private bool GetIdCardIsBold(EntityUid senderUid)
{
return GetIdCard(senderUid)?.RadioBold ?? false;
diff --git a/Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs b/Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
index 135bf33fd3f..aa1c8ae8613 100644
--- a/Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
+++ b/Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
@@ -405,4 +405,11 @@ public static readonly CVarDef
public static readonly CVarDef DamageOverlayStructures =
CVarDef.Create("damage_overlay.structures", true, CVar.CLIENTONLY | CVar.ARCHIVE);
+
+ /*
+ * Radio chat icons
+ */
+
+ public static readonly CVarDef ChatIconsEnable =
+ CVarDef.Create("chat_icon.enable", true, CVar.CLIENTONLY | CVar.ARCHIVE);
}
diff --git a/Resources/Locale/ru-RU/_strings/_sunrise/escape-menu/ui/options-menu.ftl b/Resources/Locale/ru-RU/_strings/_sunrise/escape-menu/ui/options-menu.ftl
index 80983017cd9..b97317e8294 100644
--- a/Resources/Locale/ru-RU/_strings/_sunrise/escape-menu/ui/options-menu.ftl
+++ b/Resources/Locale/ru-RU/_strings/_sunrise/escape-menu/ui/options-menu.ftl
@@ -20,3 +20,5 @@ ui-options-function-reloading = Перезарядка
ui-options-function-look-up = Присмотреться/Прицелиться
ui-options-function-auto-get-up = Автоматически вставать при падении
ui-options-function-hold-look-up = Удерживать клавишу для прицеливания
+
+ui-options-chat-icons-enable = Использовать иконки в чате
diff --git a/Resources/Locale/ru-RU/_strings/_sunrise/tags/radio_icon.ftl b/Resources/Locale/ru-RU/_strings/_sunrise/tags/radio_icon.ftl
new file mode 100644
index 00000000000..c36c23ed09c
--- /dev/null
+++ b/Resources/Locale/ru-RU/_strings/_sunrise/tags/radio_icon.ftl
@@ -0,0 +1,2 @@
+radio-icon-tag-short = [radicon path="{$path}" text="{$text}" color="{$color}"]
+radio-icon-tag = [radicon path="{$path}" scale={$scale} text="{$text}" color="{$color}"]
diff --git a/Resources/Locale/ru-RU/_strings/_sunrise/tags/texture.ftl b/Resources/Locale/ru-RU/_strings/_sunrise/tags/texture.ftl
new file mode 100644
index 00000000000..2155eb915d1
--- /dev/null
+++ b/Resources/Locale/ru-RU/_strings/_sunrise/tags/texture.ftl
@@ -0,0 +1,2 @@
+texture-tag-short = [tex path="{$path}"]
+texture-tag = [tex path="{$path}" scale={$scale}]