osu/osu.Game.Rulesets.Mania/UI/Components/DefaultColumnBackground.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
3.1 KiB
C#
Raw Normal View History

2020-03-30 14:14:30 +00: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.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
2021-09-16 09:26:12 +00:00
using osu.Framework.Input.Events;
2020-03-30 14:14:30 +00:00
using osu.Game.Rulesets.UI.Scrolling;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.UI.Components
{
public class DefaultColumnBackground : CompositeDrawable, IKeyBindingHandler<ManiaAction>
{
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private Color4 brightColour;
private Color4 dimColour;
private Box background;
private Box backgroundOverlay;
[Resolved]
private Column column { get; set; }
public DefaultColumnBackground()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
InternalChildren = new[]
{
background = new Box
{
Name = "Background",
RelativeSizeAxes = Axes.Both,
},
backgroundOverlay = new Box
{
Name = "Background Gradient Overlay",
RelativeSizeAxes = Axes.Both,
Height = 0.5f,
Blending = BlendingParameters.Additive,
Alpha = 0
}
};
background.Colour = column.AccentColour.Darken(5);
brightColour = column.AccentColour.Opacity(0.6f);
dimColour = column.AccentColour.Opacity(0);
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (direction.NewValue == ScrollingDirection.Up)
{
backgroundOverlay.Anchor = backgroundOverlay.Origin = Anchor.TopLeft;
backgroundOverlay.Colour = ColourInfo.GradientVertical(brightColour, dimColour);
}
else
{
backgroundOverlay.Anchor = backgroundOverlay.Origin = Anchor.BottomLeft;
backgroundOverlay.Colour = ColourInfo.GradientVertical(dimColour, brightColour);
}
}
2021-09-16 09:26:12 +00:00
public bool OnPressed(KeyBindingPressEvent<ManiaAction> e)
2020-03-30 14:14:30 +00:00
{
2021-09-16 09:26:12 +00:00
if (e.Action == column.Action.Value)
2020-03-30 14:14:30 +00:00
backgroundOverlay.FadeTo(1, 50, Easing.OutQuint).Then().FadeTo(0.5f, 250, Easing.OutQuint);
return false;
}
2021-09-16 09:26:12 +00:00
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
2020-03-30 14:14:30 +00:00
{
2021-09-16 09:26:12 +00:00
if (e.Action == column.Action.Value)
2020-03-30 14:14:30 +00:00
backgroundOverlay.FadeTo(0, 250, Easing.OutQuint);
}
}
}