Skip to content

Commit 8a0a731

Browse files
authored
Merge pull request #151 from ppy/master
aa
2 parents d6f8350 + 8b69aa9 commit 8a0a731

5 files changed

Lines changed: 257 additions & 13 deletions

File tree

osu.Game.Tests/Visual/RankedPlay/TestSceneRankedPlayUserDisplay.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using NUnit.Framework;
55
using osu.Framework.Bindables;
66
using osu.Framework.Graphics;
7+
using osu.Framework.Utils;
8+
using osu.Game.Online.Rooms;
79
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay;
810
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Components;
911
using osu.Game.Tests.Visual.Multiplayer;
@@ -20,11 +22,19 @@ public partial class TestSceneRankedPlayUserDisplay : MultiplayerTestScene
2022
Value = 1_000_000,
2123
};
2224

25+
public TestSceneRankedPlayUserDisplay()
26+
{
27+
AddSliderStep("health", 0, 1_000_000, 1_000_000, value => health.Value = value);
28+
}
29+
2330
public override void SetUpSteps()
2431
{
2532
base.SetUpSteps();
2633

27-
AddStep("add display", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
34+
AddStep("join room", () => JoinRoom(CreateDefaultRoom(MatchType.RankedPlay)));
35+
WaitForJoined();
36+
37+
AddStep("add display", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
2838
{
2939
Anchor = Anchor.Centre,
3040
Origin = Anchor.Centre,
@@ -36,23 +46,38 @@ public override void SetUpSteps()
3646
[Test]
3747
public void TesUserDisplay()
3848
{
39-
AddStep("blue color scheme", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
49+
AddStep("blue color scheme", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Blue)
4050
{
4151
Anchor = Anchor.Centre,
4252
Origin = Anchor.Centre,
4353
Size = new Vector2(256, 72),
4454
Health = { BindTarget = health }
4555
});
4656

47-
AddStep("red color scheme", () => Child = new RankedPlayUserDisplay(2, Anchor.BottomLeft, RankedPlayColourScheme.Red)
57+
AddStep("red color scheme", () => Child = new RankedPlayUserDisplay(1001, Anchor.BottomLeft, RankedPlayColourScheme.Red)
4858
{
4959
Anchor = Anchor.Centre,
5060
Origin = Anchor.Centre,
5161
Size = new Vector2(256, 72),
5262
Health = { BindTarget = health }
5363
});
64+
}
5465

55-
AddSliderStep("health", 0, 1_000_000, 1_000_000, value => health.Value = value);
66+
[Test]
67+
public void TestBeatmapState()
68+
{
69+
float progress = 0;
70+
71+
AddStep("set unavailable", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.NotDownloaded()));
72+
AddStep("set downloading", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress = 0)));
73+
AddUntilStep("increment progress", () =>
74+
{
75+
progress += RNG.NextSingle(0.1f);
76+
MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress));
77+
return progress >= 1;
78+
});
79+
AddStep("set to importing", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.Importing()));
80+
AddStep("set to available", () => MultiplayerClient.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable()));
5681
}
5782
}
5883
}

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Components/RankedPlayUserDisplay.cs

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5+
using System.Linq;
56
using osu.Framework.Allocation;
67
using osu.Framework.Bindables;
78
using osu.Framework.Extensions;
@@ -17,7 +18,10 @@
1718
using osu.Game.Graphics;
1819
using osu.Game.Graphics.Backgrounds;
1920
using osu.Game.Graphics.Sprites;
21+
using osu.Game.Online;
2022
using osu.Game.Online.API.Requests.Responses;
23+
using osu.Game.Online.Multiplayer;
24+
using osu.Game.Online.Rooms;
2125
using osu.Game.Users.Drawables;
2226
using osuTK;
2327
using osuTK.Graphics;
@@ -42,6 +46,13 @@ public partial class RankedPlayUserDisplay : CompositeDrawable
4246

4347
private BufferedContainer grayScaleContainer = null!;
4448

49+
private OsuSpriteText beatmapState = null!;
50+
51+
private BeatmapAvailability availability = BeatmapAvailability.Unknown();
52+
53+
[Resolved]
54+
private MultiplayerClient client { get; set; } = null!;
55+
4556
[Resolved]
4657
private RankedPlayCornerPiece? cornerPiece { get; set; }
4758

@@ -61,6 +72,10 @@ private void load()
6172
? -OsuGame.SHEAR
6273
: OsuGame.SHEAR;
6374

