Skip to content

Commit 14c0471

Browse files
authored
Merge pull request #217 from ppy/master
a
2 parents d44d76d + 8691004 commit 14c0471

12 files changed

Lines changed: 153 additions & 40 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,24 @@ public void TestContract()
192192
.All(card => !card.ScreenSpaceDrawQuad.AABBFloat.IntersectsWith(handOfCards.ScreenSpaceDrawQuad.AABBFloat))
193193
);
194194
}
195+
196+
[Test]
197+
public void TestRemoveCardsWhileDragging()
198+
{
199+
AddStep("add cards", () =>
200+
{
201+
for (int i = 0; i < 5; i++)
202+
handOfCards.AddCard(new RankedPlayCardWithPlaylistItem(new RankedPlayCardItem()));
203+
});
204+
AddStep("hover card", () => InputManager.MoveMouseTo(handOfCards.Cards.First()));
205+
AddStep("start drag", () => InputManager.PressButton(MouseButton.Left));
206+
AddStep("move card", () => InputManager.MoveMouseTo(handOfCards.Cards[3]));
207+
AddStep("remove cards", () =>
208+
{
209+
foreach (var card in handOfCards.Cards.ToArray())
210+
handOfCards.RemoveCard(card.Item);
211+
});
212+
AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left));
213+
}
195214
}
196215
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ public override void SetUpSteps()
4040
[Test]
4141
public void TestBasic()
4242
{
43+
double multiplier = 1.0;
44+
45+
AddSliderStep<double>("set multiplier", 1, 5, 2, value => multiplier = value);
4346
AddStep("create", () => Child = new RankedPlayStageOverlay("Pick Phase", RankedPlayColourScheme.BLUE)
4447
{
4548
PickingUser = new APIUser
4649
{
4750
Id = 2,
4851
Username = "peppy",
4952
},
50-
Multiplier = 2,
53+
Multiplier = multiplier,
5154
});
5255
}
5356

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using NUnit.Framework;
88
using osu.Framework.Extensions;
9+
using osu.Framework.Screens;
910
using osu.Framework.Utils;
1011
using osu.Game.Online.API;
1112
using osu.Game.Online.API.Requests.Responses;
@@ -38,6 +39,44 @@ public override void SetUpSteps()
3839
setupRequestHandler();
3940
}
4041

42+
[Test]
43+
[Explicit("Test exercises correct stopping of audio playback. Has no assertions, only useful when checked manually by a human.")]
44+
public void TestAllSamplesStopOnExit()
45+
{
46+
AddStep("set results state", () => MultiplayerClient.RankedPlayChangeStage(RankedPlayStage.Results, state =>
47+
{
48+
int losingPlayer = state.Users.Keys.First();
49+
50+
foreach (var (id, userInfo) in state.Users)
51+
{
52+
if (id == losingPlayer)
53+
{
54+
userInfo.DamageInfo = new RankedPlayDamageInfo
55+
{
56+
RawDamage = 123_456,
57+
Damage = 123_456,
58+
OldLife = 500_000,
59+
NewLife = 500_000 - 123_456,
60+
};
61+
62+
userInfo.Life = 500_000 - 123_456;
63+
}
64+
else
65+
{
66+
userInfo.DamageInfo = new RankedPlayDamageInfo
67+
{
68+
RawDamage = 0,
69+
Damage = 0,
70+
OldLife = 1_000_000,
71+
NewLife = 1_000_000,
72+
};
73+
}
74+
}
75+
}).WaitSafely());
76+
AddWaitStep("wait for samples to start playing", 5);
77+
AddRepeatStep("exit", () => screen.Exit(), 2);
78+
}
79+
4180
[Test]
4281
public void TestBasic()
4382
{

osu.Game/Screens/OnlinePlay/Matchmaking/Queue/RatingDistributionGraph.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using osu.Framework.Graphics.Shapes;
1212
using osu.Framework.Input.Events;
1313
using osu.Framework.Layout;
14+
using osu.Framework.Utils;
1415
using osu.Game.Graphics;
1516
using osu.Game.Graphics.Containers;
1617
using osu.Game.Graphics.Sprites;
@@ -521,7 +522,8 @@ private partial class VerticalLine : Box
521522
protected override void Update()
522523
{
523524
base.Update();
524-
Width = Parent!.DrawWidth / Parent.ScreenSpaceDrawQuad.Width;
525+
if (Precision.DefinitelyBigger(Parent!.ScreenSpaceDrawQuad.Width, 0))
526+
Width = Parent.DrawWidth / Parent.ScreenSpaceDrawQuad.Width;
525527
}
526528
}
527529

