Skip to content
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

Иконки в чате #1168

Merged
merged 7 commits into from
Jan 21, 2025
Merged
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
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/ExtraTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<!-- Graphics -->
<Label Text="{Loc 'ui-options-sunrise-general-graphics'}" StyleClasses="LabelKeyText"/>
<CheckBox Name="ChatIconsEnableCheckBox" Text="{Loc 'ui-options-chat-icons-enable'}" />

</BoxContainer>
</ScrollContainer>
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public ExtraTab()
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlaySelf, DamageOverlaySelfCheckBox);
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlayStructures, DamageOverlayStructuresCheckBox);

Control.AddOptionCheckBox(SunriseCCVars.ChatIconsEnable, ChatIconsEnableCheckBox);

Control.Initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +82,7 @@ private void OnChannelSelect(ChatSelectChannel channel)

public void Repopulate()
{
Contents.Clear();
ClearChatContents(); // Sunrise

foreach (var message in _controller.History)
{
Expand All @@ -91,7 +92,7 @@ public void Repopulate()

private void OnChannelFilter(ChatChannel channel, bool active)
{
Contents.Clear();
ClearChatContents(); // Sunrise

foreach (var message in _controller.History)
{
Expand All @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs
Original file line number Diff line number Diff line change
@@ -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<ChatUIController>().Repopulate();
}
}
100 changes: 100 additions & 0 deletions Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs
Original file line number Diff line number Diff line change
@@ -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";

/// <inheritdoc/>
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<FontResource>("/Fonts/NotoSans/NotoSans-Bold.ttf"), 13);

return label;
}

/// <summary>
/// Очищает строку от мусора, который приходит вместе с ней
/// </summary>
/// <remarks>
/// Почему мне приходят строки в говне
/// </remarks>
private static string ClearString(string str)
{
str = str.Replace("=", "");
str = str.Replace(" ", "");
str = str.Replace("\"", "");

return str;
}

}
42 changes: 42 additions & 0 deletions Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs
Original file line number Diff line number Diff line change
@@ -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";

/// <inheritdoc/>
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;
}
}
46 changes: 44 additions & 2 deletions Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +42,12 @@ public sealed class RadioSystem : EntitySystem

private EntityQuery<TelecomExemptComponent> _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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -213,6 +228,33 @@ private string GetIdCardColor(EntityUid senderUid)
return (!string.IsNullOrEmpty(color)) ? color : "#9FED58";
}

private string GetIdSprite(EntityUid senderUid)
{
if (HasComp<BorgChassisComponent>(senderUid))
return BorgIconPath;

if (HasComp<StationAiHeldComponent>(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;
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/_Sunrise/SunriseCCVars/SunriseCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,11 @@ public static readonly CVarDef<bool>

public static readonly CVarDef<bool> DamageOverlayStructures =
CVarDef.Create("damage_overlay.structures", true, CVar.CLIENTONLY | CVar.ARCHIVE);

/*
* Radio chat icons
*/

public static readonly CVarDef<bool> ChatIconsEnable =
CVarDef.Create("chat_icon.enable", true, CVar.CLIENTONLY | CVar.ARCHIVE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Использовать иконки в чате
Original file line number Diff line number Diff line change
@@ -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}"]
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/_strings/_sunrise/tags/texture.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
texture-tag-short = [tex path="{$path}"]
texture-tag = [tex path="{$path}" scale={$scale}]
Loading