mirror of
https://github.com/ppy/osu.git
synced 2024-12-21 07:53:38 +08:00
109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Configuration;
|
|
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;
|
|
using OpenTK.Graphics;
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI.Components
|
|
{
|
|
public class ColumnBackground : CompositeDrawable, IKeyBindingHandler<ManiaAction>, IHasAccentColour
|
|
{
|
|
private readonly IBindable<ManiaAction> action = new Bindable<ManiaAction>();
|
|
|
|
private Box background;
|
|
private Box backgroundOverlay;
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(IBindable<ManiaAction> action, IScrollingInfo scrollingInfo)
|
|
{
|
|
this.action.BindTo(action);
|
|
|
|
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
|
|
}
|
|
};
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
direction.BindValueChanged(direction =>
|
|
{
|
|
backgroundOverlay.Anchor = backgroundOverlay.Origin = direction == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
|
|
updateColours();
|
|
}, true);
|
|
}
|
|
|
|
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;
|
|
|
|
background.Colour = AccentColour;
|
|
|
|
var brightPoint = AccentColour.Opacity(0.6f);
|
|
var dimPoint = AccentColour.Opacity(0);
|
|
|
|
backgroundOverlay.Colour = ColourInfo.GradientVertical(
|
|
direction.Value == ScrollingDirection.Up ? brightPoint : dimPoint,
|
|
direction.Value == ScrollingDirection.Up ? dimPoint : brightPoint);
|
|
}
|
|
|
|
public bool OnPressed(ManiaAction action)
|
|
{
|
|
if (action == this.action.Value)
|
|
backgroundOverlay.FadeTo(1, 50, Easing.OutQuint).Then().FadeTo(0.5f, 250, Easing.OutQuint);
|
|
return false;
|
|
}
|
|
|
|
public bool OnReleased(ManiaAction action)
|
|
{
|
|
if (action == this.action.Value)
|
|
backgroundOverlay.FadeTo(0, 250, Easing.OutQuint);
|
|
return false;
|
|
}
|
|
}
|
|
}
|