1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Merge branch 'master' into mass-nrt

This commit is contained in:
Dean Herbert 2023-06-24 09:59:15 +09:00
commit 2bda63c2c8
7 changed files with 140 additions and 66 deletions

View File

@ -21,10 +21,10 @@ namespace osu.Game.Rulesets.Catch.Mods
public void ApplyToDrawableRuleset(DrawableRuleset<CatchHitObject> drawableRuleset)
{
drawableRuleset.Anchor = Anchor.Centre;
drawableRuleset.Origin = Anchor.Centre;
drawableRuleset.PlayfieldAdjustmentContainer.Anchor = Anchor.Centre;
drawableRuleset.PlayfieldAdjustmentContainer.Origin = Anchor.Centre;
drawableRuleset.Scale = new Vector2(1, -1);
drawableRuleset.PlayfieldAdjustmentContainer.Scale = new Vector2(1, -1);
}
}
}

View File

@ -38,10 +38,17 @@ namespace osu.Game.Tests.Visual.Online
private void clear() => AddStep("clear messages", textContainer.Clear);
private void addMessageWithChecks(string text, bool isAction = false, bool isImportant = false, string username = null)
private void addMessageWithChecks(string text, bool isAction = false, bool isImportant = false, string username = null, Colour4? color = null)
{
int index = textContainer.Count + 1;
var newLine = new ChatLine(new DummyMessage(text, isAction, isImportant, index, username));
var newLine = color != null
? new ChatLine(new DummyMessage(text, isAction, isImportant, index, username))
{
UsernameColour = color.Value
}
: new ChatLine(new DummyMessage(text, isAction, isImportant, index, username));
textContainer.Add(newLine);
}
@ -51,6 +58,7 @@ namespace osu.Game.Tests.Visual.Online
addMessageWithChecks($"Wide {a} character username.", username: new string('w', a));
addMessageWithChecks("Short name with spaces.", username: "sho rt name");
addMessageWithChecks("Long name with spaces.", username: "long name with s p a c e s");
addMessageWithChecks("message with custom color", username: "I have custom color", color: Colour4.Green);
}
private class DummyMessage : Message

View File

@ -1,11 +1,15 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat;
using osu.Game.Tests.Visual;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.IPC;
@ -37,6 +41,12 @@ namespace osu.Game.Tournament.Tests.Components
OnlineID = 4,
};
private readonly TournamentUser blueUserWithCustomColour = new TournamentUser
{
Username = "nekodex",
OnlineID = 5,
};
[Cached]
private LadderInfo ladderInfo = new LadderInfo();
@ -61,7 +71,7 @@ namespace osu.Game.Tournament.Tests.Components
},
Team2 =
{
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { blueUser } }
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { blueUser, blueUserWithCustomColour } }
}
};
@ -84,6 +94,9 @@ namespace osu.Game.Tournament.Tests.Components
Content = "I am team red."
}));
AddUntilStep("message from team red is red color", () =>
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_RED));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId())
{
Sender = redUser.ToAPIUser(),
@ -96,6 +109,24 @@ namespace osu.Game.Tournament.Tests.Components
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
}));
AddUntilStep("message from team blue is blue color", () =>
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_BLUE));
var userWithCustomColour = blueUserWithCustomColour.ToAPIUser();
userWithCustomColour.Colour = "#e45678";
AddStep("message from team blue with custom colour", () => testChannel.AddNewMessages(new Message(nextMessageId())
{
Sender = userWithCustomColour,
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
}));
AddUntilStep("message from team blue is blue color", () =>
this.ChildrenOfType<DrawableChatUsername>().Last().AccentColour, () => Is.EqualTo(TournamentGame.COLOUR_BLUE));
AddUntilStep("message from user with custom colour is inverted", () =>
this.ChildrenOfType<DrawableChatUsername>().Last().Inverted, () => Is.EqualTo(true));
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(nextMessageId())
{
Sender = admin,

View File

@ -21,6 +21,9 @@ namespace osu.Game.Tournament.Components
private ChannelManager manager;
[Resolved]
private LadderInfo ladderInfo { get; set; }
public TournamentMatchChatDisplay()
{
RelativeSizeAxes = Axes.X;
@ -71,7 +74,7 @@ namespace osu.Game.Tournament.Components
public void Contract() => this.FadeOut(200);
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message);
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message, ladderInfo);
protected override StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => new MatchChannel(channel);
@ -86,19 +89,13 @@ namespace osu.Game.Tournament.Components
protected partial class MatchMessage : StandAloneMessage
{
public MatchMessage(Message message)
public MatchMessage(Message message, LadderInfo info)
: base(message)
{
}
private void load(LadderInfo info)
{
// if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.Id == Message.Sender.Id))
// SenderText.Colour = TournamentGame.COLOUR_RED;
// else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.Id == Message.Sender.Id))
// SenderText.Colour = TournamentGame.COLOUR_BLUE;
// else if (Message.Sender.Colour != null)
// SenderText.Colour = ColourBox.Colour = Color4Extensions.FromHex(Message.Sender.Colour);
if (info.CurrentMatch.Value.Team1.Value.Players.Any(u => u.OnlineID == Message.Sender.OnlineID))
UsernameColour = TournamentGame.COLOUR_RED;
else if (info.CurrentMatch.Value.Team2.Value.Players.Any(u => u.OnlineID == Message.Sender.OnlineID))
UsernameColour = TournamentGame.COLOUR_BLUE;
}
}
}

