Skip to content

Commit

Permalink
Implement changes from ImpStation PR
Browse files Browse the repository at this point in the history
  • Loading branch information
honeyed-lemons authored and Toby222 committed Feb 17, 2025
1 parent cf9df4e commit b8fe651
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared._DV.CartridgeLoader.Cartridges;
using Content.Shared.Access.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -8,9 +9,6 @@ namespace Content.Client._DV.CartridgeLoader.Cartridges;
[GenerateTypedNameReferences]
public sealed partial class NanoChatEntry : BoxContainer
{
private const int MaxNameLength = 14;
private const int MaxJobLength = 20;

public event Action<uint>? OnPressed;
private uint _number;
private Action<EventArgs>? _pressHandler;
Expand All @@ -32,8 +30,8 @@ public void SetRecipient(NanoChatRecipient recipient, uint number, bool isSelect
_pressHandler = _ => OnPressed?.Invoke(_number);
ChatButton.OnPressed += _pressHandler;

NameLabel.Text = Truncate(recipient.Name, MaxNameLength);
JobLabel.Text = Truncate(recipient.JobTitle ?? "", MaxJobLength);
NameLabel.Text = Truncate(recipient.Name, IdCardConsoleComponent.MaxFullNameLength);
JobLabel.Text = Truncate(recipient.JobTitle ?? "", IdCardConsoleComponent.MaxJobTitleLength);
JobLabel.Visible = !string.IsNullOrEmpty(recipient.JobTitle);
UnreadIndicator.Visible = recipient.HasUnread;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Numerics;
using Content.Shared._DV.CartridgeLoader.Cartridges;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

Expand Down Expand Up @@ -28,6 +29,19 @@ public void UpdateContactList(NanoChatUiState state)
for (var idx = 0; idx < contacts.Count; idx++)
{
var contact = contacts[idx];
var isEvenRow = idx % 2 == 0;
var contactControl = new ContactControl(contact, state, isEvenRow, OnStartChat);
ContactsList.AddChild(contactControl);
}
}

public sealed class ContactControl : PanelContainer
{
public ContactControl(NanoChatRecipient contact, NanoChatUiState state, bool isEvenRow, Action<NanoChatRecipient>? onStartChat)
{
HorizontalExpand = true;
StyleClasses.Add(isEvenRow ? "PanelBackgroundBaseDark" : "PanelBackgroundLight");

var nameLabel = new Label()
{
Text = contact.Name,
Expand All @@ -36,7 +50,7 @@ public void UpdateContactList(NanoChatUiState state)
};
var numberLabel = new Label()
{
Text = $"#{contacts[idx].Number:D4}",
Text = $"#{contact.Number:D4}",
HorizontalAlignment = HAlignment.Right,
Margin = new Thickness(0, 0, 36, 0),
};
Expand All @@ -49,25 +63,17 @@ public void UpdateContactList(NanoChatUiState state)
ToolTip = Loc.GetString("nano-chat-new-chat"),
};
startChatButton.AddStyleClass("OpenBoth");

if (contact.Number == state.OwnNumber || state.Recipients.ContainsKey(contact.Number) || state.MaxRecipients <= state.Recipients.Count)
{
startChatButton.Disabled = true;
}
startChatButton.OnPressed += _ => OnStartChat?.Invoke(contact);

var panel = new PanelContainer()
{
HorizontalExpand = true,
};

panel.AddChild(nameLabel);
panel.AddChild(numberLabel);
panel.AddChild(startChatButton);

var styleClass = idx % 2 == 0 ? "PanelBackgroundBaseDark" : "PanelBackgroundLight";
panel.StyleClasses.Add(styleClass);
startChatButton.OnPressed += _ => onStartChat?.Invoke(contact);

ContactsList.AddChild(panel);
AddChild(nameLabel);
AddChild(numberLabel);
AddChild(startChatButton);
}
}
}

0 comments on commit b8fe651

Please sign in to comment.