Skip to content

Commit 4e76bd0

Browse files
authored
Play sound when match is available even when queueing in background (#35496)
1 parent 050c10c commit 4e76bd0

File tree

1 file changed

+67
-32
lines changed

1 file changed

+67
-32
lines changed

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

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

44
using osu.Framework.Allocation;
5+
using osu.Framework.Audio;
6+
using osu.Framework.Audio.Sample;
57
using osu.Framework.Bindables;
68
using osu.Framework.Extensions.ObjectExtensions;
79
using osu.Framework.Graphics;
@@ -32,11 +34,7 @@ public partial class QueueController : Component
3234
[Resolved]
3335
private INotificationOverlay? notifications { get; set; }
3436

35-
[Resolved]
36-
private IPerformFromScreenRunner? performer { get; set; }
37-
38-
private ProgressNotification? backgroundNotification;
39-
private Notification? readyNotification;
37+
private BackgroundQueueNotification? backgroundNotification;
4038
private bool isBackgrounded;
4139

4240
protected override void LoadComplete()
@@ -118,41 +116,17 @@ private void postNotification()
118116
if (backgroundNotification != null)
119117
return;
120118

121-
notifications?.Post(backgroundNotification = new ProgressNotification
122-
{
123-
Text = "Searching for opponents...",
124-
CompletionTarget = n => notifications.Post(readyNotification = n),
125-
CompletionText = "Your match is ready! Click to join.",
126-
CompletionClickAction = () =>
127-
{
128-
client.MatchmakingAcceptInvitation().FireAndForget();
129-
performer?.PerformFromScreen(s => s.Push(new IntroScreen()));
130-
131-
closeNotifications();
132-
return true;
133-
},
134-
CancelRequested = () =>
135-
{
136-
client.MatchmakingLeaveQueue().FireAndForget();
137-
138-
closeNotifications();
139-
return true;
140-
}
141-
});
119+
notifications?.Post(backgroundNotification = new BackgroundQueueNotification());
142120
}
143121

144122
private void closeNotifications()
145123
{
146124
if (backgroundNotification != null)
147125
{
148126
backgroundNotification.State = ProgressNotificationState.Cancelled;
149-
backgroundNotification.Close(false);
127+
backgroundNotification.CloseAll();
128+
backgroundNotification = null;
150129
}
151-
152-
readyNotification?.Close(false);
153-
154-
backgroundNotification = null;
155-
readyNotification = null;
156130
}
157131

158132
protected override void Dispose(bool isDisposing)
@@ -168,5 +142,66 @@ protected override void Dispose(bool isDisposing)
168142
client.MatchmakingRoomReady -= onMatchmakingRoomReady;
169143
}
170144
}
145+
146+
private partial class BackgroundQueueNotification : ProgressNotification
147+
{
148+
[Resolved]
149+
private IPerformFromScreenRunner? performer { get; set; }
150+
151+
[Resolved]
152+
private MultiplayerClient client { get; set; } = null!;
153+
154+
private Notification? foundNotification;
155+
private Sample? matchFoundSample;
156+
157+
[BackgroundDependencyLoader]
158+
private void load(AudioManager audio)
159+
{
160+
Text = "Searching for opponents...";
161+
162+
CompletionClickAction = () =>
163+
{
164+
client.MatchmakingAcceptInvitation().FireAndForget();
165+
performer?.PerformFromScreen(s => s.Push(new IntroScreen()));
166+
167+
Close(false);
168+
return true;
169+
};
170+
171+
CancelRequested = () =>
172+
{
173+
client.MatchmakingLeaveQueue().FireAndForget();
174+
return true;
175+
};
176+
177+
matchFoundSample = audio.Samples.Get(@"Multiplayer/Matchmaking/match-found");
178+
}
179+
180+
protected override Notification CreateCompletionNotification()
181+
{
182+
// Playing here means it will play even if notification overlay is hidden.
183+
//
184+
// If we add support for the completion notification to be processed during gameplay,
185+
// this can be moved inside the `MatchFoundNotification` implementation.
186+
matchFoundSample?.Play();
187+
188+
return foundNotification = new MatchFoundNotification
189+
{
190+
Activated = CompletionClickAction,
191+
Text = "Your match is ready! Click to join.",
192+
};
193+
}
194+
195+
public void CloseAll()
196+
{
197+
foundNotification?.Close(false);
198+
Close(false);
199+
}
200+
201+
public partial class MatchFoundNotification : ProgressCompletionNotification
202+
{
203+
// for future use.
204+
}
205+
}
171206
}
172207
}

0 commit comments

Comments
 (0)