Skip to content

Commit

Permalink
Merge branch 'arumoon-server' into clothhead
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0maks committed Aug 16, 2023
2 parents 10a2fc4 + 99f1cd2 commit f4c1e46
Show file tree
Hide file tree
Showing 1,585 changed files with 127,060 additions and 105,014 deletions.
17 changes: 17 additions & 0 deletions Content.Client/Administration/Systems/BwoinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Shared.Network;
using Robust.Shared.Timing;

namespace Content.Client.Administration.Systems
{
[UsedImplicitly]
public sealed class BwoinkSystem : SharedBwoinkSystem
{
[Dependency] private readonly IGameTiming _timing = default!;

public event EventHandler<BwoinkTextMessage>? OnBwoinkTextMessageRecieved;
private (TimeSpan Timestamp, bool Typing) _lastTypingUpdateSent;

protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs)
{
Expand All @@ -20,6 +24,19 @@ public void Send(NetUserId channelId, string text)
// Reuse the channel ID as the 'true sender'.
// Server will ignore this and if someone makes it not ignore this (which is bad, allows impersonation!!!), that will help.
RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text));
SendInputTextUpdated(channelId, false);
}

public void SendInputTextUpdated(NetUserId channel, bool typing)
{
if (_lastTypingUpdateSent.Typing == typing &&
_lastTypingUpdateSent.Timestamp + TimeSpan.FromSeconds(1) > _timing.RealTime)
{
return;
}

_lastTypingUpdateSent = (_timing.RealTime, typing);
RaiseNetworkEvent(new BwoinkClientTypingUpdated(channel, typing));
}
}
}
1 change: 1 addition & 0 deletions Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Orientation="Vertical"
HorizontalExpand="True">
<OutputPanel Name="TextOutput" VerticalExpand="true" />
<RichTextLabel Name="TypingIndicator" Access="Public" />
<HistoryLineEdit Name="SenderLineEdit" />
<RichTextLabel Name="RelayedToDiscordLabel" Access="Public" Visible="False" />
</BoxContainer>
59 changes: 59 additions & 0 deletions Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.Administration.UI.Bwoink
Expand All @@ -13,6 +14,8 @@ public sealed partial class BwoinkPanel : BoxContainer

public int Unread { get; private set; } = 0;
public DateTime LastMessage { get; private set; } = DateTime.MinValue;
private List<string> PeopleTyping { get; set; } = new();
public event Action<string>? InputTextChanged;

public BwoinkPanel(Action<string> messageSender)
{
Expand All @@ -32,6 +35,8 @@ public BwoinkPanel(Action<string> messageSender)
Unread = 0;
};
SenderLineEdit.OnTextEntered += Input_OnTextEntered;
SenderLineEdit.OnTextChanged += Input_OnTextChanged;
UpdateTypingIndicator();
}

private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
Expand All @@ -43,6 +48,11 @@ private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
SenderLineEdit.Clear();
}

private void Input_OnTextChanged(LineEdit.LineEditEventArgs args)
{
InputTextChanged?.Invoke(args.Text);
}

public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message)
{
if (!Visible)
Expand All @@ -53,5 +63,54 @@ public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message)
TextOutput.AddMessage(formatted);
LastMessage = message.SentAt;
}

private void UpdateTypingIndicator()
{
var msg = new FormattedMessage();
msg.PushColor(Color.LightGray);

var text = PeopleTyping.Count == 0
? string.Empty
: Loc.GetString("bwoink-system-typing-indicator",
("players", string.Join(", ", PeopleTyping)),
("count", PeopleTyping.Count));

msg.AddText(text);
msg.Pop();

TypingIndicator.SetMessage(msg);
}

public void UpdatePlayerTyping(string name, bool typing)
{
if (typing)
{
if (PeopleTyping.Contains(name))
return;

PeopleTyping.Add(name);
Timer.Spawn(TimeSpan.FromSeconds(10), () =>
{
if (Disposed)
return;
PeopleTyping.Remove(name);
UpdateTypingIndicator();
});
}
else
{
PeopleTyping.Remove(name);
}

UpdateTypingIndicator();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

InputTextChanged = null;
}
}
}
18 changes: 12 additions & 6 deletions Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,18 @@ private void SetTypes(LogType[] types)
public void SetPlayers(Dictionary<Guid, string> players)
{
var buttons = new SortedSet<AdminLogPlayerButton>(_adminLogPlayerButtonComparer);
var allSelected = true;

foreach (var control in PlayersContainer.Children.ToArray())
{
if (control is not AdminLogPlayerButton player ||
!players.Remove(player.Id))
{
if (control is not AdminLogPlayerButton player)
continue;

if (!SelectedPlayers.Contains(player.Id))
allSelected = false;

if (!players.Remove(player.Id))
continue;
}

buttons.Add(player);
}
Expand All @@ -437,10 +441,12 @@ public void SetPlayers(Dictionary<Guid, string> players)
var button = new AdminLogPlayerButton(id)
{
Text = name,
Pressed = true
Pressed = allSelected
};

SelectedPlayers.Add(id);
if (allSelected)
SelectedPlayers.Add(id);

button.OnPressed += PlayerButtonPressed;

buttons.Add(button);
Expand Down
70 changes: 57 additions & 13 deletions Content.Client/Administration/UI/Notes/AdminNotesControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,64 @@ private bool NoteClicked(AdminNotesLine line)
};

