2020-04-22 10:12:29 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-07-27 18:11:08 +08:00
|
|
|
using System;
|
2020-04-22 10:12:29 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-07 17:12:55 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2021-07-27 17:48:31 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Skinning;
|
|
|
|
using osu.Game.Skinning;
|
2020-04-22 10:12:29 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a component responsible for displaying
|
|
|
|
/// the appropriate catcher trails when requested to.
|
|
|
|
/// </summary>
|
2021-07-27 17:48:31 +08:00
|
|
|
public class CatcherTrailDisplay : SkinReloadableDrawable
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-26 16:50:10 +08:00
|
|
|
/// <summary>
|
2021-07-27 18:11:08 +08:00
|
|
|
/// The most recent time a dash trail was added to this container.
|
2021-07-26 16:50:10 +08:00
|
|
|
/// Only alive (not faded out) trails are considered.
|
2021-07-27 18:11:08 +08:00
|
|
|
/// Returns <see cref="double.NegativeInfinity"/> if no dash trail is alive.
|
2021-07-26 16:50:10 +08:00
|
|
|
/// </summary>
|
2021-07-27 18:11:08 +08:00
|
|
|
public double LastDashTrailTime => getLastDashTrailTime();
|
2020-04-22 10:12:29 +08:00
|
|
|
|
2021-07-27 17:48:31 +08:00
|
|
|
public Color4 HyperDashTrailsColour => hyperDashTrails.Colour;
|
|
|
|
|
|
|
|
public Color4 EndGlowSpritesColour => endGlowSprites.Colour;
|
|
|
|
|
2021-06-14 18:47:18 +08:00
|
|
|
private readonly DrawablePool<CatcherTrail> trailPool;
|
2020-12-07 17:12:55 +08:00
|
|
|
|
2021-06-14 18:47:18 +08:00
|
|
|
private readonly Container<CatcherTrail> dashTrails;
|
|
|
|
private readonly Container<CatcherTrail> hyperDashTrails;
|
|
|
|
private readonly Container<CatcherTrail> endGlowSprites;
|
2020-04-22 10:12:29 +08:00
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
public CatcherTrailDisplay()
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2020-12-07 17:12:55 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-06-14 18:47:18 +08:00
|
|
|
trailPool = new DrawablePool<CatcherTrail>(30),
|
|
|
|
dashTrails = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both },
|
|
|
|
hyperDashTrails = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR },
|
|
|
|
endGlowSprites = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR },
|
2020-04-22 10:12:29 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-27 17:48:31 +08:00
|
|
|
protected override void SkinChanged(ISkinSource skin)
|
|
|
|
{
|
|
|
|
base.SkinChanged(skin);
|
|
|
|
|
|
|
|
hyperDashTrails.Colour = skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ?? Catcher.DEFAULT_HYPER_DASH_COLOUR;
|
|
|
|
endGlowSprites.Colour = skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashAfterImage)?.Value ?? hyperDashTrails.Colour;
|
|
|
|
}
|
|
|
|
|
2020-04-22 10:12:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Displays a single end-glow catcher sprite.
|
|
|
|
/// </summary>
|
2021-07-26 16:46:56 +08:00
|
|
|
public void DisplayEndGlow(CatcherAnimationState animationState, float x, Vector2 scale)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-26 16:46:56 +08:00
|
|
|
var endGlow = createTrail(animationState, x, scale);
|
|
|
|
|
|
|
|
endGlowSprites.Add(endGlow);
|
2020-04-22 10:12:29 +08:00
|
|
|
|
|
|
|
endGlow.MoveToOffset(new Vector2(0, -10), 1200, Easing.In);
|
|
|
|
endGlow.ScaleTo(endGlow.Scale * 0.95f).ScaleTo(endGlow.Scale * 1.2f, 1200, Easing.In);
|
|
|
|
endGlow.FadeOut(1200);
|
|
|
|
endGlow.Expire(true);
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
public void DisplayDashTrail(CatcherAnimationState animationState, float x, Vector2 scale, bool hyperDashing)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-26 16:46:56 +08:00
|
|
|
var sprite = createTrail(animationState, x, scale);
|
2020-04-22 10:12:29 +08:00
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
if (hyperDashing)
|
|
|
|
hyperDashTrails.Add(sprite);
|
|
|
|
else
|
|
|
|
dashTrails.Add(sprite);
|
2020-04-22 10:12:29 +08:00
|
|
|
|
|
|
|
sprite.FadeTo(0.4f).FadeOut(800, Easing.OutQuint);
|
|
|
|
sprite.Expire(true);
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
private CatcherTrail createTrail(CatcherAnimationState animationState, float x, Vector2 scale)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-06-14 18:47:18 +08:00
|
|
|
CatcherTrail sprite = trailPool.Get();
|
2020-12-07 17:12:55 +08:00
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
sprite.AnimationState = animationState;
|
|
|
|
sprite.Scale = scale;
|
|
|
|
sprite.Position = new Vector2(x, 0);
|
2020-04-22 10:12:29 +08:00
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
2021-07-27 18:11:08 +08:00
|
|
|
|
|
|
|
private double getLastDashTrailTime()
|
|
|
|
{
|
|
|
|
double maxTime = double.NegativeInfinity;
|
|
|
|
|
|
|
|
foreach (var trail in dashTrails)
|
|
|
|
maxTime = Math.Max(maxTime, trail.LifetimeStart);
|
|
|
|
|
|
|
|
foreach (var trail in hyperDashTrails)
|
|
|
|
maxTime = Math.Max(maxTime, trail.LifetimeStart);
|
|
|
|
|
|
|
|
return maxTime;
|
|
|
|
}
|
2020-04-22 10:12:29 +08:00
|
|
|
}
|
|
|
|
}
|