// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using JetBrains.Annotations; 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.Effects; using osu.Framework.Graphics.Shapes; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI.Scrolling; using osuTK.Graphics; namespace osu.Game.Rulesets.Mania.Skinning.Default { /// /// Represents the static hit markers of notes. /// internal class DefaultNotePiece : CompositeDrawable { public const float NOTE_HEIGHT = 12; private readonly IBindable direction = new Bindable(); private readonly IBindable accentColour = new Bindable(); private readonly Box colouredBox; public DefaultNotePiece() { RelativeSizeAxes = Axes.X; Height = NOTE_HEIGHT; CornerRadius = 5; Masking = true; InternalChildren = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both }, colouredBox = new Box { RelativeSizeAxes = Axes.X, Height = NOTE_HEIGHT / 2, Alpha = 0.1f } }; } [BackgroundDependencyLoader(true)] private void load([NotNull] IScrollingInfo scrollingInfo, [CanBeNull] DrawableHitObject drawableObject) { direction.BindTo(scrollingInfo.Direction); direction.BindValueChanged(onDirectionChanged, true); if (drawableObject != null) { accentColour.BindTo(drawableObject.AccentColour); accentColour.BindValueChanged(onAccentChanged, true); } } private void onDirectionChanged(ValueChangedEvent direction) { colouredBox.Anchor = colouredBox.Origin = direction.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre; } private void onAccentChanged(ValueChangedEvent accent) { colouredBox.Colour = accent.NewValue.Lighten(0.9f); EdgeEffect = new EdgeEffectParameters { Type = EdgeEffectType.Glow, Colour = accent.NewValue.Lighten(1f).Opacity(0.2f), Radius = 10, }; } } }