_popup.OnDeletePressed += (noteId, noteType) => NoteDeleted?.Invoke(noteId, noteType);
_popup.OnPopupHide += OnPopupHide;

var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, Vector2.One);
_popup.Open(box);

return true;
}

private void OnPopupHide()
{
if (_popup == null ||
!Inputs.TryGetValue((_popup.NoteId, _popup.NoteType), out var input))
{
return;
}

UpdateNoteLineAlpha(input);
}

private void NoteMouseEntered(GUIMouseHoverEventArgs args)
{
if (args.SourceControl is not AdminNotesLine line)
return;

line.Modulate = line.Modulate.WithAlpha(1f);
}

private void NoteMouseExited(GUIMouseHoverEventArgs args)
{
if (args.SourceControl is not AdminNotesLine line)
return;

if (_popup?.NoteId == line.Note.Id && _popup.Visible)
return;

UpdateNoteLineAlpha(line);
}

private void UpdateNoteLineAlpha(AdminNotesLine input)
{
var timeDiff = DateTime.UtcNow - input.Note.CreatedAt;
float alpha;
if (_noteFreshDays == 0 || timeDiff.TotalDays <= _noteFreshDays)
{
alpha = 1f;
}
else if (_noteStaleDays == 0 || timeDiff.TotalDays > _noteStaleDays)
{
alpha = 0f;
}
else
{
alpha = (float) (1 - Math.Clamp((timeDiff.TotalDays - _noteFreshDays) / (_noteStaleDays - _noteFreshDays), 0, 1));
}

input.Modulate = input.Modulate.WithAlpha(alpha);
}

public void SetNotes(Dictionary<(int, NoteType), SharedAdminNote> notes)
{
foreach (var (key, input) in Inputs)
Expand All @@ -119,25 +171,17 @@ public void SetNotes(Dictionary<(int, NoteType), SharedAdminNote> notes)

input = new AdminNotesLine(_sprites, note);
input.OnClicked += NoteClicked;
input.OnMouseEntered += NoteMouseEntered;
input.OnMouseExited += NoteMouseExited;

var timeDiff = DateTime.UtcNow - note.CreatedAt;
float alpha;
if (_noteFreshDays == 0 || timeDiff.TotalDays <= _noteFreshDays)
{
alpha = 1f;
}
else if (_noteStaleDays == 0 || timeDiff.TotalDays > _noteStaleDays)
UpdateNoteLineAlpha(input);

if (input.Modulate.A == 0)
{
alpha = 0f;
input.Visible = false;
showMoreButtonVisible = true;
}
else
{
alpha = (float) (1 - Math.Clamp((timeDiff.TotalDays - _noteFreshDays) / (_noteStaleDays - _noteFreshDays), 0, 1));
}

input.Modulate = input.Modulate.WithAlpha(alpha);
Notes.AddChild(input);
Inputs[(note.Id, note.NoteType)] = input;
ShowMoreButton.Visible = showMoreButtonVisible;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Text;
using Content.Client.Resources;
using Content.Shared.Administration.Notes;
using Content.Shared.Database;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand Down Expand Up @@ -56,7 +53,7 @@ public AdminNotesLine(SpriteSystem sprites, SharedAdminNote note)
private void Refresh()
{
string? iconPath;
if(Note.NoteSeverity is not null)
if (Note.NoteSeverity is not null && !NoteTypeIcons.ContainsKey(Note.NoteType))
SeverityIcons.TryGetValue(Note.NoteSeverity.Value, out iconPath);
else
NoteTypeIcons.TryGetValue(Note.NoteType, out iconPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public AdminNotesLinePopup(SharedAdminNote note, string playerName, bool showDel
DeleteButton.OnPressed += DeletePressed;
}

private int NoteId { get; }
private NoteType NoteType { get; }
public int NoteId { get; }
public NoteType NoteType { get; }
private TimeSpan? DeleteResetOn { get; set; }

private void EditPressed(ButtonEventArgs args)
Expand Down
Loading

0 comments on commit f4c1e46

Please sign in to comment.