2020-04-01 19:00:52 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-02 13:24:09 +08:00
|
|
|
using System;
|
2020-04-01 19:00:52 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2020-04-02 13:24:09 +08:00
|
|
|
using osu.Framework.Graphics.Animations;
|
2020-07-29 15:14:19 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2020-08-18 23:28:53 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Judgements;
|
2020-07-29 14:36:42 +08:00
|
|
|
using osu.Game.Rulesets.Mania.UI;
|
2020-04-01 19:00:52 +08:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2020-04-02 13:24:09 +08:00
|
|
|
using osu.Game.Skinning;
|
2020-04-02 13:29:16 +08:00
|
|
|
using osuTK;
|
2020-04-01 19:00:52 +08:00
|
|
|
|
2020-12-07 11:32:52 +08:00
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2020-07-29 14:36:42 +08:00
|
|
|
public class LegacyHitExplosion : LegacyManiaColumnElement, IHitExplosion
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2021-03-22 15:18:31 +08:00
|
|
|
public const double FADE_IN_DURATION = 80;
|
|
|
|
|
2020-04-01 19:00:52 +08:00
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
|
|
|
private Drawable explosion;
|
|
|
|
|
2020-04-02 13:24:09 +08:00
|
|
|
public LegacyHitExplosion()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2020-04-01 19:00:52 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-04-02 13:24:09 +08:00
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2020-06-20 14:56:39 +08:00
|
|
|
string imageName = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.ExplosionImage)?.Value
|
2020-04-02 13:24:09 +08:00
|
|
|
?? "lightingN";
|
|
|
|
|
2020-06-20 14:56:39 +08:00
|
|
|
float explosionScale = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.ExplosionScale)?.Value
|
2020-04-02 13:29:16 +08:00
|
|
|
?? 1;
|
|
|
|
|
2020-04-02 21:55:54 +08:00
|
|
|
// Create a temporary animation to retrieve the number of frames, in an effort to calculate the intended frame length.
|
|
|
|
// This animation is discarded and re-queried with the appropriate frame length afterwards.
|
|
|
|
var tmp = skin.GetAnimation(imageName, true, false);
|
|
|
|
double frameLength = 0;
|
2020-04-03 14:59:56 +08:00
|
|
|
if (tmp is IFramedAnimation tmpAnimation && tmpAnimation.FrameCount > 0)
|
2020-04-02 21:55:54 +08:00
|
|
|
frameLength = Math.Max(1000 / 60.0, 170.0 / tmpAnimation.FrameCount);
|
|
|
|
|
2020-04-06 11:39:49 +08:00
|
|
|
explosion = skin.GetAnimation(imageName, true, false, frameLength: frameLength).With(d =>
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2020-04-02 13:24:09 +08:00
|
|
|
if (d == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d.Origin = Anchor.Centre;
|
|
|
|
d.Blending = BlendingParameters.Additive;
|
2020-04-02 13:29:16 +08:00
|
|
|
d.Scale = new Vector2(explosionScale);
|
2020-04-02 13:24:09 +08:00
|
|
|
});
|
2020-04-01 19:00:52 +08:00
|
|
|
|
2020-04-02 14:27:31 +08:00
|
|
|
if (explosion != null)
|
|
|
|
InternalChild = explosion;
|
|
|
|
|
2020-04-01 19:00:52 +08:00
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
direction.BindValueChanged(onDirectionChanged, true);
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:24:09 +08:00
|
|
|
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2020-04-02 13:24:09 +08:00
|
|
|
if (explosion != null)
|
|
|
|
explosion.Anchor = direction.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
|
2020-04-01 19:00:52 +08:00
|
|
|
}
|
|
|
|
|
2020-07-29 15:14:19 +08:00
|
|
|
public void Animate(JudgementResult result)
|
2020-04-01 19:00:52 +08:00
|
|
|
{
|
2020-08-18 23:40:29 +08:00
|
|
|
if (result.Judgement is HoldNoteTickJudgement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(explosion as IFramedAnimation)?.GotoFrame(0);
|
2020-07-29 14:52:25 +08:00
|
|
|
|
2021-03-22 15:19:29 +08:00
|
|
|
explosion?.FadeInFromZero(FADE_IN_DURATION)
|
2020-08-19 20:39:55 +08:00
|
|
|
.Then().FadeOut(120);
|
2020-04-01 19:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|