2022-10-06 15:54:47 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning.Argon
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents length-wise portion of a hold note.
|
|
|
|
/// </summary>
|
|
|
|
public class ArgonHoldBodyPiece : CompositeDrawable
|
|
|
|
{
|
|
|
|
protected readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
|
|
|
|
protected readonly IBindable<bool> IsHitting = new Bindable<bool>();
|
|
|
|
|
|
|
|
private Drawable background = null!;
|
|
|
|
private Box foreground = null!;
|
|
|
|
|
|
|
|
public ArgonHoldBodyPiece()
|
|
|
|
{
|
|
|
|
Blending = BlendingParameters.Additive;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
// Without this, the width of the body will be slightly larger than the head/tail.
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = ArgonNotePiece.CORNER_RADIUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(DrawableHitObject? drawableObject)
|
|
|
|
{
|
|
|
|
InternalChildren = new[]
|
|
|
|
{
|
|
|
|
background = new Box { RelativeSizeAxes = Axes.Both },
|
|
|
|
foreground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (drawableObject != null)
|
|
|
|
{
|
|
|
|
var holdNote = (DrawableHoldNote)drawableObject;
|
|
|
|
|
|
|
|
AccentColour.BindTo(drawableObject.AccentColour);
|
|
|
|
IsHitting.BindTo(holdNote.IsHitting);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccentColour.BindValueChanged(colour =>
|
|
|
|
{
|
2022-10-07 18:31:23 +08:00
|
|
|
background.Colour = colour.NewValue.Darken(1.5f);
|
2022-10-06 15:54:47 +08:00
|
|
|
foreground.Colour = colour.NewValue.Opacity(0.1f);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
IsHitting.BindValueChanged(hitting =>
|
|
|
|
{
|
|
|
|
const float animation_length = 50;
|
|
|
|
|
|
|
|
foreground.ClearTransforms();
|
|
|
|
|
|
|
|
if (hitting.NewValue)
|
|
|
|
{
|
|
|
|
// wait for the next sync point
|
|
|
|
double synchronisedOffset = animation_length * 2 - Time.Current % (animation_length * 2);
|
|
|
|
|
|
|
|
using (foreground.BeginDelayedSequence(synchronisedOffset))
|
|
|
|
{
|
|
|
|
foreground.FadeTo(1, animation_length).Then()
|
|
|
|
.FadeTo(0, animation_length)
|
|
|
|
.Loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreground.FadeOut(animation_length);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|