From b334b78b636a7d4504f3509c88fbf2542d8f4f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 20 Feb 2024 13:44:25 +0100 Subject: [PATCH] Make medal overlay respect overlay disable via activation mode --- .../Visual/Gameplay/TestSceneMedalOverlay.cs | 35 ++++++++++++++++-- osu.Game/Overlays/MedalOverlay.cs | 36 +++++++++++-------- osu.Game/Properties/AssemblyInfo.cs | 3 ++ 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs index a33c7e662f..fe9c524285 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneMedalOverlay.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . 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 overlayActivationMode = new Bindable(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(); + 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", diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 70cde43924..03beba2d3b 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -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 queuedMedals = new Queue(); @@ -36,7 +32,6 @@ namespace osu.Game.Overlays private IAPIProvider api { get; set; } = null!; private Container 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) diff --git a/osu.Game/Properties/AssemblyInfo.cs b/osu.Game/Properties/AssemblyInfo.cs index 1b77e45891..be430a0fe4 100644 --- a/osu.Game/Properties/AssemblyInfo.cs +++ b/osu.Game/Properties/AssemblyInfo.cs @@ -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")]