osu/osu.Game.Rulesets.Mania/Skinning/LegacyColumnBackground.cs

140 lines
5.4 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.Skinning
{
public class LegacyColumnBackground : LegacyManiaColumnElement, IKeyBindingHandler<ManiaAction>
2020-03-30 14:14:30 +00:00
{
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private readonly bool isLastColumn;
2020-03-30 14:14:30 +00:00
private Container lightContainer;
private Sprite light;
public LegacyColumnBackground(bool isLastColumn)
2020-03-30 14:14:30 +00:00
{
this.isLastColumn = isLastColumn;
2020-03-30 14:14:30 +00:00
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
{
string lightImage = skin.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.LightImage)?.Value
2020-03-30 14:14:30 +00:00
?? "mania-stage-light";
float leftLineWidth = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.LeftLineWidth)
2020-03-31 11:12:02 +00:00
?.Value ?? 1;
float rightLineWidth = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.RightLineWidth)
2020-03-31 11:12:02 +00:00
?.Value ?? 1;
2020-03-30 14:14:30 +00:00
bool hasLeftLine = leftLineWidth > 0;
bool hasRightLine = rightLineWidth > 0 && skin.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version)?.Value >= 2.4m
|| isLastColumn;
2020-03-30 14:14:30 +00:00
float lightPosition = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.LightPosition)?.Value
?? 0;
Color4 lineColour = GetColumnSkinConfig<Color4>(skin, LegacyManiaSkinConfigurationLookups.ColumnLineColour)?.Value
?? Color4.White;
Color4 backgroundColour = GetColumnSkinConfig<Color4>(skin, LegacyManiaSkinConfigurationLookups.ColumnBackgroundColour)?.Value
?? Color4.Black;
Color4 lightColour = GetColumnSkinConfig<Color4>(skin, LegacyManiaSkinConfigurationLookups.ColumnLightColour)?.Value
?? Color4.White;
2020-03-30 14:14:30 +00:00
InternalChildren = new Drawable[]
{
new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(backgroundColour),
new Container
2020-03-30 14:14:30 +00:00
{
RelativeSizeAxes = Axes.Y,
Width = leftLineWidth,
2020-04-21 08:14:49 +00:00
Scale = new Vector2(0.740f, 1),
Alpha = hasLeftLine ? 1 : 0,
Child = new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(lineColour)
2020-03-30 14:14:30 +00:00
},
new Container
2020-03-30 14:14:30 +00:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = rightLineWidth,
2020-04-21 08:14:49 +00:00
Scale = new Vector2(0.740f, 1),
Alpha = hasRightLine ? 1 : 0,
Child = new Box { RelativeSizeAxes = Axes.Both }.WithLegacyColour(lineColour)
2020-03-30 14:14:30 +00:00
},
lightContainer = new Container
{
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = lightPosition },
2020-03-30 14:14:30 +00:00
Child = light = new Sprite
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Colour = lightColour.ToLegacyColour(),
2020-03-30 14:14:30 +00:00
Texture = skin.GetTexture(lightImage),
RelativeSizeAxes = Axes.X,
Width = 1,
Alpha = 0
}
}
};
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (direction.NewValue == ScrollingDirection.Up)
{
lightContainer.Anchor = Anchor.TopCentre;
lightContainer.Scale = new Vector2(1, -1);
}
else
{
lightContainer.Anchor = Anchor.BottomCentre;
lightContainer.Scale = Vector2.One;
}
}
public bool OnPressed(ManiaAction action)
{
if (action == Column.Action.Value)
2020-03-30 14:14:30 +00:00
{
light.FadeIn();
light.ScaleTo(Vector2.One);
}
return false;
}
public void OnReleased(ManiaAction action)
{
// Todo: Should be 400 * 100 / CurrentBPM
const double animation_length = 250;
if (action == Column.Action.Value)
2020-03-30 14:14:30 +00:00
{
light.FadeTo(0, animation_length);
light.ScaleTo(new Vector2(1, 0), animation_length);
}
}
}
}