@@ -533,7 +535,8 @@ private partial class HorizontalLine : Box
533535
protected override void Update()
534536
{
535537
base.Update();
536-
Height = Parent!.DrawHeight / Parent.ScreenSpaceDrawQuad.Height;
538+
if (Precision.DefinitelyBigger(Parent!.ScreenSpaceDrawQuad.Height, 0))
539+
Height = Parent!.DrawHeight / Parent.ScreenSpaceDrawQuad.Height;
537540
}
538541
}
539542

osu.Game/Screens/OnlinePlay/Matchmaking/Queue/ScreenQueue.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
using System.Linq;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using osu.Framework;
910
using osu.Framework.Allocation;
1011
using osu.Framework.Audio;
1112
using osu.Framework.Audio.Sample;
1213
using osu.Framework.Bindables;
1314
using osu.Framework.Extensions;
1415
using osu.Framework.Extensions.ObjectExtensions;
1516
using osu.Framework.Graphics;
17+
using osu.Framework.Graphics.Audio;
1618
using osu.Framework.Graphics.Containers;
1719
using osu.Framework.Graphics.Shapes;
1820
using osu.Framework.Input.Bindings;
@@ -83,11 +85,11 @@ public partial class ScreenQueue : OsuScreen
8385
private CancellationTokenSource userLookupCancellation = new CancellationTokenSource();
8486

8587
private Sample? enqueueSample;
86-
private Sample? waitingLoopSample;
8788
private Sample? matchFoundSample;
8889

8990
private SampleChannel? waitingLoopChannel;
9091
private ScheduledDelegate? startLoopPlaybackDelegate;
92+
private DrawableSample waitingLoop = null!;
9193

9294
private int? userRating;
9395

