1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 10:57:30 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/Components/DefaultHitTarget.cs

81 lines
2.6 KiB
C#
Raw Normal View History

2020-03-31 11:17:44 +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.Effects;
using osu.Framework.Graphics.Shapes;
2020-12-07 11:32:52 +08:00
using osu.Game.Rulesets.Mania.Skinning.Default;
2020-03-31 11:17:44 +08:00
using osu.Game.Rulesets.UI.Scrolling;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.UI.Components
{
public class DefaultHitTarget : CompositeDrawable
{
private const float hit_target_bar_height = 2;
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private Container hitTargetLine;
private Drawable hitTargetBar;
[Resolved]
private Column column { get; set; }
public DefaultHitTarget()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
InternalChildren = new[]
{
hitTargetBar = new Box
{
RelativeSizeAxes = Axes.X,
2020-03-31 14:29:25 +08:00
Height = DefaultNotePiece.NOTE_HEIGHT,
2020-03-31 11:17:44 +08:00
Alpha = 0.6f,
Colour = Color4.Black
},
hitTargetLine = new Container
{
RelativeSizeAxes = Axes.X,
Height = hit_target_bar_height,
Masking = true,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
};
hitTargetLine.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = column.AccentColour.Opacity(0.5f),
};
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (direction.NewValue == ScrollingDirection.Up)
{
hitTargetBar.Anchor = hitTargetBar.Origin = Anchor.TopLeft;
hitTargetLine.Anchor = hitTargetLine.Origin = Anchor.TopLeft;
}
else
{
hitTargetBar.Anchor = hitTargetBar.Origin = Anchor.BottomLeft;
hitTargetLine.Anchor = hitTargetLine.Origin = Anchor.BottomLeft;
}
}
}
}