mirror of
https://github.com/ppy/osu.git
synced 2026-06-05 08:03:40 +08:00
Update logo tracking operations to use IDisposable flow
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@@ -28,6 +29,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
private Drawable logoFacade;
|
||||
private bool randomPositions;
|
||||
|
||||
[CanBeNull]
|
||||
private IDisposable logoTracking;
|
||||
|
||||
private const float visual_box_size = 72;
|
||||
|
||||
[SetUpSteps]
|
||||
@@ -150,14 +154,15 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
AddStep("Perform logo movements", () =>
|
||||
{
|
||||
trackingContainer.StopTracking();
|
||||
logoTracking?.Dispose();
|
||||
|
||||
logo.MoveTo(new Vector2(0.5f), 500, Easing.InOutExpo);
|
||||
|
||||
visualBox.Colour = Color4.White;
|
||||
|
||||
Scheduler.AddDelayed(() =>
|
||||
{
|
||||
trackingContainer.StartTracking(logo, 1000, Easing.InOutExpo);
|
||||
logoTracking = trackingContainer.StartTracking(logo, 1000, Easing.InOutExpo);
|
||||
visualBox.Colour = Color4.Tomato;
|
||||
}, 700);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Utils;
|
||||
@@ -32,7 +34,7 @@ namespace osu.Game.Graphics.Containers
|
||||
/// <param name="logo">The instance of the logo to be used for tracking.</param>
|
||||
/// <param name="duration">The duration of the initial transform. Default is instant.</param>
|
||||
/// <param name="easing">The easing type of the initial transform.</param>
|
||||
public void StartTracking(OsuLogo logo, double duration = 0, Easing easing = Easing.None)
|
||||
public IDisposable StartTracking(OsuLogo logo, double duration = 0, Easing easing = Easing.None)
|
||||
{
|
||||
if (Logo != null && Logo != logo)
|
||||
throw new InvalidOperationException("A different logo is already being tracked.");
|
||||
@@ -50,19 +52,21 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
startTime = null;
|
||||
startPosition = null;
|
||||
|
||||
return new InvokeOnDisposal(stopTracking);
|
||||
|
||||
void stopTracking()
|
||||
{
|
||||
Debug.Assert(Logo != null);
|
||||
|
||||
Logo.IsTracking = false;
|
||||
Logo = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the logo assigned in <see cref="StartTracking"/> from tracking the facade's position.
|
||||
/// </summary>
|
||||
public void StopTracking()
|
||||
{
|
||||
if (Logo == null) return;
|
||||
|
||||
Logo.IsTracking = false;
|
||||
Logo = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position that the logo should move to with respect to the <see cref="LogoFacade"/>.
|
||||
/// Manually performs a conversion of the Facade's position to the Logo's parent's relative space.
|
||||
|
||||
@@ -48,7 +48,9 @@ namespace osu.Game.Screens.Footer
|
||||
private FillFlowContainer<ScreenFooterButton> buttonsFlow = null!;
|
||||
private Container footerContentContainer = null!;
|
||||
private Container<ScreenFooterButton> hiddenButtonsContainer = null!;
|
||||
|
||||
private LogoTrackingContainer logoTrackingContainer = null!;
|
||||
private IDisposable? logoTracking;
|
||||
|
||||
// TODO: This has some weird update logic local in this class, but it only works for overlay containers.
|
||||
// This is not what we want. The footer is to be displayed on *screens* with different colour schemes.
|
||||
@@ -145,13 +147,14 @@ namespace osu.Game.Screens.Footer
|
||||
changeLogoDepthDelegate?.Cancel();
|
||||
changeLogoDepthDelegate = null;
|
||||
|
||||
logoTrackingContainer.StartTracking(logo, duration, easing);
|
||||
logoTracking = logoTrackingContainer.StartTracking(logo, duration, easing);
|
||||
RequestLogoInFront?.Invoke(true);
|
||||
}
|
||||
|
||||
public void StopTrackingLogo()
|
||||
{
|
||||
logoTrackingContainer.StopTracking();
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
|
||||
changeLogoDepthDelegate = Scheduler.AddDelayed(() => RequestLogoInFront?.Invoke(false), transition_duration);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ namespace osu.Game.Screens.Menu
|
||||
else
|
||||
{
|
||||
// We should stop tracking as the facade is now out of scope.
|
||||
logoTrackingContainer.StopTracking();
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +391,7 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
|
||||
private ScheduledDelegate? logoDelayedAction;
|
||||
private IDisposable? logoTracking;
|
||||
|
||||
private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Initial)
|
||||
{
|
||||
@@ -402,7 +404,8 @@ namespace osu.Game.Screens.Menu
|
||||
logoDelayedAction?.Cancel();
|
||||
logoDelayedAction = Scheduler.AddDelayed(() =>
|
||||
{
|
||||
logoTrackingContainer.StopTracking();
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
|
||||
game?.Toolbar.Hide();
|
||||
|
||||
@@ -429,7 +432,7 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
logo.ScaleTo(0.5f, 200, Easing.In);
|
||||
|
||||
logoTrackingContainer.StartTracking(logo, 200, Easing.In);
|
||||
logoTracking = logoTrackingContainer.StartTracking(logo, 200, Easing.In);
|
||||
|
||||
logoDelayedAction?.Cancel();
|
||||
logoDelayedAction = Scheduler.AddDelayed(() =>
|
||||
@@ -451,7 +454,7 @@ namespace osu.Game.Screens.Menu
|
||||
break;
|
||||
|
||||
case ButtonSystemState.EnteringMode:
|
||||
logoTrackingContainer.StartTracking(logo, lastState == ButtonSystemState.Initial ? MainMenu.FADE_OUT_DURATION : 0, Easing.InSine);
|
||||
logoTracking = logoTrackingContainer.StartTracking(logo, lastState == ButtonSystemState.Initial ? MainMenu.FADE_OUT_DURATION : 0, Easing.InSine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace osu.Game.Screens.Play
|
||||
private bool playerConsumed;
|
||||
|
||||
private LogoTrackingContainer content = null!;
|
||||
private IDisposable? logoTracking;
|
||||
|
||||
private bool hideOverlays;
|
||||
|
||||
@@ -379,21 +380,26 @@ namespace osu.Game.Screens.Play
|
||||
Scheduler.AddDelayed(() =>
|
||||
{
|
||||
if (this.IsCurrentScreen())
|
||||
content.StartTracking(logo, resuming ? 0 : 500, Easing.InOutExpo);
|
||||
logoTracking = content.StartTracking(logo, resuming ? 0 : 500, Easing.InOutExpo);
|
||||
}, resuming ? 0 : 250);
|
||||
}
|
||||
|
||||
protected override void LogoExiting(OsuLogo logo)
|
||||
{
|
||||
base.LogoExiting(logo);
|
||||
content.StopTracking();
|
||||
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
|
||||
osuLogo = null;
|
||||
}
|
||||
|
||||
protected override void LogoSuspending(OsuLogo logo)
|
||||
{
|
||||
base.LogoSuspending(logo);
|
||||
content.StopTracking();
|
||||
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
|
||||
logo
|
||||
.FadeOut(CONTENT_OUT_DURATION / 2, Easing.OutQuint)
|
||||
@@ -538,7 +544,8 @@ namespace osu.Game.Screens.Play
|
||||
protected virtual void ContentOut()
|
||||
{
|
||||
// Ensure the logo is no longer tracking before we scale the content
|
||||
content.StopTracking();
|
||||
logoTracking?.Dispose();
|
||||
logoTracking = null;
|
||||
|
||||
content.ScaleTo(0.7f, CONTENT_OUT_DURATION * 2, Easing.OutQuint);
|
||||
content.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint)
|
||||
|
||||
Reference in New Issue
Block a user