mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 09:42:55 +08:00
Make medal overlay respect overlay disable via activation mode
This commit is contained in:
parent
e4971ae121
commit
b334b78b63
@ -1,8 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.API;
|
||||
@ -16,14 +19,26 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[TestFixture]
|
||||
public partial class TestSceneMedalOverlay : OsuManualInputManagerTestScene
|
||||
{
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
||||
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
private MedalOverlay overlay = null!;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("create overlay", () => Child = overlay = new MedalOverlay());
|
||||
var overlayManagerMock = new Mock<IOverlayManager>();
|
||||
overlayManagerMock.Setup(mock => mock.OverlayActivationMode).Returns(overlayActivationMode);
|
||||
|
||||
AddStep("create overlay", () => Child = new DependencyProvidingContainer
|
||||
{
|
||||
Child = overlay = new MedalOverlay(),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
CachedDependencies =
|
||||
[
|
||||
(typeof(IOverlayManager), overlayManagerMock.Object)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -63,6 +78,22 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDelayMedalDisplayUntilActivationModeAllowsIt()
|
||||
{
|
||||
AddStep("disable overlay activation", () => overlayActivationMode.Value = OverlayActivation.Disabled);
|
||||
awardMedal(new UserAchievementUnlock
|
||||
{
|
||||
Title = "Time And A Half",
|
||||
Description = "Having a right ol' time. One and a half of them, almost.",
|
||||
Slug = @"all-intro-doubletime"
|
||||
});
|
||||
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
|
||||
|
||||
AddStep("re-enable overlay activation", () => overlayActivationMode.Value = OverlayActivation.All);
|
||||
AddUntilStep("overlay shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
|
||||
}
|
||||
|
||||
private void awardMedal(UserAchievementUnlock unlock) => AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
|
||||
{
|
||||
Event = @"new",
|
||||
|
@ -24,11 +24,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override void PopIn() => this.FadeIn();
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
showingMedals = false;
|
||||
this.FadeOut();
|
||||
}
|
||||
protected override void PopOut() => this.FadeOut();
|
||||
|
||||
private readonly Queue<MedalAnimation> queuedMedals = new Queue<MedalAnimation>();
|
||||
|
||||
@ -36,7 +32,6 @@ namespace osu.Game.Overlays
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private Container<Drawable> medalContainer = null!;
|
||||
private bool showingMedals;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -51,6 +46,17 @@ namespace osu.Game.Overlays
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
OverlayActivationMode.BindValueChanged(val =>
|
||||
{
|
||||
if (val.NewValue != OverlayActivation.Disabled && queuedMedals.Any())
|
||||
Show();
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void handleMedalMessages(SocketMessage obj)
|
||||
{
|
||||
if (obj.Event != @"new")
|
||||
@ -71,25 +77,25 @@ namespace osu.Game.Overlays
|
||||
Description = details.Description,
|
||||
};
|
||||
|
||||
var medalAnimation = new MedalAnimation(medal);
|
||||
queuedMedals.Enqueue(medalAnimation);
|
||||
Show();
|
||||
LoadComponentAsync(new MedalAnimation(medal), animation =>
|
||||
{
|
||||
queuedMedals.Enqueue(animation);
|
||||
showingMedals = true;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!showingMedals || medalContainer.Any())
|
||||
if (medalContainer.Any())
|
||||
return;
|
||||
|
||||
if (queuedMedals.TryDequeue(out var nextMedal))
|
||||
medalContainer.Add(nextMedal);
|
||||
else
|
||||
if (!queuedMedals.TryDequeue(out var medal))
|
||||
{
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
LoadComponentAsync(medal, medalContainer.Add);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
|
@ -11,3 +11,6 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: InternalsVisibleTo("osu.Game.Tests.Dynamic")]
|
||||
[assembly: InternalsVisibleTo("osu.Game.Tests.iOS")]
|
||||
[assembly: InternalsVisibleTo("osu.Game.Tests.Android")]
|
||||
|
||||
// intended for Moq usage
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
|
Loading…
Reference in New Issue
Block a user