mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:42:58 +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:
commit
85c85f37c6
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -26,33 +28,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
{
|
{
|
||||||
public class ChatLine : CompositeDrawable
|
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
|
public Message Message
|
||||||
{
|
{
|
||||||
get => 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 senderHasColour => !string.IsNullOrEmpty(message.Sender.Colour);
|
||||||
|
|
||||||
|
private bool messageHasColour => Message.IsAction && senderHasColour;
|
||||||
|
|
||||||
[Resolved]
|
[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]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(OverlayColourProvider? colourProvider)
|
||||||
{
|
{
|
||||||
usernameColour = senderHasColour
|
usernameColour = senderHasColour
|
||||||
? Color4Extensions.FromHex(message.Sender.Colour)
|
? Color4Extensions.FromHex(message.Sender.Colour)
|
||||||
@ -108,6 +115,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Font = OsuFont.GetFont(size: TextSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
Font = OsuFont.GetFont(size: TextSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
||||||
MaxWidth = TimestampWidth,
|
MaxWidth = TimestampWidth,
|
||||||
|
Colour = colourProvider?.Background1 ?? Colour4.White,
|
||||||
},
|
},
|
||||||
new MessageSender(message.Sender)
|
new MessageSender(message.Sender)
|
||||||
{
|
{
|
||||||
@ -123,16 +131,8 @@ namespace osu.Game.Overlays.Chat
|
|||||||
ContentFlow = new LinkFlowContainer(t =>
|
ContentFlow = new LinkFlowContainer(t =>
|
||||||
{
|
{
|
||||||
t.Shadow = false;
|
t.Shadow = false;
|
||||||
|
t.Font = t.Font.With(size: TextSize, italics: Message.IsAction);
|
||||||
if (Message.IsAction)
|
t.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White;
|
||||||
{
|
|
||||||
t.Font = OsuFont.GetFont(italics: true);
|
|
||||||
|
|
||||||
if (senderHasColour)
|
|
||||||
t.Colour = Color4Extensions.FromHex(message.Sender.Colour);
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Font = t.Font.With(size: TextSize);
|
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -151,8 +151,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Container highlight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs a highlight animation on this <see cref="ChatLine"/>.
|
/// Performs a highlight animation on this <see cref="ChatLine"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -250,18 +248,18 @@ namespace osu.Game.Overlays.Chat
|
|||||||
{
|
{
|
||||||
private readonly APIUser sender;
|
private readonly APIUser sender;
|
||||||
|
|
||||||
private Action startChatAction;
|
private Action startChatAction = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
public MessageSender(APIUser sender)
|
public MessageSender(APIUser sender)
|
||||||
{
|
{
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader]
|
||||||
private void load(UserProfileOverlay profile, ChannelManager chatManager)
|
private void load(UserProfileOverlay? profile, ChannelManager? chatManager)
|
||||||
{
|
{
|
||||||
Action = () => profile?.ShowUser(sender);
|
Action = () => profile?.ShowUser(sender);
|
||||||
startChatAction = () => chatManager?.OpenPrivateChannel(sender);
|
startChatAction = () => chatManager?.OpenPrivateChannel(sender);
|
||||||
|
Loading…
Reference in New Issue
Block a user