1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 12:42:56 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Skinning/Default/DefaultNotePiece.cs

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

88 lines
2.7 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
2022-06-17 15:37:17 +08:00
#nullable disable
2020-03-31 15:00:08 +08:00
using JetBrains.Annotations;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2017-05-04 14:36:37 +08:00
using osu.Framework.Extensions.Color4Extensions;
2017-05-03 14:50:42 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-03-31 14:29:25 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
2020-03-31 14:29:25 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
2020-12-07 11:32:52 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2020-12-07 11:32:52 +08:00
namespace osu.Game.Rulesets.Mania.Skinning.Default
2017-05-03 14:50:42 +08:00
{
2017-05-09 19:55:20 +08:00
/// <summary>
/// Represents the static hit markers of notes.
/// </summary>
2020-03-31 14:29:25 +08:00
internal class DefaultNotePiece : CompositeDrawable
2017-05-03 14:50:42 +08:00
{
2019-09-11 17:16:14 +08:00
public const float NOTE_HEIGHT = 12;
2018-04-13 17:19:50 +08:00
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
2020-03-31 14:29:25 +08:00
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
2017-05-11 12:11:36 +08:00
private readonly Box colouredBox;
2018-04-13 17:19:50 +08:00
2020-03-31 14:29:25 +08:00
public DefaultNotePiece()
2017-05-03 14:50:42 +08:00
{
RelativeSizeAxes = Axes.X;
Height = NOTE_HEIGHT;
2018-04-13 17:19:50 +08:00
2020-03-31 14:29:25 +08:00
CornerRadius = 5;
Masking = true;
InternalChildren = new Drawable[]
2017-05-03 14:50:42 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both
},
colouredBox = new Box
{
RelativeSizeAxes = Axes.X,
2019-09-11 17:16:14 +08:00
Height = NOTE_HEIGHT / 2,
Alpha = 0.1f
2017-05-03 14:50:42 +08:00
}
};
}
2018-04-13 17:19:50 +08:00
2020-03-31 15:00:08 +08:00
[BackgroundDependencyLoader(true)]
private void load([NotNull] IScrollingInfo scrollingInfo, [CanBeNull] DrawableHitObject drawableObject)
{
direction.BindTo(scrollingInfo.Direction);
2020-03-31 14:29:25 +08:00
direction.BindValueChanged(onDirectionChanged, true);
2020-03-31 15:00:08 +08:00
if (drawableObject != null)
{
accentColour.BindTo(drawableObject.AccentColour);
accentColour.BindValueChanged(onAccentChanged, true);
}
2020-03-31 14:29:25 +08:00
}
2019-02-28 12:31:40 +08:00
2020-03-31 14:29:25 +08:00
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
2017-05-03 14:50:42 +08:00
{
2020-03-31 14:29:25 +08:00
colouredBox.Anchor = colouredBox.Origin = direction.NewValue == ScrollingDirection.Up
? Anchor.TopCentre
: Anchor.BottomCentre;
}
2019-02-28 12:31:40 +08:00
2020-03-31 14:29:25 +08:00
private void onAccentChanged(ValueChangedEvent<Color4> accent)
{
colouredBox.Colour = accent.NewValue.Lighten(0.9f);
2018-04-13 17:19:50 +08:00
2020-03-31 14:29:25 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = accent.NewValue.Lighten(1f).Opacity(0.2f),
Radius = 10,
};
2017-05-03 14:50:42 +08:00
}
}
}