View File

@ -18,7 +18,10 @@ using osu.Game.Configuration;
using osu.Game.Graphics;
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;
using Message = osu.Game.Online.Chat.Message;
namespace osu.Game.Overlays.Chat
{
@ -66,12 +69,31 @@ namespace osu.Game.Overlays.Chat
private Container? highlight;
/// <summary>
/// The colour used to paint the author's username.
/// </summary>
/// <remarks>
/// The colour can be set explicitly by consumers via the property initialiser.
/// If unspecified, the colour is by default initialised to:
/// <list type="bullet">
/// <item><see cref="APIUser.Colour">message.Sender.Colour</see>, if non-empty,</item>
/// <item>a random colour from <see cref="default_username_colours"/> if the above is empty.</item>
/// </list>
/// </remarks>
public Color4 UsernameColour { get; init; }
public ChatLine(Message message)
{
Message = message;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
// initialise using sane defaults.
// consumers can use the initialiser of `UsernameColour` to override this if they wish to.
UsernameColour = !string.IsNullOrEmpty(message.Sender.Colour)
? Color4Extensions.FromHex(message.Sender.Colour)
: default_username_colours[message.SenderId % default_username_colours.Length];
}
[BackgroundDependencyLoader]
@ -111,6 +133,8 @@ namespace osu.Game.Overlays.Chat
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Margin = new MarginPadding { Horizontal = Spacing },
AccentColour = UsernameColour,
Inverted = !string.IsNullOrEmpty(message.Sender.Colour),
},
drawableContentFlow = new LinkFlowContainer(styleMessageContent)
{
@ -195,5 +219,44 @@ namespace osu.Game.Overlays.Chat
{
drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm:ss" : @"hh:mm:ss tt");
}
private static readonly Color4[] default_username_colours =
{
Color4Extensions.FromHex("588c7e"),
Color4Extensions.FromHex("b2a367"),
Color4Extensions.FromHex("c98f65"),
Color4Extensions.FromHex("bc5151"),
Color4Extensions.FromHex("5c8bd6"),
Color4Extensions.FromHex("7f6ab7"),
Color4Extensions.FromHex("a368ad"),
Color4Extensions.FromHex("aa6880"),
Color4Extensions.FromHex("6fad9b"),
Color4Extensions.FromHex("f2e394"),
Color4Extensions.FromHex("f2ae72"),
Color4Extensions.FromHex("f98f8a"),
Color4Extensions.FromHex("7daef4"),
Color4Extensions.FromHex("a691f2"),
Color4Extensions.FromHex("c894d3"),
Color4Extensions.FromHex("d895b0"),
Color4Extensions.FromHex("53c4a1"),
Color4Extensions.FromHex("eace5c"),
Color4Extensions.FromHex("ea8c47"),
Color4Extensions.FromHex("fc4f4f"),
Color4Extensions.FromHex("3d94ea"),
Color4Extensions.FromHex("7760ea"),
Color4Extensions.FromHex("af52c6"),
Color4Extensions.FromHex("e25696"),
Color4Extensions.FromHex("677c66"),
Color4Extensions.FromHex("9b8732"),
Color4Extensions.FromHex("8c5129"),
Color4Extensions.FromHex("8c3030"),
Color4Extensions.FromHex("1f5d91"),
Color4Extensions.FromHex("4335a5"),
Color4Extensions.FromHex("812a96"),
Color4Extensions.FromHex("992861"),
};
}
}

View File

