Skip to content

Commit b334b78

Browse files
committed
Make medal overlay respect overlay disable via activation mode
1 parent e4971ae commit b334b78

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using Moq;
45
using Newtonsoft.Json.Linq;
56
using NUnit.Framework;
7+
using osu.Framework.Bindables;
8+
using osu.Framework.Graphics;
69
using osu.Framework.Graphics.Containers;
710
using osu.Framework.Testing;
811
using osu.Game.Online.API;
@@ -16,14 +19,26 @@ namespace osu.Game.Tests.Visual.Gameplay
1619
[TestFixture]
1720
public partial class TestSceneMedalOverlay : OsuManualInputManagerTestScene
1821
{
19-
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
22+
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
2023

24+
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
2125
private MedalOverlay overlay = null!;
2226

2327
[SetUpSteps]
2428
public void SetUpSteps()
2529
{
26-
AddStep("create overlay", () => Child = overlay = new MedalOverlay());
30+
var overlayManagerMock = new Mock<IOverlayManager>();
31+
overlayManagerMock.Setup(mock => mock.OverlayActivationMode).Returns(overlayActivationMode);
32+
33+
AddStep("create overlay", () => Child = new DependencyProvidingContainer
34+
{
35+
Child = overlay = new MedalOverlay(),
36+
RelativeSizeAxes = Axes.Both,
37+
CachedDependencies =
38+
[
39+
(typeof(IOverlayManager), overlayManagerMock.Object)
40+
]
41+
});
2742
}
2843

2944
[Test]
@@ -63,6 +78,22 @@ public void TestMultipleMedalsInQuickSuccession()
6378
});
6479
}
6580

81+
[Test]
82+
public void TestDelayMedalDisplayUntilActivationModeAllowsIt()
83+
{
84+
AddStep("disable overlay activation", () => overlayActivationMode.Value = OverlayActivation.Disabled);
85+
awardMedal(new UserAchievementUnlock
86+
{
87+
Title = "Time And A Half",
88+
Description = "Having a right ol' time. One and a half of them, almost.",
89+
Slug = @"all-intro-doubletime"
90+
});
91+
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
92+
93+
AddStep("re-enable overlay activation", () => overlayActivationMode.Value = OverlayActivation.All);
94+
AddUntilStep("overlay shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
95+
}
96+
6697
private void awardMedal(UserAchievementUnlock unlock) => AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
6798
{
6899
Event = @"new",

osu.Game/Overlays/MedalOverlay.cs

+21-15
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ public partial class MedalOverlay : OsuFocusedOverlayContainer
2424

2525
protected override void PopIn() => this.FadeIn();
2626

27-
protected override void PopOut()
28-
{
29-
showingMedals = false;
30-
this.FadeOut();
31-
}
27+
protected override void PopOut() => this.FadeOut();
3228

3329
private readonly Queue<MedalAnimation> queuedMedals = new Queue<MedalAnimation>();
3430

3531
[Resolved]
3632
private IAPIProvider api { get; set; } = null!;
3733

3834
private Container<Drawable> medalContainer = null!;
39-
private bool showingMedals;
4035

4136
[BackgroundDependencyLoader]
4237
private void load()
@@ -51,6 +46,17 @@ private void load()
5146
});
5247
}
5348

49+
protected override void LoadComplete()
50+
{
51+
base.LoadComplete();
52+
53+
OverlayActivationMode.BindValueChanged(val =>
54+
{
55+
if (val.NewValue != OverlayActivation.Disabled && queuedMedals.Any())
56+
Show();
57+
}, true);
58+
}
59+
5460
private void handleMedalMessages(SocketMessage obj)
5561
{
5662
if (obj.Event != @"new")
@@ -71,25 +77,25 @@ private void handleMedalMessages(SocketMessage obj)
7177
Description = details.Description,
7278
};
7379

80+
var medalAnimation = new MedalAnimation(medal);
81+
queuedMedals.Enqueue(medalAnimation);
7482
Show();
75-
LoadComponentAsync(new MedalAnimation(medal), animation =>
76-
{
77-
queuedMedals.Enqueue(animation);
78-
showingMedals = true;
79-
});
8083
}
8184

8285
protected override void Update()
8386
{
8487
base.Update();
8588

86-
if (!showingMedals || medalContainer.Any())
89+
if (medalContainer.Any())
8790
return;
8891

89-
if (queuedMedals.TryDequeue(out var nextMedal))
90-
medalContainer.Add(nextMedal);
91-
else
92+
if (!queuedMedals.TryDequeue(out var medal))
93+
{
9294
Hide();
95+
return;
96+
}
97+
98+
LoadComponentAsync(medal, medalContainer.Add);
9399
}
94100

95101
protected override bool OnClick(ClickEvent e)

osu.Game/Properties/AssemblyInfo.cs

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
[assembly: InternalsVisibleTo("osu.Game.Tests.Dynamic")]
1212
[assembly: InternalsVisibleTo("osu.Game.Tests.iOS")]
1313
[assembly: InternalsVisibleTo("osu.Game.Tests.Android")]
14+
15+
// intended for Moq usage
16+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

0 commit comments

Comments
 (0)