mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using Content.Shared._DV.CartridgeLoader.Cartridges;
|
|
using Content.Shared._DV.NanoChat;
|
|
using Content.Shared.Access.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._DV.CartridgeLoader.Cartridges;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class NanoChatEntry : BoxContainer
|
|
{
|
|
public event Action<uint>? OnPressed;
|
|
private uint _number;
|
|
private Action<EventArgs>? _pressHandler;
|
|
|
|
private int _maxNameLength;
|
|
private int _maxIdJobLength;
|
|
|
|
public NanoChatEntry(int maxNameLength, int maxIdJobLength)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_maxNameLength = maxNameLength;
|
|
_maxIdJobLength = maxIdJobLength;
|
|
}
|
|
|
|
public void SetRecipient(NanoChatRecipient recipient, uint number, bool isSelected)
|
|
{
|
|
// Remove old handler if it exists
|
|
if (_pressHandler != null)
|
|
ChatButton.OnPressed -= _pressHandler;
|
|
|
|
_number = number;
|
|
|
|
// Create and store new handler
|
|
_pressHandler = _ => OnPressed?.Invoke(_number);
|
|
ChatButton.OnPressed += _pressHandler;
|
|
|
|
// FIXME: Truncate and Escape can lead to stray `\`, if the truncate cuts a markup tag in half
|
|
NameLabel.Text = FormattedMessage.EscapeText(SharedNanoChatSystem.Truncate(recipient.Name, _maxNameLength));
|
|
JobLabel.Text = FormattedMessage.EscapeText(SharedNanoChatSystem.Truncate(recipient.JobTitle ?? string.Empty, _maxIdJobLength));
|
|
JobLabel.Visible = !string.IsNullOrWhiteSpace(JobLabel.Text);
|
|
UnreadIndicator.Visible = recipient.HasUnread;
|
|
GroupIcon.Visible = recipient.IsGroup;
|
|
|
|
ChatButton.ModulateSelfOverride = isSelected ? NanoChatMessageBubble.OwnMessageColor : null;
|
|
}
|
|
}
|