1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 14:37:30 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/Components/DefaultColumnBackground.cs

100 lines
3.3 KiB
C#
Raw Normal View History

2020-03-30 22:14:30 +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-30 22:14:30 +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.Shapes;
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
2020-03-30 22:14:30 +08:00
using osu.Game.Rulesets.UI.Scrolling;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.UI.Components
{
2022-11-24 13:32:20 +08:00
public partial class DefaultColumnBackground : CompositeDrawable, IKeyBindingHandler<ManiaAction>
2020-03-30 22:14:30 +08:00
{
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; }
2022-10-05 19:02:02 +08:00
private Bindable<Color4> accentColour;
2020-03-30 22:14:30 +08:00
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
}
};
2022-10-05 19:02:02 +08:00
accentColour = column.AccentColour.GetBoundCopy();
accentColour.BindValueChanged(colour =>
{
background.Colour = colour.NewValue.Darken(5);
brightColour = colour.NewValue.Opacity(0.6f);
dimColour = colour.NewValue.Opacity(0);
}, true);
2020-03-30 22:14:30 +08:00
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 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<ManiaAction> e)
2020-03-30 22:14:30 +08:00
{
2021-09-16 17:26:12 +08:00
if (e.Action == column.Action.Value)
2020-03-30 22:14:30 +08:00
backgroundOverlay.FadeTo(1, 50, Easing.OutQuint).Then().FadeTo(0.5f, 250, Easing.OutQuint);
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
2020-03-30 22:14:30 +08:00
{
2021-09-16 17:26:12 +08:00
if (e.Action == column.Action.Value)
2020-03-30 22:14:30 +08:00
backgroundOverlay.FadeTo(0, 250, Easing.OutQuint);
}
}
}