mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 05:22:54 +08:00
Implement basic medal display flow
This commit is contained in:
parent
4f321e242b
commit
2e5b61302a
@ -1,26 +1,51 @@
|
||||
// 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 Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Notifications.WebSocket;
|
||||
using osu.Game.Online.Notifications.WebSocket.Events;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Users;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class TestSceneMedalOverlay : OsuTestScene
|
||||
public partial class TestSceneMedalOverlay : OsuManualInputManagerTestScene
|
||||
{
|
||||
public TestSceneMedalOverlay()
|
||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||
|
||||
private MedalOverlay overlay = null!;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep(@"display", () =>
|
||||
AddStep("create overlay", () => Child = overlay = new MedalOverlay());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasicAward()
|
||||
{
|
||||
AddStep("award medal", () => dummyAPI.NotificationsClient.Receive(new SocketMessage
|
||||
{
|
||||
LoadComponentAsync(new MedalAnimation(new Medal
|
||||
Event = @"new",
|
||||
Data = JObject.FromObject(new NewPrivateNotificationEvent
|
||||
{
|
||||
Name = @"Animations",
|
||||
InternalName = @"all-intro-doubletime",
|
||||
Description = @"More complex than you think.",
|
||||
}), Add);
|
||||
});
|
||||
Name = @"user_achievement_unlock",
|
||||
Details = JObject.FromObject(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 shown", () => overlay.State.Value, () => Is.EqualTo(Visibility.Visible));
|
||||
AddRepeatStep("dismiss", () => InputManager.Key(Key.Escape), 2);
|
||||
AddUntilStep("overlay hidden", () => overlay.State.Value, () => Is.EqualTo(Visibility.Hidden));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
protected readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
||||
|
||||
protected virtual string PopInSampleName => @"UI/overlay-pop-in";
|
||||
protected virtual string PopOutSampleName => @"UI/overlay-pop-out";
|
||||
protected virtual string? PopInSampleName => @"UI/overlay-pop-in";
|
||||
protected virtual string? PopOutSampleName => @"UI/overlay-pop-out";
|
||||
protected virtual double PopInOutSampleBalance => 0;
|
||||
|
||||
protected override bool BlockNonPositionalInput => true;
|
||||
@ -44,8 +44,11 @@ namespace osu.Game.Graphics.Containers
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager? audio)
|
||||
{
|
||||
samplePopIn = audio?.Samples.Get(PopInSampleName);
|
||||
samplePopOut = audio?.Samples.Get(PopOutSampleName);
|
||||
if (!string.IsNullOrEmpty(PopInSampleName))
|
||||
samplePopIn = audio?.Samples.Get(PopInSampleName);
|
||||
|
||||
if (!string.IsNullOrEmpty(PopOutSampleName))
|
||||
samplePopOut = audio?.Samples.Get(PopOutSampleName);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -18,11 +18,9 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osuTK.Input;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using System;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Utils;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
@ -190,17 +188,6 @@ namespace osu.Game.Overlays
|
||||
particleContainer.Add(new MedalParticle(RNG.Next(0, 359)));
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnFocusLost(FocusLostEvent e)
|
||||
{
|
||||
if (e.CurrentState.Keyboard.Keys.IsPressed(Key.Escape)) dismiss();
|
||||
}
|
||||
|
||||
private const double initial_duration = 400;
|
||||
private const double step_duration = 900;
|
||||
|
||||
@ -256,7 +243,7 @@ namespace osu.Game.Overlays
|
||||
this.FadeOut(200);
|
||||
}
|
||||
|
||||
private void dismiss()
|
||||
public void Dismiss()
|
||||
{
|
||||
if (drawableMedal.State != DisplayState.Full)
|
||||
{
|
||||
|
112
osu.Game/Overlays/MedalOverlay.cs
Normal file
112
osu.Game/Overlays/MedalOverlay.cs
Normal file
@ -0,0 +1,112 @@
|
||||
// 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 System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Notifications.WebSocket;
|
||||
using osu.Game.Online.Notifications.WebSocket.Events;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public partial class MedalOverlay : OsuFocusedOverlayContainer
|
||||
{
|
||||
protected override string? PopInSampleName => null;
|
||||
protected override string? PopOutSampleName => null;
|
||||
|
||||
protected override void PopIn() => this.FadeIn();
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
showingMedals = false;
|
||||
this.FadeOut();
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private Container<Drawable> medalContainer = null!;
|
||||
private bool showingMedals;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
api.NotificationsClient.MessageReceived += handleMedalMessages;
|
||||
|
||||
Add(medalContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
});
|
||||
}
|
||||
|
||||
private void handleMedalMessages(SocketMessage obj)
|
||||
{
|
||||
if (obj.Event != @"new")
|
||||
return;
|
||||
|
||||
var data = obj.Data?.ToObject<NewPrivateNotificationEvent>();
|
||||
if (data == null || data.Name != @"user_achievement_unlock")
|
||||
return;
|
||||
|
||||
var details = data.Details?.ToObject<UserAchievementUnlock>();
|
||||
if (details == null)
|
||||
return;
|
||||
|
||||
var medal = new Medal
|
||||
{
|
||||
Name = details.Title,
|
||||
InternalName = details.Slug,
|
||||
Description = details.Description,
|
||||
};
|
||||
|
||||
Show();
|
||||
LoadComponentAsync(new MedalAnimation(medal), animation =>
|
||||
{
|
||||
medalContainer.Add(animation);
|
||||
showingMedals = true;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (showingMedals && !medalContainer.Any())
|
||||
Hide();
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
(medalContainer.FirstOrDefault(anim => anim.IsAlive) as MedalAnimation)?.Dismiss();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
{
|
||||
if (e.Action == GlobalAction.Back)
|
||||
{
|
||||
(medalContainer.FirstOrDefault(anim => anim.IsAlive) as MedalAnimation)?.Dismiss();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnPressed(e);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (api.IsNotNull())
|
||||
api.NotificationsClient.MessageReceived -= handleMedalMessages;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user