@@ -102,14 +104,14 @@ public ScreenQueue(MatchmakingPoolType poolType)
102104
private void load(AudioManager audio, IAPIProvider api)
103105
{
104106
enqueueSample = audio.Samples.Get(@"Multiplayer/Matchmaking/enqueue");
105-
waitingLoopSample = audio.Samples.Get(@"Multiplayer/Matchmaking/waiting-loop");
106107
matchFoundSample = audio.Samples.Get(@"Multiplayer/Matchmaking/match-found");
107108

108109
InternalChild = new InverseScalingDrawSizePreservingFillContainer
109110
{
110111
RelativeSizeAxes = Axes.Both,
111112
Children = new Drawable[]
112113
{
114+
waitingLoop = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/waiting-loop")),
113115
new GlobalScrollAdjustsVolume(),
114116
mainGrid = new GridContainer
115117
{
@@ -123,7 +125,7 @@ private void load(AudioManager audio, IAPIProvider api)
123125
RowDimensions =
124126
[
125127
new Dimension(),
126-
new Dimension(GridSizeMode.Relative, 0.35f)
128+
new Dimension(GridSizeMode.Relative, RuntimeInfo.IsMobile ? 0.55f : 0.35f)
127129
],
128130
Content = new[]
129131
{
@@ -642,12 +644,16 @@ private void startWaitingLoopPlayback()
642644
{
643645
stopWaitingLoopPlayback();
644646

645-
waitingLoopChannel = waitingLoopSample?.GetChannel();
647+
waitingLoopChannel = waitingLoop.GetChannel();
646648
if (waitingLoopChannel == null)
647649
return;
648650

649651
waitingLoopChannel.Looping = true;
650652
waitingLoopChannel?.Play();
653+
654+
waitingLoop.VolumeTo(1)
655+
.Delay(2000)
656+
.VolumeTo(0, 12000);
651657
}
652658

653659
private void stopWaitingLoopPlayback()

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Card/RankedPlayCardContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private void load(CardColours colours)
141141

142142
public MenuItem[] ContextMenuItems =>
143143
[
144-
new OsuMenuItem(ContextMenuStrings.ViewBeatmap, MenuItemType.Highlighted, () => beatmapSetOverlay?.ShowBeatmapSet(Beatmap.BeatmapSet))
144+
new OsuMenuItem(ContextMenuStrings.ViewBeatmap, MenuItemType.Highlighted, () => beatmapSetOverlay?.FetchAndShowBeatmap(Beatmap.OnlineID))
145145
];
146146
}
147147
}

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/Hand/HandOfCards.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public bool RemoveCard(RankedPlayCardWithPlaylistItem item)
138138
if (!cardLookup.Remove(item.Card, out var drawable))
139139
return false;
140140

141+
// child order is only updated once per frame so ordering can change between that and the card getting removed
142+
// which can mess when doing a binary-search for the child during removal
143+
cardContainer.Sort();
141144
cardContainer.Remove(drawable, true);
142145
InvalidateLayout(drawOrder: true);
143146
return true;
@@ -162,6 +165,9 @@ public bool RemoveCard(RankedPlayCardWithPlaylistItem item, [MaybeNullWhen(false
162165
screenSpaceDrawQuad = drawable.ScreenSpaceDrawQuad;
163166
card = drawable.Detach();
164167

168+
// child order is only updated once per frame so ordering can change between that and the card getting removed
169+
// which can mess when doing a binary-search for the child during removal
170+
cardContainer.Sort();
165171
cardContainer.Remove(drawable, true);
166172
InvalidateLayout(drawOrder: true);
167173

@@ -352,13 +358,11 @@ protected override int Compare(Drawable x, Drawable y)
352358
if (x is HandCard c1 && y is HandCard c2)
353359
{
354360
// dragged cards should always be drawn on top
355-
if (c1.CardDragged)
356-
return 1;
357-
358-
if (c2.CardDragged)
359-
return -1;
361+
int result = c1.CardDragged.CompareTo(c2.CardDragged);
362+
if (result != 0)
363+
return result;
360364

361-
int result = c1.Order.CompareTo(c2.Order);
365+
result = c1.Order.CompareTo(c2.Order);
362366
if (result != 0)
363367
return result;
364368
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Components;
3535
using osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay.Intro;
3636
using osu.Game.Screens.OnlinePlay.Multiplayer;
37+
using osu.Game.Users;
3738
using osuTK;
3839

3940
namespace osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay
@@ -43,6 +44,10 @@ public partial class RankedPlayScreen : OsuScreen, IPreviewTrackOwner, IHandlePr
4344
{
4445
protected override bool InitialBackButtonVisibility => false;
4546

47+
public override bool? ApplyModTrackAdjustments => true;
48+
49+
public override bool DisallowExternalBeatmapRulesetChanges => true;
50+
4651
public override bool HideOverlaysOnEnter => true;
4752

4853
public RankedPlaySubScreen? ActiveSubScreen { get; private set; }
@@ -115,6 +120,8 @@ public RankedPlayScreen(MultiplayerRoom room)
115120
{
116121
this.room = room;
117122

123+
Activity.Value = new UserActivity.InLobby(room);
124+
118125
InternalChildren = new Drawable[]
119126
{
120127
matchInfo = new RankedPlayMatchInfo(),
@@ -369,6 +376,7 @@ public override bool OnExiting(ScreenExitEvent e)
369376
return true;
370377
}
371378

379+
ActiveSubScreen?.OnExiting(null);
372380
backgroundMusic.Stop();
373381
previewTrackManager.StopAnyPlaying(this);
374382

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using osu.Framework.Graphics.Containers;
1010
using osu.Framework.Graphics.Shapes;
1111
using osu.Framework.Localisation;
12+
using osu.Game.Extensions;
1213
using osu.Game.Graphics;
1314
using osu.Game.Graphics.Sprites;
1415
using osu.Game.Online.API.Requests.Responses;
@@ -158,7 +159,7 @@ private void load(AudioManager audio)
158159
Origin = Anchor.CentreLeft,
159160
UseFullGlyphHeight = false,
160161
Font = OsuFont.Torus.With(size: 32),
161-
Text = $"{Multiplier:N0}x damage",
162+
Text = $"{Multiplier.Value.ToStandardFormattedString(maxDecimalDigits: 1)}x damage",
162163
});
163164
}
164165

osu.Game/Screens/OnlinePlay/Matchmaking/RankedPlay/ResultsScreen.MainPanel.cs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using osu.Framework.Audio.Sample;
99
using osu.Framework.Bindables;
1010
using osu.Framework.Graphics;
11+
using osu.Framework.Graphics.Audio;
1112
using osu.Framework.Graphics.Containers;
1213
using osu.Framework.Graphics.Shapes;
1314
using osu.Framework.Graphics.Transforms;
@@ -59,17 +60,18 @@ private partial class MainPanel : CompositeDrawable
5960

6061
private RankedPlayDamageInfo losingDamageInfo = null!;
6162

62-
private Sample resultsAppearSample = null!;
63-
private Sample dmgFlySample = null!;
64-
private Sample dmgHitSample = null!;
65-
private Sample hpDownSample = null!;
66-
private Sample playerAppearSample = null!;
67-
private Sample pseudoScoreCounterSample = null!;
68-
private Sample scoreTickSample = null!;
69-
private Sample gradePassSample = null!;
70-
private Sample gradePassSsSample = null!;
71-
private Sample gradeFailSample = null!;
72-
private Sample gradeFailDSample = null!;
63+
private AudioContainer sampleContainer = null!;
64+
private DrawableSample resultsAppearSample = null!;
65+
private DrawableSample dmgFlySample = null!;
66+
private DrawableSample dmgHitSample = null!;
67+
private DrawableSample hpDownSample = null!;
68+
private DrawableSample playerAppearSample = null!;
69+
private DrawableSample pseudoScoreCounterSample = null!;
70+
private DrawableSample scoreTickSample = null!;
71+
private DrawableSample gradePassSample = null!;
72+
private DrawableSample gradePassSsSample = null!;
73+
private DrawableSample gradeFailSample = null!;
74+
private DrawableSample gradeFailDSample = null!;
7375
private SampleChannel? playerScoreTickChannel;
7476
private SampleChannel? opponentScoreTickChannel;
7577
private readonly BindableDouble playerScoreTickPitch = new BindableDouble();
@@ -288,17 +290,23 @@ private void load(AudioManager audio)
288290
}
289291
});
290292

291-
resultsAppearSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/results-appear");
292-
dmgFlySample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/dmg-fly");
293-
dmgHitSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/dmg-hit");
294-
hpDownSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/hp-down");
295-
playerAppearSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/players-appear");
296-
pseudoScoreCounterSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/pseudo-score-counter");
297-
scoreTickSample = audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/score-tick");
298-
gradePassSample = audio.Samples.Get(@"Results/rank-impact-pass");
299-
gradePassSsSample = audio.Samples.Get(@"Results/rank-impact-pass-ss");
300-
gradeFailSample = audio.Samples.Get(@"Results/rank-impact-fail");
301-
gradeFailDSample = audio.Samples.Get(@"Results/rank-impact-fail-d");
293+
AddInternal(sampleContainer = new AudioContainer
294+
{
295+
Children = new Drawable[]
296+
{
297+
resultsAppearSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/results-appear")),
298+
dmgFlySample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/dmg-fly")),
299+
dmgHitSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/dmg-hit")),
300+
hpDownSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/hp-down")),
301+
playerAppearSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/players-appear")),
302+
pseudoScoreCounterSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/pseudo-score-counter")),
303+
scoreTickSample = new DrawableSample(audio.Samples.Get(@"Multiplayer/Matchmaking/Ranked/Results/score-tick")),
304+
gradePassSample = new DrawableSample(audio.Samples.Get(@"Results/rank-impact-pass")),
305+
gradePassSsSample = new DrawableSample(audio.Samples.Get(@"Results/rank-impact-pass-ss")),
306+
gradeFailSample = new DrawableSample(audio.Samples.Get(@"Results/rank-impact-fail")),
307+
gradeFailDSample = new DrawableSample(audio.Samples.Get(@"Results/rank-impact-fail-d")),
308+
}
309+
});
302310
}
303311

304312
protected override void LoadComplete()
@@ -524,7 +532,7 @@ private void playAnimation()
524532
}
525533
}
526534

527-
private Sample getRankSample(ScoreRank rank)
535+
private DrawableSample getRankSample(ScoreRank rank)
528536
{
529537
switch (rank)
530538
{
@@ -555,6 +563,13 @@ private static int numDigits(long value)
555563
return (int)Math.Floor(Math.Log10(value)) + 1;
556564
}
557565

566+
public void StopAllSamples()
567+
{
568+
sampleContainer.Volume.Value = 0;
569+
playerScoreTickChannel?.Stop();
570+
opponentScoreTickChannel?.Stop();
571+
}
572+
558573
private partial class DamageParticle : Triangle
559574
{
560575
private Vector2 velocity = new Vector2(RNG.NextSingle(-0.3f, 0.3f), RNG.NextSingle(-0.3f, 0.3f));

0 commit comments

Comments
 (0)