2020-03-31 10:23:33 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-31 10:23:33 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 17:26:12 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-03-31 10:23:33 +08:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI.Components
|
|
|
|
{
|
|
|
|
public partial class DefaultKeyArea : CompositeDrawable, IKeyBindingHandler<ManiaAction>
|
|
|
|
{
|
|
|
|
private const float key_icon_size = 10;
|
|
|
|
private const float key_icon_corner_radius = 3;
|
|
|
|
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
|
|
|
private Container directionContainer;
|
|
|
|
private Container keyIcon;
|
|
|
|
private Drawable gradient;
|
|
|
|
|
2022-10-05 19:02:02 +08:00
|
|
|
private Bindable<Color4> accentColour;
|
|
|
|
|
2020-03-31 10:23:33 +08:00
|
|
|
[Resolved]
|
|
|
|
private Column column { get; set; }
|
|
|
|
|
|
|
|
public DefaultKeyArea()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(IScrollingInfo scrollingInfo)
|
|
|
|
{
|
2021-12-30 16:37:14 +08:00
|
|
|
InternalChild = directionContainer = new Container
|
2020-03-31 10:23:33 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-04-08 13:08:34 +08:00
|
|
|
Height = Stage.HIT_TARGET_POSITION,
|
2020-03-31 10:23:33 +08:00
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
gradient = new Box
|
|
|
|
{
|
|
|
|
Name = "Key gradient",
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0.5f
|
|
|
|
},
|
|
|
|
keyIcon = new Container
|
|
|
|
{
|
|
|
|
Name = "Key icon",
|
|
|
|
Size = new Vector2(key_icon_size),
|
2020-04-08 13:08:58 +08:00
|
|
|
Origin = Anchor.Centre,
|
2020-03-31 10:23:33 +08:00
|
|
|
Masking = true,
|
|
|
|
CornerRadius = key_icon_corner_radius,
|
|
|
|
BorderThickness = 2,
|
|
|
|
BorderColour = Color4.White, // Not true
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
|
|
|
}
|
2021-12-28 21:35:45 +08:00
|
|
|
},
|
2020-03-31 10:23:33 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
direction.BindValueChanged(onDirectionChanged, true);
|
2022-10-05 19:02:02 +08:00
|
|
|
|
|
|
|
accentColour = column.AccentColour.GetBoundCopy();
|
|
|
|
accentColour.BindValueChanged(colour =>
|
|
|
|
{
|
|
|
|
keyIcon.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
Radius = 5,
|
|
|
|
Colour = colour.NewValue.Opacity(0.5f),
|
|
|
|
};
|
2022-10-07 16:00:10 +08:00
|
|
|
}, true);
|
2020-03-31 10:23:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
|
|
|
{
|
|
|
|
if (direction.NewValue == ScrollingDirection.Up)
|
|
|
|
{
|
2020-04-08 13:08:58 +08:00
|
|
|
keyIcon.Anchor = Anchor.BottomCentre;
|
|
|
|
keyIcon.Y = -20;
|
2020-03-31 10:23:33 +08:00
|
|
|
directionContainer.Anchor = directionContainer.Origin = Anchor.TopLeft;
|
|
|
|
gradient.Colour = ColourInfo.GradientVertical(Color4.Black, Color4.Black.Opacity(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-08 13:08:58 +08:00
|
|
|
keyIcon.Anchor = Anchor.TopCentre;
|
|
|
|
keyIcon.Y = 20;
|
2020-03-31 10:23:33 +08:00
|
|
|
directionContainer.Anchor = directionContainer.Origin = Anchor.BottomLeft;
|
|
|
|
gradient.Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0), Color4.Black);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<ManiaAction> e)
|
2020-03-31 10:23:33 +08:00
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
if (e.Action == column.Action.Value)
|
2020-03-31 10:23:33 +08:00
|
|
|
keyIcon.ScaleTo(1.4f, 50, Easing.OutQuint).Then().ScaleTo(1.3f, 250, Easing.OutQuint);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
|
2020-03-31 10:23:33 +08:00
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
if (e.Action == column.Action.Value)
|
2020-03-31 10:23:33 +08:00
|
|
|
keyIcon.ScaleTo(1f, 125, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|