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 19:49:06 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-06-07 19:49:06 +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;
|
2018-06-07 19:59:04 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-06-07 19:49:06 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-06-07 19:49:06 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI.Components
|
|
|
|
|
{
|
2018-06-07 19:59:04 +08:00
|
|
|
|
public class ColumnBackground : CompositeDrawable, IKeyBindingHandler<ManiaAction>, IHasAccentColour
|
2018-06-07 19:49:06 +08:00
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
private readonly IBindable<ManiaAction> action = new Bindable<ManiaAction>();
|
2018-06-07 19:59:04 +08:00
|
|
|
|
|
2018-06-07 20:19:31 +08:00
|
|
|
|
private Box background;
|
|
|
|
|
private Box backgroundOverlay;
|
|
|
|
|
|
2018-06-08 20:41:20 +08:00
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
2018-06-07 19:49:06 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-07-02 11:31:41 +08:00
|
|
|
|
private void load(IBindable<ManiaAction> action, IScrollingInfo scrollingInfo)
|
2018-06-07 19:49:06 +08:00
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
this.action.BindTo(action);
|
|
|
|
|
|
2018-06-07 19:49:06 +08:00
|
|
|
|
InternalChildren = new[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Background",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.3f
|
|
|
|
|
},
|
|
|
|
|
backgroundOverlay = new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Background Gradient Overlay",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.5f,
|
|
|
|
|
Blending = BlendingMode.Additive,
|
|
|
|
|
Alpha = 0
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-08 20:41:20 +08:00
|
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
2019-02-22 19:13:38 +08:00
|
|
|
|
direction.BindValueChanged(dir =>
|
2018-06-08 20:41:20 +08:00
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
|
backgroundOverlay.Anchor = backgroundOverlay.Origin = dir.NewValue == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
|
2018-06-08 20:41:20 +08:00
|
|
|
|
updateColours();
|
|
|
|
|
}, true);
|
2018-06-07 19:49:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
updateColours();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-06-07 19:49:06 +08:00
|
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
|
|
updateColours();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateColours()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
background.Colour = AccentColour;
|
|
|
|
|
|
|
|
|
|
var brightPoint = AccentColour.Opacity(0.6f);
|
|
|
|
|
var dimPoint = AccentColour.Opacity(0);
|
|
|
|
|
|
|
|
|
|
backgroundOverlay.Colour = ColourInfo.GradientVertical(
|
2018-06-08 20:41:20 +08:00
|
|
|
|
direction.Value == ScrollingDirection.Up ? brightPoint : dimPoint,
|
|
|
|
|
direction.Value == ScrollingDirection.Up ? dimPoint : brightPoint);
|
2018-06-07 19:49:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 19:59:04 +08:00
|
|
|
|
public bool OnPressed(ManiaAction action)
|
2018-06-07 19:49:06 +08:00
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action == this.action.Value)
|
2018-06-07 19:59:04 +08:00
|
|
|
|
backgroundOverlay.FadeTo(1, 50, Easing.OutQuint).Then().FadeTo(0.5f, 250, Easing.OutQuint);
|
|
|
|
|
return false;
|
2018-06-07 19:49:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 19:59:04 +08:00
|
|
|
|
public bool OnReleased(ManiaAction action)
|
|
|
|
|
{
|
2018-07-02 11:31:41 +08:00
|
|
|
|
if (action == this.action.Value)
|
2018-06-07 19:59:04 +08:00
|
|
|
|
backgroundOverlay.FadeTo(0, 250, Easing.OutQuint);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-07 19:49:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|