1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 10:32:56 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Skinning/Argon/ArgonHoldNoteTailPiece.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
4.9 KiB
C#
Raw Normal View History

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;
2023-02-02 09:22:28 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
2022-10-06 15:54:47 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Mania.Objects.Drawables;
2023-02-02 08:50:38 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
2023-02-02 09:22:28 +08:00
using osuTK;
using osuTK.Graphics;
2022-10-06 15:54:47 +08:00
namespace osu.Game.Rulesets.Mania.Skinning.Argon
{
internal partial class ArgonHoldNoteTailPiece : CompositeDrawable
{
[Resolved]
private DrawableHitObject? drawableObject { get; set; }
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
2023-02-02 08:50:38 +08:00
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
private readonly Box foreground;
private readonly ArgonHoldNoteHittingLayer hittingLayer;
private readonly Box foregroundAdditive;
2022-10-06 15:54:47 +08:00
public ArgonHoldNoteTailPiece()
{
RelativeSizeAxes = Axes.X;
2023-02-02 08:50:38 +08:00
Height = ArgonNotePiece.NOTE_HEIGHT;
2023-01-31 16:23:25 +08:00
InternalChildren = new Drawable[]
{
2023-02-02 08:50:38 +08:00
new Container
{
RelativeSizeAxes = Axes.X,
Height = ArgonNotePiece.NOTE_HEIGHT,
CornerRadius = ArgonNotePiece.CORNER_RADIUS,
Masking = true,
2023-01-31 16:23:25 +08:00
Children = new Drawable[]
{
2023-03-10 02:14:08 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0), Colour4.Black),
// Avoid ugly single pixel overlap.
Height = 0.9f,
},
new Container
2023-01-31 16:23:25 +08:00
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Height = ArgonNotePiece.NOTE_ACCENT_RATIO,
CornerRadius = ArgonNotePiece.CORNER_RADIUS,
Masking = true,
Children = new Drawable[]
{
foreground = new Box
{
RelativeSizeAxes = Axes.Both,
},
hittingLayer = new ArgonHoldNoteHittingLayer(),
foregroundAdditive = new Box
{
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
Height = 0.5f,
},
},
},
}
2023-02-02 08:50:38 +08:00
},
};
}
[BackgroundDependencyLoader(true)]
private void load(IScrollingInfo scrollingInfo)
{
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
2023-02-02 08:50:38 +08:00
if (drawableObject != null)
{
accentColour.BindTo(drawableObject.AccentColour);
accentColour.BindValueChanged(onAccentChanged, true);
drawableObject.HitObjectApplied += hitObjectApplied;
2023-02-02 08:50:38 +08:00
}
}
private void hitObjectApplied(DrawableHitObject drawableHitObject)
{
var holdNoteTail = (DrawableHoldNoteTail)drawableHitObject;
hittingLayer.Recycle();
hittingLayer.AccentColour.UnbindBindings();
hittingLayer.AccentColour.BindTo(holdNoteTail.HoldNote.AccentColour);
hittingLayer.IsHitting.UnbindBindings();
((IBindable<bool>)hittingLayer.IsHitting).BindTo(holdNoteTail.HoldNote.IsHitting);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
2023-02-02 09:22:28 +08:00
Scale = new Vector2(1, direction.NewValue == ScrollingDirection.Up ? -1 : 1);
2022-10-06 15:54:47 +08:00
}
2023-02-02 08:50:38 +08:00
private void onAccentChanged(ValueChangedEvent<Color4> accent)
{
foreground.Colour = accent.NewValue.Darken(0.6f); // matches body
foregroundAdditive.Colour = ColourInfo.GradientVertical(
accent.NewValue.Opacity(0.4f),
accent.NewValue.Opacity(0)
);
2023-02-02 08:50:38 +08:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (drawableObject != null)
drawableObject.HitObjectApplied -= hitObjectApplied;
}
2022-10-06 15:54:47 +08:00
}
}