1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 18:20:34 +08:00
osu-lazer/osu.Game.Rulesets.Catch/UI/HitExplosion.cs

136 lines
4.6 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.
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
2020-12-01 10:32:20 +08:00
using osu.Framework.Graphics.Pooling;
using osu.Framework.Utils;
2020-12-08 14:43:17 +08:00
using osu.Game.Rulesets.Catch.Objects;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.UI
{
2020-12-01 10:32:20 +08:00
public class HitExplosion : PoolableDrawable
{
2020-12-01 10:32:20 +08:00
private Color4 objectColour;
2020-12-08 14:43:17 +08:00
public CatchHitObject HitObject;
2020-12-01 10:32:20 +08:00
public Color4 ObjectColour
{
get => objectColour;
set
{
if (objectColour == value) return;
objectColour = value;
onColourChanged();
}
}
2020-12-01 11:57:37 +08:00
private readonly CircularContainer largeFaint;
private readonly CircularContainer smallFaint;
private readonly CircularContainer directionalGlow1;
private readonly CircularContainer directionalGlow2;
2020-12-01 10:32:20 +08:00
public HitExplosion()
{
Size = new Vector2(20);
Anchor = Anchor.TopCentre;
Origin = Anchor.BottomCentre;
// scale roughly in-line with visual appearance of notes
const float initial_height = 10;
InternalChildren = new Drawable[]
{
largeFaint = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Blending = BlendingParameters.Additive,
},
2020-12-01 10:32:20 +08:00
smallFaint = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Blending = BlendingParameters.Additive,
},
2020-12-01 11:57:37 +08:00
directionalGlow1 = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
},
2020-12-01 11:57:37 +08:00
directionalGlow2 = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
}
};
}
2020-12-01 10:32:20 +08:00
protected override void PrepareForUse()
{
2020-12-01 10:32:20 +08:00
base.PrepareForUse();
const double duration = 400;
2020-12-01 10:32:20 +08:00
// we want our size to be very small so the glow dominates it.
largeFaint.Size = new Vector2(0.8f);
largeFaint
.ResizeTo(largeFaint.Size * new Vector2(5, 1), duration, Easing.OutQuint)
.FadeOut(duration * 2);
2020-12-01 10:32:20 +08:00
const float angle_variangle = 15; // should be less than 45
2020-12-01 11:57:37 +08:00
directionalGlow1.Rotation = RNG.NextSingle(-angle_variangle, angle_variangle);
directionalGlow2.Rotation = RNG.NextSingle(-angle_variangle, angle_variangle);
2020-12-01 10:32:20 +08:00
this.FadeInFromZero(50).Then().FadeOut(duration, Easing.Out);
Expire(true);
}
2020-12-01 10:32:20 +08:00
private void onColourChanged()
{
const float roundness = 100;
largeFaint.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = Interpolation.ValueAt(0.1f, objectColour, Color4.White, 0, 1).Opacity(0.3f),
Roundness = 160,
Radius = 200,
};
smallFaint.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = Interpolation.ValueAt(0.6f, objectColour, Color4.White, 0, 1),
Roundness = 20,
Radius = 50,
};
2020-12-01 13:46:04 +08:00
directionalGlow1.EdgeEffect = directionalGlow2.EdgeEffect = new EdgeEffectParameters
2020-12-01 10:32:20 +08:00
{
Type = EdgeEffectType.Glow,
Colour = Interpolation.ValueAt(0.4f, objectColour, Color4.White, 0, 1),
Roundness = roundness,
Radius = 40,
};
}
}
}