75+
var beatmapStateAnchor = (contentAnchor & Anchor.x0) != 0
76+
? Anchor.CentreLeft
77+
: Anchor.CentreRight;
78+
6479
InternalChildren =
6580
[
6681
new CircularContainer
@@ -103,15 +118,33 @@ private void load()
103118
Anchor = contentAnchor,
104119
Origin = contentAnchor,
105120
},
106-
new OsuSpriteText
121+
new FillFlowContainer
107122
{
108-
Name = "Username",
109-
Text = user.Username,
123+
Name = "Username/beatmap state container",
124+
AutoSizeAxes = Axes.Both,
110125
Anchor = contentAnchor,
111126
Origin = contentAnchor,
127+
Direction = FillDirection.Horizontal,
112128
Padding = new MarginPadding { Horizontal = 4, Vertical = 6 },
113-
Font = OsuFont.GetFont(size: 24, weight: FontWeight.SemiBold),
114-
UseFullGlyphHeight = false,
129+
Spacing = new Vector2(5, 0),
130+
Children =
131+
[
132+
new OsuSpriteText
133+
{
134+
Name = "Username",
135+
Text = user.Username,
136+
Anchor = contentAnchor,
137+
Origin = contentAnchor,
138+
Font = OsuFont.GetFont(size: 24, weight: FontWeight.SemiBold),
139+
UseFullGlyphHeight = false,
140+
},
141+
beatmapState = new OsuSpriteText
142+
{
143+
Anchor = beatmapStateAnchor,
144+
Origin = beatmapStateAnchor,
145+
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
146+
},
147+
],
115148
},
116149
]
117150
}
@@ -129,6 +162,46 @@ protected override void LoadComplete()
129162
grayScaleContainer.GrayscaleTo(e.NewValue <= 0 ? 1 : 0, 300);
130163
cornerPiece?.OnHealthChanged(e.NewValue);
131164
});
165+
166+
client.RoomUpdated += onRoomUpdated;
167+
}
168+
169+
private void onRoomUpdated()
170+
{
171+
var user = client.Room?.Users.SingleOrDefault(u => u.UserID == userId);
172+
173+
if (user == null || availability == user.BeatmapAvailability)
174+
return;
175+
176+
availability = user.BeatmapAvailability;
177+
178+
if (availability.State is DownloadState.NotDownloaded or DownloadState.Downloading or DownloadState.Importing)
179+
beatmapState.FadeIn(50);
180+
else
181+
beatmapState.FadeOut(50);
182+
183+
switch (availability.State)
184+
{
185+
case DownloadState.NotDownloaded:
186+
beatmapState.Text = "Missing Beatmap";
187+
break;
188+
189+
case DownloadState.Downloading:
190+
double progress = Math.Clamp(availability.DownloadProgress ?? 0, 0, 1);
191+
beatmapState.Text = $"Downloading... ({progress:P0})";
192+
break;
193+
194+
case DownloadState.Importing:
195+
beatmapState.Text = "Importing...";
196+
break;
197+
}
198+
}
199+
200+
protected override void Dispose(bool isDisposing)
201+
{
202+
base.Dispose(isDisposing);
203+
204+
client.RoomUpdated -= onRoomUpdated;
132205
}
133206

134207
public partial class HealthBar : CompositeDrawable

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/EndedScreen.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System;
55
using System.Linq;
66
using osu.Framework.Allocation;
7+
using osu.Framework.Audio;
8+
using osu.Framework.Audio.Sample;
79
using osu.Framework.Graphics;
810
using osu.Framework.Graphics.Containers;
911
using osu.Framework.Graphics.Shapes;
@@ -36,8 +38,12 @@ public partial class EndedScreen : RankedPlaySubScreen
3638
private OsuTextFlowContainer localRatingText = null!;
3739
private OsuTextFlowContainer opponentRatingText = null!;
3840

41+
private Sample winSample = null!;
42+
private Sample loseSample = null!;
43+
private Sample drawSample = null!;
44+
3945
[BackgroundDependencyLoader]
40-
private void load(OsuColour colours)
46+
private void load(OsuColour colours, AudioManager audio)
4147
{
4248
CenterColumn.Child = new FillFlowContainer
4349
{
@@ -172,23 +178,30 @@ private void load(OsuColour colours)
172178
}
173179
};
174180

181+
winSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/win");
182+
loseSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/lose");
183+
drawSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/draw");
184+
175185
RankedPlayUserInfo localUser = matchInfo.RoomState.Users[Client.LocalUser!.UserID];
176186
RankedPlayUserInfo otherUser = matchInfo.RoomState.Users.Values.Single(u => u != localUser);
177187

178188
if (matchInfo.RoomState.WinningUserId == null)
179189
{
180190
titleText.Text = "DRAW";
181191
titleText.Colour = titleSeparator.Colour = colours.Orange1;
192+
drawSample.Play();
182193
}
183194
else if (matchInfo.RoomState.WinningUserId == Client.LocalUser!.UserID)
184195
{
185196
titleText.Text = "VICTORY";
186197
titleText.Colour = titleSeparator.Colour = colours.Green1;
198+
winSample.Play();
187199
}
188200
else
189201
{
190202
titleText.Text = "DEFEAT";
191203
titleText.Colour = titleSeparator.Colour = colours.Red1;
204+
loseSample.Play();
192205
}
193206

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

0 commit comments

Comments
 (0)