1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/DefaultHitExplosion.cs

164 lines
5.9 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2020-07-29 15:14:19 +08:00
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using osu.Game.Rulesets.UI.Scrolling;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mania.UI
{
2020-07-29 14:36:42 +08:00
public class DefaultHitExplosion : CompositeDrawable, IHitExplosion
2018-04-13 17:19:50 +08:00
{
2020-07-29 14:52:25 +08:00
private const float default_large_faint_size = 0.8f;
public override bool RemoveWhenNotAlive => true;
2020-07-29 15:14:19 +08:00
[Resolved]
private Column column { get; set; }
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
2020-07-29 15:14:19 +08:00
private CircularContainer largeFaint;
private CircularContainer mainGlow1;
2018-04-13 17:19:50 +08:00
2020-07-29 15:14:19 +08:00
public DefaultHitExplosion()
2018-04-13 17:19:50 +08:00
{
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.X;
2020-03-31 14:29:25 +08:00
Height = DefaultNotePiece.NOTE_HEIGHT;
2020-07-29 15:14:19 +08:00
}
2018-04-13 17:19:50 +08:00
2020-07-29 15:14:19 +08:00
[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
const float angle_variangle = 15; // should be less than 45
const float roundness = 80;
const float initial_height = 10;
2020-07-29 15:14:19 +08:00
var colour = Interpolation.ValueAt(0.4f, column.AccentColour, Color4.White, 0, 1);
2018-04-13 17:19:50 +08:00
InternalChildren = new Drawable[]
2018-04-13 17:19:50 +08:00
{
largeFaint = new CircularContainer
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
// we want our size to be very small so the glow dominates it.
2020-07-29 14:52:25 +08:00
Size = new Vector2(default_large_faint_size),
Blending = BlendingParameters.Additive,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
2020-07-29 15:14:19 +08:00
Colour = Interpolation.ValueAt(0.1f, column.AccentColour, Color4.White, 0, 1).Opacity(0.3f),
Roundness = 160,
Radius = 200,
},
2018-04-13 17:19:50 +08:00
},
mainGlow1 = new CircularContainer
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
Blending = BlendingParameters.Additive,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
2020-07-29 15:14:19 +08:00
Colour = Interpolation.ValueAt(0.6f, column.AccentColour, Color4.White, 0, 1),
Roundness = 20,
Radius = 50,
},
},
2019-09-12 13:09:21 +08:00
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
Rotation = RNG.NextSingle(-angle_variangle, angle_variangle),
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = colour,
Roundness = roundness,
Radius = 40,
},
},
2019-09-12 13:09:21 +08:00
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
Rotation = RNG.NextSingle(-angle_variangle, angle_variangle),
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = colour,
Roundness = roundness,
Radius = 40,
},
2018-04-13 17:19:50 +08:00
}
};
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (direction.NewValue == ScrollingDirection.Up)
{
Anchor = Anchor.TopCentre;
Y = DefaultNotePiece.NOTE_HEIGHT / 2;
}
else
{
Anchor = Anchor.BottomCentre;
Y = -DefaultNotePiece.NOTE_HEIGHT / 2;
}
}
2020-07-29 14:36:42 +08:00
2020-07-29 15:14:19 +08:00
public void Animate(JudgementResult result)
2020-07-29 14:36:42 +08:00
{
2020-07-29 15:14:19 +08:00
// scale roughly in-line with visual appearance of notes
Vector2 scale = new Vector2(1, 0.6f);
if (result.Judgement is HoldNoteTickJudgement)
scale *= 0.5f;
this.ScaleTo(scale);
2020-07-29 14:36:42 +08:00
largeFaint
2020-07-29 14:52:25 +08:00
.ResizeTo(default_large_faint_size)
.Then()
.ResizeTo(default_large_faint_size * new Vector2(5, 1), PoolableHitExplosion.DURATION, Easing.OutQuint)
2020-07-29 14:36:42 +08:00
.FadeOut(PoolableHitExplosion.DURATION * 2);
2020-07-29 14:52:25 +08:00
mainGlow1
.ScaleTo(1)
.Then()
.ScaleTo(1.4f, PoolableHitExplosion.DURATION, Easing.OutQuint);
2020-07-29 14:36:42 +08:00
2020-07-29 14:52:25 +08:00
this.FadeOutFromOne(PoolableHitExplosion.DURATION, Easing.Out);
2020-07-29 14:36:42 +08:00
}
2018-04-13 17:19:50 +08:00
}
}