1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00

Merge pull request #29201 from peppy/chat-less-username-truncation

Adjust chat sizing to better fit long usernames
This commit is contained in:
Dan Balasescu 2024-07-30 23:09:48 +09:00 committed by GitHub
commit 13669fe949
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 21 deletions

View File

@ -6,6 +6,7 @@ using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
@ -88,19 +89,17 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestBackgroundAlternating() public void TestBackgroundAlternating()
{ {
var localUser = new APIUser
{
Id = 3,
Username = "LocalUser"
};
int messageCount = 1; int messageCount = 1;
AddRepeatStep("add messages", () => AddRepeatStep("add messages", () =>
{ {
channel.AddNewMessages(new Message(messageCount) channel.AddNewMessages(new Message(messageCount)
{ {
Sender = localUser, Sender = new APIUser
{
Id = 3,
Username = "LocalUser " + RNG.Next(0, int.MaxValue - 100).ToString("N")
},
Content = "Hi there all!", Content = "Hi there all!",
Timestamp = new DateTimeOffset(2022, 11, 21, 20, messageCount, 13, TimeSpan.Zero), Timestamp = new DateTimeOffset(2022, 11, 21, 20, messageCount, 13, TimeSpan.Zero),
Uuid = Guid.NewGuid().ToString(), Uuid = Guid.NewGuid().ToString(),

View File

@ -178,7 +178,7 @@ namespace osu.Game.Online.Chat
protected partial class StandAloneDaySeparator : DaySeparator protected partial class StandAloneDaySeparator : DaySeparator
{ {
protected override float TextSize => 14; protected override float TextSize => 13;
protected override float LineHeight => 1; protected override float LineHeight => 1;
protected override float Spacing => 5; protected override float Spacing => 5;
protected override float DateAlign => 125; protected override float DateAlign => 125;
@ -198,9 +198,9 @@ namespace osu.Game.Online.Chat
protected partial class StandAloneMessage : ChatLine protected partial class StandAloneMessage : ChatLine
{ {
protected override float FontSize => 15; protected override float FontSize => 13;
protected override float Spacing => 5; protected override float Spacing => 5;
protected override float UsernameWidth => 75; protected override float UsernameWidth => 90;
public StandAloneMessage(Message message) public StandAloneMessage(Message message)
: base(message) : base(message)

View File

@ -20,6 +20,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.Chat namespace osu.Game.Overlays.Chat
@ -46,11 +47,11 @@ namespace osu.Game.Overlays.Chat
public IReadOnlyCollection<Drawable> DrawableContentFlow => drawableContentFlow; public IReadOnlyCollection<Drawable> DrawableContentFlow => drawableContentFlow;
protected virtual float FontSize => 14; protected virtual float FontSize => 12;
protected virtual float Spacing => 15; protected virtual float Spacing => 15;
protected virtual float UsernameWidth => 130; protected virtual float UsernameWidth => 150;
[Resolved] [Resolved]
private ChannelManager? chatManager { get; set; } private ChannelManager? chatManager { get; set; }
@ -71,6 +72,24 @@ namespace osu.Game.Overlays.Chat
private Drawable? background; private Drawable? background;
private bool alternatingBackground; private bool alternatingBackground;
private bool requiresTimestamp = true;
public bool RequiresTimestamp
{
get => requiresTimestamp;
set
{
if (requiresTimestamp == value)
return;
requiresTimestamp = value;
if (!IsLoaded)
return;
updateMessageContent();
}
}
public bool AlternatingBackground public bool AlternatingBackground
{ {
@ -147,7 +166,7 @@ namespace osu.Game.Overlays.Chat
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
ColumnDimensions = new[] ColumnDimensions = new[]
{ {
new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.Absolute, 45),
new Dimension(GridSizeMode.Absolute, Spacing + UsernameWidth + Spacing), new Dimension(GridSizeMode.Absolute, Spacing + UsernameWidth + Spacing),
new Dimension(), new Dimension(),
}, },
@ -158,9 +177,10 @@ namespace osu.Game.Overlays.Chat
drawableTimestamp = new OsuSpriteText drawableTimestamp = new OsuSpriteText
{ {
Shadow = false, Shadow = false,
Anchor = Anchor.CentreLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.TopLeft,
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true), Spacing = new Vector2(-1, 0),
Font = OsuFont.GetFont(size: FontSize, weight: FontWeight.SemiBold, fixedWidth: true),
AlwaysPresent = true, AlwaysPresent = true,
}, },
drawableUsername = new DrawableChatUsername(message.Sender) drawableUsername = new DrawableChatUsername(message.Sender)
@ -244,9 +264,17 @@ namespace osu.Game.Overlays.Chat
private void updateMessageContent() private void updateMessageContent()
{ {
this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint); this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint);
drawableTimestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint);
updateTimestamp(); if (requiresTimestamp && !(message is LocalEchoMessage))
{
drawableTimestamp.Show();
updateTimestamp();
}
else
{
drawableTimestamp.Hide();
}
drawableUsername.Text = $@"{message.Sender.Username}"; drawableUsername.Text = $@"{message.Sender.Username}";
// remove non-existent channels from the link list // remove non-existent channels from the link list
@ -258,7 +286,7 @@ namespace osu.Game.Overlays.Chat
private void updateTimestamp() private void updateTimestamp()
{ {
drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm:ss" : @"hh:mm:ss tt"); drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm" : @"hh:mm tt");
} }
private static readonly Color4[] default_username_colours = private static readonly Color4[] default_username_colours =

View File

@ -14,7 +14,7 @@ namespace osu.Game.Overlays.Chat
{ {
public partial class DaySeparator : Container public partial class DaySeparator : Container
{ {
protected virtual float TextSize => 15; protected virtual float TextSize => 13;
protected virtual float LineHeight => 2; protected virtual float LineHeight => 2;

View File

@ -61,7 +61,7 @@ namespace osu.Game.Overlays.Chat
Padding = new MarginPadding { Bottom = 5 }, Padding = new MarginPadding { Bottom = 5 },
Child = ChatLineFlow = new FillFlowContainer Child = ChatLineFlow = new FillFlowContainer
{ {
Padding = new MarginPadding { Horizontal = 10 }, Padding = new MarginPadding { Left = 3, Right = 10 },
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
@ -88,10 +88,18 @@ namespace osu.Game.Overlays.Chat
{ {
base.Update(); base.Update();
long? lastMinutes = null;
for (int i = 0; i < ChatLineFlow.Count; i++) for (int i = 0; i < ChatLineFlow.Count; i++)
{ {
if (ChatLineFlow[i] is ChatLine chatline) if (ChatLineFlow[i] is ChatLine chatline)
{
long minutes = chatline.Message.Timestamp.ToUnixTimeSeconds() / 60;
chatline.AlternatingBackground = i % 2 == 0; chatline.AlternatingBackground = i % 2 == 0;
chatline.RequiresTimestamp = minutes != lastMinutes;
lastMinutes = minutes;
}
} }
} }