@ -33,7 +33,16 @@ namespace osu.Game.Overlays.Chat
{
public Action? ReportRequested;
public Color4 AccentColour { get; }
/// <summary>
/// The primary colour to use for the username.
/// </summary>
public Color4 AccentColour { get; init; }
/// <summary>
/// If set to <see langword="false"/>, the username will be drawn as plain text in <see cref="AccentColour"/>.
/// If set to <see langword="true"/>, the username will be drawn as black text inside a rounded rectangle in <see cref="AccentColour"/>.
/// </summary>
public bool Inverted { get; init; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
colouredDrawable.ReceivePositionalInputAt(screenSpacePos);
@ -75,7 +84,7 @@ namespace osu.Game.Overlays.Chat
private readonly APIUser user;
private readonly OsuSpriteText drawableText;
private readonly Drawable colouredDrawable;
private Drawable colouredDrawable = null!;
public DrawableChatUsername(APIUser user)
{
@ -89,17 +98,17 @@ namespace osu.Game.Overlays.Chat
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
};
}
if (string.IsNullOrWhiteSpace(user.Colour))
[BackgroundDependencyLoader]
private void load()
{
if (!Inverted)
{
AccentColour = default_colours[user.Id % default_colours.Length];
Add(colouredDrawable = drawableText);
}
else
{
AccentColour = Color4Extensions.FromHex(user.Colour);
Add(new Container
{
Anchor = Anchor.TopRight,
@ -141,7 +150,6 @@ namespace osu.Game.Overlays.Chat
protected override void LoadComplete()
{
base.LoadComplete();
drawableText.Colour = colours.ChatBlue;
colouredDrawable.Colour = AccentColour;
}
@ -200,44 +208,5 @@ namespace osu.Game.Overlays.Chat
colouredDrawable.FadeColour(AccentColour, 800, Easing.OutQuint);
}
private static readonly Color4[] default_colours =
{
Color4Extensions.FromHex("588c7e"),
Color4Extensions.FromHex("b2a367"),
Color4Extensions.FromHex("c98f65"),
Color4Extensions.FromHex("bc5151"),
Color4Extensions.FromHex("5c8bd6"),
Color4Extensions.FromHex("7f6ab7"),
Color4Extensions.FromHex("a368ad"),
Color4Extensions.FromHex("aa6880"),
Color4Extensions.FromHex("6fad9b"),
Color4Extensions.FromHex("f2e394"),
Color4Extensions.FromHex("f2ae72"),
Color4Extensions.FromHex("f98f8a"),
Color4Extensions.FromHex("7daef4"),
Color4Extensions.FromHex("a691f2"),
Color4Extensions.FromHex("c894d3"),
Color4Extensions.FromHex("d895b0"),
Color4Extensions.FromHex("53c4a1"),
Color4Extensions.FromHex("eace5c"),
Color4Extensions.FromHex("ea8c47"),
Color4Extensions.FromHex("fc4f4f"),
Color4Extensions.FromHex("3d94ea"),
Color4Extensions.FromHex("7760ea"),
Color4Extensions.FromHex("af52c6"),
Color4Extensions.FromHex("e25696"),
Color4Extensions.FromHex("677c66"),
Color4Extensions.FromHex("9b8732"),
Color4Extensions.FromHex("8c5129"),
Color4Extensions.FromHex("8c3030"),
Color4Extensions.FromHex("1f5d91"),
Color4Extensions.FromHex("4335a5"),
Color4Extensions.FromHex("812a96"),
Color4Extensions.FromHex("992861"),
};
}
}

View File

@ -71,6 +71,12 @@ namespace osu.Game.Rulesets.UI
private readonly AudioContainer audioContainer = new AudioContainer { RelativeSizeAxes = Axes.Both };
/// <summary>
/// A container which encapsulates the <see cref="Playfield"/> and provides any adjustments to
/// ensure correct scale and position.
/// </summary>
public virtual PlayfieldAdjustmentContainer PlayfieldAdjustmentContainer { get; private set; }
public override Container FrameStableComponents { get; } = new Container { RelativeSizeAxes = Axes.Both };
public override IFrameStableClock FrameStableClock => frameStabilityContainer;
@ -178,7 +184,7 @@ namespace osu.Game.Rulesets.UI
audioContainer.WithChild(KeyBindingInputManager
.WithChildren(new Drawable[]
{
CreatePlayfieldAdjustmentContainer()
PlayfieldAdjustmentContainer = CreatePlayfieldAdjustmentContainer()
.WithChild(Playfield),
Overlays
})),