mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 09:42:54 +08:00
Merge c14fe21219
into f09d8f097a
This commit is contained in:
commit
feade4a2b8
@ -245,18 +245,19 @@ namespace osu.Game.Overlays
|
|||||||
this.FadeOut(200);
|
this.FadeOut(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dismiss()
|
public bool Dismiss()
|
||||||
{
|
{
|
||||||
if (drawableMedal != null && drawableMedal.State != DisplayState.Full)
|
if (drawableMedal != null && drawableMedal.State != DisplayState.Full)
|
||||||
{
|
{
|
||||||
// if we haven't yet, play out the animation fully
|
// if we haven't yet, play out the animation fully
|
||||||
drawableMedal.State = DisplayState.Full;
|
drawableMedal.State = DisplayState.Full;
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
Expire();
|
Expire();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class BackgroundStrip : Container
|
private partial class BackgroundStrip : Container
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -35,7 +34,7 @@ namespace osu.Game.Overlays
|
|||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
private Container<Drawable> medalContainer = null!;
|
private Container<Drawable> medalContainer = null!;
|
||||||
private MedalAnimation? lastAnimation;
|
private MedalAnimation? currentMedalDisplay;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
@ -54,11 +53,12 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
OverlayActivationMode.BindValueChanged(val =>
|
OverlayActivationMode.BindValueChanged(_ => showNextMedal(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Hide()
|
||||||
{
|
{
|
||||||
if (val.NewValue == OverlayActivation.All && (queuedMedals.Any() || medalContainer.Any() || lastAnimation?.IsLoaded == false))
|
// don't allow hiding the overlay via any method other than our own.
|
||||||
Show();
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMedalMessages(SocketMessage obj)
|
private void handleMedalMessages(SocketMessage obj)
|
||||||
@ -83,34 +83,18 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
var medalAnimation = new MedalAnimation(medal);
|
var medalAnimation = new MedalAnimation(medal);
|
||||||
|
|
||||||
queuedMedals.Enqueue(medalAnimation);
|
|
||||||
Logger.Log($"Queueing medal unlock for \"{medal.Name}\" ({queuedMedals.Count} to display)");
|
Logger.Log($"Queueing medal unlock for \"{medal.Name}\" ({queuedMedals.Count} to display)");
|
||||||
|
|
||||||
if (OverlayActivationMode.Value == OverlayActivation.All)
|
Schedule(() => LoadComponentAsync(medalAnimation, m =>
|
||||||
Scheduler.AddOnce(Show);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
{
|
||||||
base.Update();
|
queuedMedals.Enqueue(m);
|
||||||
|
showNextMedal();
|
||||||
if (medalContainer.Any() || lastAnimation?.IsLoaded == false)
|
}));
|
||||||
return;
|
|
||||||
|
|
||||||
if (!queuedMedals.TryDequeue(out lastAnimation))
|
|
||||||
{
|
|
||||||
Logger.Log("All queued medals have been displayed!");
|
|
||||||
Hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"Preparing to display \"{lastAnimation.Medal.Name}\"");
|
|
||||||
LoadComponentAsync(lastAnimation, medalContainer.Add);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
lastAnimation?.Dismiss();
|
progressDisplayByUser();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,19 +102,54 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
if (e.Action == GlobalAction.Back)
|
if (e.Action == GlobalAction.Back)
|
||||||
{
|
{
|
||||||
lastAnimation?.Dismiss();
|
progressDisplayByUser();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnPressed(e);
|
return base.OnPressed(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void progressDisplayByUser()
|
||||||
|
{
|
||||||
|
// Dismissing may sometimes play out the medal animation rather than immediately dismissing.
|
||||||
|
if (currentMedalDisplay?.Dismiss() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
currentMedalDisplay = null;
|
||||||
|
showNextMedal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showNextMedal()
|
||||||
|
{
|
||||||
|
// If already displayed, keep displaying medals regardless of activation mode changes.
|
||||||
|
if (OverlayActivationMode.Value != OverlayActivation.All && State.Value == Visibility.Hidden)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// A medal is already displaying.
|
||||||
|
if (currentMedalDisplay != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (queuedMedals.TryDequeue(out currentMedalDisplay))
|
||||||
|
{
|
||||||
|
Logger.Log($"Displaying \"{currentMedalDisplay.Medal.Name}\"");
|
||||||
|
medalContainer.Add(currentMedalDisplay);
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
else if (State.Value == Visibility.Visible)
|
||||||
|
{
|
||||||
|
Logger.Log("All queued medals have been displayed, hiding overlay!");
|
||||||
|
base.Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
// this event subscription fires async loads, which hard-fail if `CompositeDrawable.disposalCancellationSource` is canceled, which happens in the base call.
|
||||||
|
// therefore, unsubscribe from this event early to reduce the chances of a stray event firing at an inconvenient spot.
|
||||||
if (api.IsNotNull())
|
if (api.IsNotNull())
|
||||||
api.NotificationsClient.MessageReceived -= handleMedalMessages;
|
api.NotificationsClient.MessageReceived -= handleMedalMessages;
|
||||||
|
|
||||||
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user