1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Merge pull request #18622 from jai-x/chat-timestamp-colour

Enable nullable types in `ChatLine` and update timestamp colours to match design
This commit is contained in:
Dan Balasescu 2022-06-09 11:39:51 +09:00 committed by GitHub
commit 85c85f37c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using System;
using System.Linq;
using System.Collections.Generic;
@ -26,33 +28,6 @@ namespace osu.Game.Overlays.Chat
{
public class ChatLine : CompositeDrawable
{
protected virtual float TextSize => 20;
protected virtual float Spacing => 15;
protected virtual float TimestampWidth => 60;
protected virtual float UsernameWidth => 130;
private Color4 usernameColour;
private OsuSpriteText timestamp;
public ChatLine(Message message)
{
Message = message;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
[Resolved(CanBeNull = true)]
private ChannelManager chatManager { get; set; }
private Message message;
private OsuSpriteText username;
public LinkFlowContainer ContentFlow { get; private set; }
public Message Message
{
get => message;
@ -69,13 +44,45 @@ namespace osu.Game.Overlays.Chat
}
}
public LinkFlowContainer ContentFlow { get; private set; } = null!;
protected virtual float TextSize => 20;
protected virtual float Spacing => 15;
protected virtual float TimestampWidth => 60;
protected virtual float UsernameWidth => 130;
private Color4 usernameColour;
private OsuSpriteText timestamp = null!;
private Message message = null!;
private OsuSpriteText username = null!;
private Container? highlight;
private bool senderHasColour => !string.IsNullOrEmpty(message.Sender.Colour);
private bool messageHasColour => Message.IsAction && senderHasColour;
[Resolved]
private OsuColour colours { get; set; }
private ChannelManager? chatManager { get; set; }
[Resolved]
private OsuColour colours { get; set; } = null!;
public ChatLine(Message message)
{
Message = message;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load()
private void load(OverlayColourProvider? colourProvider)
{
usernameColour = senderHasColour
? Color4Extensions.FromHex(message.Sender.Colour)
@ -108,6 +115,7 @@ namespace osu.Game.Overlays.Chat
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: TextSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
MaxWidth = TimestampWidth,
Colour = colourProvider?.Background1 ?? Colour4.White,
},
new MessageSender(message.Sender)
{
@ -123,16 +131,8 @@ namespace osu.Game.Overlays.Chat
ContentFlow = new LinkFlowContainer(t =>
{
t.Shadow = false;
if (Message.IsAction)
{
t.Font = OsuFont.GetFont(italics: true);
if (senderHasColour)
t.Colour = Color4Extensions.FromHex(message.Sender.Colour);
}
t.Font = t.Font.With(size: TextSize);
t.Font = t.Font.With(size: TextSize, italics: Message.IsAction);
t.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White;
})
{
AutoSizeAxes = Axes.Y,
@ -151,8 +151,6 @@ namespace osu.Game.Overlays.Chat
FinishTransforms(true);
}
private Container highlight;
/// <summary>
/// Performs a highlight animation on this <see cref="ChatLine"/>.
/// </summary>
@ -250,18 +248,18 @@ namespace osu.Game.Overlays.Chat
{
private readonly APIUser sender;
private Action startChatAction;
private Action startChatAction = null!;
[Resolved]
private IAPIProvider api { get; set; }
private IAPIProvider api { get; set; } = null!;
public MessageSender(APIUser sender)
{
this.sender = sender;
}
[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profile, ChannelManager chatManager)
[BackgroundDependencyLoader]
private void load(UserProfileOverlay? profile, ChannelManager? chatManager)
{
Action = () => profile?.ShowUser(sender);
startChatAction = () => chatManager?.OpenPrivateChannel(sender);