1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

use { get; init; }

This commit is contained in:
cdwcgt 2023-06-13 00:39:25 +09:00
parent 2da8335da2
commit 27b99ea923
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
3 changed files with 29 additions and 42 deletions

View File

@ -90,10 +90,7 @@ namespace osu.Game.Tournament.Tests.Components
}));
AddUntilStep("message from team red is red color", () =>
{
var chatLine = this.ChildrenOfType<ChatLine>().FirstOrDefault(m => m.Message.Sender.OnlineID == redUser.OnlineID);
return chatLine!.UsernameColour == TournamentGame.COLOUR_RED;
});
this.ChildrenOfType<DrawableChatUsername>().Any(s => s.AccentColour == TournamentGame.COLOUR_RED));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
{
@ -108,10 +105,7 @@ namespace osu.Game.Tournament.Tests.Components
}));
AddUntilStep("message from team blue is blue color", () =>
{
var chatLine = this.ChildrenOfType<ChatLine>().FirstOrDefault(m => m.Message.Sender.OnlineID == blueUser.OnlineID);
return chatLine!.UsernameColour == TournamentGame.COLOUR_BLUE;
});
this.ChildrenOfType<DrawableChatUsername>().Any(s => s.AccentColour == TournamentGame.COLOUR_BLUE));
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(nextMessageId())
{

View File

@ -1,7 +1,6 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -21,6 +20,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osuTK.Graphics;
namespace osu.Game.Overlays.Chat
{
@ -68,23 +68,10 @@ namespace osu.Game.Overlays.Chat
private Container? highlight;
private Colour4? usernameColour;
/// <summary>
/// if set, it will override <see cref="APIUser.Colour"/> or <see cref="DrawableChatUsername.default_colours"/>.
/// Must be set when constructor, otherwise throw <see cref="InvalidOperationException"/>.
/// </summary>
public Colour4? UsernameColour
{
get => usernameColour;
set
{
if (drawableUsername != null)
throw new InvalidOperationException("Can't change Username color after DrawableChatUsername created");
usernameColour = value;
}
}
public Color4? UsernameColour { get; init; }
public ChatLine(Message message)
{
@ -100,6 +87,28 @@ namespace osu.Game.Overlays.Chat
configManager.BindWith(OsuSetting.Prefer24HourTime, prefer24HourTime);
prefer24HourTime.BindValueChanged(_ => updateTimestamp());
if (UsernameColour != null)
{
drawableUsername = new DrawableChatUsername(message.Sender)
{
AccentColour = UsernameColour.Value
};
}
else
{
drawableUsername = new DrawableChatUsername(message.Sender);
}
drawableUsername.With(u =>
{
u.Width = UsernameWidth;
u.FontSize = FontSize;
u.AutoSizeAxes = Axes.Y;
u.Origin = Anchor.TopRight;
u.Anchor = Anchor.TopRight;
u.Margin = new MarginPadding { Horizontal = Spacing };
});
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.X,
@ -123,15 +132,7 @@ namespace osu.Game.Overlays.Chat
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
AlwaysPresent = true,
},
drawableUsername = new DrawableChatUsername(message.Sender, usernameColour)
{
Width = UsernameWidth,
FontSize = FontSize,
AutoSizeAxes = Axes.Y,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Margin = new MarginPadding { Horizontal = Spacing },
},
drawableUsername,
drawableContentFlow = new LinkFlowContainer(styleMessageContent)
{
AutoSizeAxes = Axes.Y,

View File

@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Chat
{
public Action? ReportRequested;
public Color4 AccentColour { get; }
public Color4 AccentColour { get; init; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
colouredDrawable.ReceivePositionalInputAt(screenSpacePos);
@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Chat
private readonly Drawable colouredDrawable;
public DrawableChatUsername(APIUser user, Color4? customColor = null)
public DrawableChatUsername(APIUser user)
{
this.user = user;
@ -92,14 +92,6 @@ namespace osu.Game.Overlays.Chat
Origin = Anchor.TopRight,
};
if (customColor != null)
{
AccentColour = customColor.Value;
Add(colouredDrawable = drawableText);
return;
}
if (string.IsNullOrWhiteSpace(user.Colour))
{
AccentColour = default_colours[user.Id % default_colours.Length];