Skip to content
Merged

aa #151

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions osu.Game.Tests/Visual/RankedPlay/TestSceneRankedPlayUserDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay;
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Components;
using osu.Game.Tests.Visual.Multiplayer;
Expand All @@ -20,11 +22,19 @@ public partial class TestSceneRankedPlayUserDisplay : MultiplayerTestScene
Value = 1_000_000,
};

public TestSceneRankedPlayUserDisplay()
{
AddSliderStep("health", 0, 1_000_000, 1_000_000, value => health.Value = value);
}

public override void SetUpSteps()
{
base.SetUpSteps();

AddStep("add display", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
AddStep("join room", () => JoinRoom(CreateDefaultRoom(MatchType.RankedPlay)));
WaitForJoined();

AddStep("add display", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand All @@ -36,23 +46,38 @@ public override void SetUpSteps()
[Test]
public void TesUserDisplay()
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test method name has a typo (TesUserDisplay). Rename to TestUserDisplay for consistency with other tests and to improve discoverability in test runners and logs.

Suggested change
public void TesUserDisplay()
public void TestUserDisplay()

Copilot uses AI. Check for mistakes.
{
AddStep("blue color scheme", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
AddStep("blue color scheme", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(256, 72),
Health = { BindTarget = health }
});

AddStep("red color scheme", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Red)
AddStep("red color scheme", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Red)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(256, 72),
Health = { BindTarget = health }
});
}

AddSliderStep("health", 0, 1_000_000, 1_000_000, value => health.Value = value);
[Test]
public void TestBeatmapState()
{
float progress = 0;

AddStep("set unavailable", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.NotDownloaded()));
AddStep("set downloading", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress = 0)));
AddUntilStep("increment progress", () =>
{
progress += RNG.NextSingle(0.1f);
MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress));
return progress >= 1;
});
AddStep("set to importing", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Importing()));
AddStep("set to available", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
Expand All @@ -17,7 +18,10 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Users.Drawables;
using osuTK;
using osuTK.Graphics;
Expand All @@ -42,6 +46,13 @@ public partial class RankedPlayUserDisplay : CompositeDrawable

private BufferedContainer grayScaleContainer = null!;

private OsuSpriteText beatmapState = null!;

private BeatmapAvailability availability = BeatmapAvailability.Unknown();

[Resolved]
private MultiplayerClient client { get; set; } = null!;

[Resolved]
private RankedPlayCornerPiece? cornerPiece { get; set; }

Expand All @@ -61,6 +72,10 @@ private void load()
? -OsuGame.SHEAR
: OsuGame.SHEAR;

var beatmapStateAnchor = (contentAnchor & Anchor.x0) != 0
? Anchor.CentreLeft
: Anchor.CentreRight;

InternalChildren =
[
new CircularContainer
Expand Down Expand Up @@ -103,15 +118,33 @@ private void load()
Anchor = contentAnchor,
Origin = contentAnchor,
},
new OsuSpriteText
new FillFlowContainer
{
Name = "Username",
Text = user.Username,
Name = "Username/beatmap state container",
AutoSizeAxes = Axes.Both,
Anchor = contentAnchor,
Origin = contentAnchor,
Direction = FillDirection.Horizontal,
Padding = new MarginPadding { Horizontal = 4, Vertical = 6 },
Font = OsuFont.GetFont(size: 24, weight: FontWeight.SemiBold),
UseFullGlyphHeight = false,
Spacing = new Vector2(5, 0),
Children =
[
new OsuSpriteText
{
Name = "Username",
Text = user.Username,
Anchor = contentAnchor,
Origin = contentAnchor,
Font = OsuFont.GetFont(size: 24, weight: FontWeight.SemiBold),
UseFullGlyphHeight = false,
},
beatmapState = new OsuSpriteText
{
Anchor = beatmapStateAnchor,
Origin = beatmapStateAnchor,
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
},
],
},
]
}
Expand All @@ -129,6 +162,46 @@ protected override void LoadComplete()
grayScaleContainer.GrayscaleTo(e.NewValue <= 0 ? 1 : 0, 300);
cornerPiece?.OnHealthChanged(e.NewValue);
});

client.RoomUpdated += onRoomUpdated;
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beatmap availability text won’t update until the next RoomUpdated event fires. If the room already has a non-default availability when this drawable appears, beatmapState will show the wrong initial state. Call onRoomUpdated() once after subscribing (or immediately before subscribing) so the UI reflects the current room state on first display.

Suggested change
client.RoomUpdated += onRoomUpdated;
client.RoomUpdated += onRoomUpdated;
onRoomUpdated();

Copilot uses AI. Check for mistakes.
}

private void onRoomUpdated()
{
var user = client.Room?.Users.SingleOrDefault(u => u.UserID == userId);

if (user == null || availability == user.BeatmapAvailability)
return;

availability = user.BeatmapAvailability;

if (availability.State is DownloadState.NotDownloaded or DownloadState.Downloading or DownloadState.Importing)
beatmapState.FadeIn(50);
else
beatmapState.FadeOut(50);

switch (availability.State)
{
case DownloadState.NotDownloaded:
beatmapState.Text = "Missing Beatmap";
break;

case DownloadState.Downloading:
double progress = Math.Clamp(availability.DownloadProgress ?? 0, 0, 1);
beatmapState.Text = $"Downloading... ({progress:P0})";
break;

case DownloadState.Importing:
beatmapState.Text = "Importing...";
break;
}
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

client.RoomUpdated -= onRoomUpdated;
}

public partial class HealthBar : CompositeDrawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand Down Expand Up @@ -36,8 +38,12 @@ public partial class EndedScreen : RankedPlaySubScreen
private OsuTextFlowContainer localRatingText = null!;
private OsuTextFlowContainer opponentRatingText = null!;

private Sample winSample = null!;
private Sample loseSample = null!;
private Sample drawSample = null!;

[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, AudioManager audio)
{
CenterColumn.Child = new FillFlowContainer
{
Expand Down Expand Up @@ -172,23 +178,30 @@ private void load(OsuColour colours)
}
};

winSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/win");
loseSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/lose");
drawSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/draw");

RankedPlayUserInfo localUser = matchInfo.RoomState.Users[Client.LocalUser!.UserID];
RankedPlayUserInfo otherUser = matchInfo.RoomState.Users.Values.Single(u => u != localUser);

if (matchInfo.RoomState.WinningUserId == null)
{
titleText.Text = "DRAW";
titleText.Colour = titleSeparator.Colour = colours.Orange1;
drawSample.Play();
}
else if (matchInfo.RoomState.WinningUserId == Client.LocalUser!.UserID)
{
titleText.Text = "VICTORY";
titleText.Colour = titleSeparator.Colour = colours.Green1;
winSample.Play();
}
else
{
titleText.Text = "DEFEAT";
titleText.Colour = titleSeparator.Colour = colours.Red1;
loseSample.Play();
}

localRatingText.AddText("Your Rating: ", s => s.Font = OsuFont.Style.Heading1.With(weight: FontWeight.Regular));
Expand Down
Loading
Loading