2022-01-03 00:54:44 +00:00
|
|
|
#nullable enable
|
2022-01-03 02:36:25 +01:00
|
|
|
using System;
|
|
|
|
|
using Content.Shared.Administration;
|
2022-01-03 00:54:44 +00:00
|
|
|
using Robust.Client.AutoGenerated;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
|
using Robust.Shared.Network;
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.Administration.UI.CustomControls
|
|
|
|
|
{
|
|
|
|
|
[GenerateTypedNameReferences]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class BwoinkPanel : BoxContainer
|
2022-01-03 00:54:44 +00:00
|
|
|
{
|
|
|
|
|
private readonly BwoinkSystem _bwoinkSystem;
|
|
|
|
|
public readonly NetUserId ChannelId;
|
|
|
|
|
|
|
|
|
|
public int Unread { get; private set; } = 0;
|
2022-01-03 04:14:10 +01:00
|
|
|
public DateTime LastMessage { get; private set; } = DateTime.MinValue;
|
2022-01-03 00:54:44 +00:00
|
|
|
|
|
|
|
|
public BwoinkPanel(BwoinkSystem bwoinkSys, NetUserId userId)
|
|
|
|
|
{
|
|
|
|
|
RobustXamlLoader.Load(this);
|
|
|
|
|
_bwoinkSystem = bwoinkSys;
|
|
|
|
|
ChannelId = userId;
|
|
|
|
|
|
|
|
|
|
OnVisibilityChanged += c =>
|
|
|
|
|
{
|
|
|
|
|
if (c.Visible)
|
|
|
|
|
Unread = 0;
|
|
|
|
|
};
|
|
|
|
|
SenderLineEdit.OnTextEntered += Input_OnTextEntered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
|
|
|
|
|
{
|
2022-01-03 04:14:10 +01:00
|
|
|
if (string.IsNullOrWhiteSpace(args.Text))
|
|
|
|
|
return;
|
2022-01-03 00:54:44 +00:00
|
|
|
|
2022-01-03 04:14:10 +01:00
|
|
|
_bwoinkSystem.Send(ChannelId, args.Text);
|
2022-01-03 00:54:44 +00:00
|
|
|
SenderLineEdit.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 02:36:25 +01:00
|
|
|
public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message)
|
2022-01-03 00:54:44 +00:00
|
|
|
{
|
|
|
|
|
if (!Visible)
|
|
|
|
|
Unread++;
|
2022-01-03 02:36:25 +01:00
|
|
|
|
2022-01-03 00:54:44 +00:00
|
|
|
var formatted = new FormattedMessage(1);
|
2022-01-03 02:36:25 +01:00
|
|
|
formatted.AddMarkup($"[color=gray]{message.SentAt.ToShortTimeString()}[/color] {message.Text}");
|
2022-01-03 00:54:44 +00:00
|
|
|
TextOutput.AddMessage(formatted);
|
2022-01-03 02:36:25 +01:00
|
|
|
LastMessage = message.SentAt;
|
2022-01-03 00:54:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|