2019-01-24 16:43:03 +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.
|
2018-06-07 20:13:57 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-06-07 20:13:57 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-06-07 20:13:57 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI.Components
|
|
|
|
|
{
|
|
|
|
|
public class ColumnKeyArea : CompositeDrawable, IKeyBindingHandler<ManiaAction>, IHasAccentColour
|
|
|
|
|
{
|
|
|
|
|
private const float key_icon_size = 10;
|
|
|
|
|
private const float key_icon_corner_radius = 3;
|
|
|
|
|
|
2018-07-02 11:31:41 +08:00
|
|
|
|
private readonly IBindable<ManiaAction> action = new Bindable<ManiaAction>();
|
2018-06-08 20:41:20 +08:00
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
|
2018-06-07 20:19:31 +08:00
|
|
|
|
private Container keyIcon;
|
|
|
|
|
|
2018-06-07 20:13:57 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-07-02 11:31:41 +08:00
|
|
|
|
private void load(IBindable<ManiaAction> action, IScrollingInfo scrollingInfo)
|
2018-06-07 20:13:57 +08:00
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
this.action.BindTo(action);
|
|
|
|
|
|
2018-06-08 20:41:20 +08:00
|
|
|
|
Drawable gradient;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new[]
|
2018-06-07 20:13:57 +08:00
|
|
|
|
{
|
2018-06-08 20:41:20 +08:00
|
|
|
|
gradient = new Box
|
2018-06-07 20:13:57 +08:00
|
|
|
|
{
|
|
|
|
|
Name = "Key gradient",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.5f
|
|
|
|
|
},
|
|
|
|
|
keyIcon = new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Key icon",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(key_icon_size),
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-08 20:41:20 +08:00
|
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
2019-02-21 17:56:34 +08:00
|
|
|
|
direction.BindValueChanged(e =>
|
2018-06-08 20:41:20 +08:00
|
|
|
|
{
|
|
|
|
|
gradient.Colour = ColourInfo.GradientVertical(
|
2019-02-21 17:56:34 +08:00
|
|
|
|
direction.Value == ScrollingDirection.Up ? Color4.Black : Color4.Black.Opacity(0),
|
|
|
|
|
direction.Value == ScrollingDirection.Up ? Color4.Black.Opacity(0) : Color4.Black);
|
2018-06-08 20:41:20 +08:00
|
|
|
|
}, true);
|
2018-06-07 20:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
updateColours();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
|
|
updateColours();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateColours()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
keyIcon.EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 5,
|
|
|
|
|
Colour = accentColour.Opacity(0.5f),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(ManiaAction action)
|
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action == this.action.Value)
|
2018-06-07 20:13:57 +08:00
|
|
|
|
keyIcon.ScaleTo(1.4f, 50, Easing.OutQuint).Then().ScaleTo(1.3f, 250, Easing.OutQuint);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(ManiaAction action)
|
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action == this.action.Value)
|
2018-06-07 20:13:57 +08:00
|
|
|
|
keyIcon.ScaleTo(1f, 125, Easing.OutQuint);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|