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.Sprites;
|
|
|
|
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 osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-07 03:32:52 +00:00
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
|
2020-03-30 14:14:30 +00:00
|
|
|
{
|
2020-03-31 09:18:53 +00:00
|
|
|
public partial class LegacyColumnBackground : LegacyManiaColumnElement, IKeyBindingHandler<ManiaAction>
|
2020-03-30 14:14:30 +00:00
|
|
|
{
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
2022-11-09 04:37:04 +00:00
|
|
|
private Container lightContainer = null!;
|
|
|
|
private Sprite light = null!;
|
2020-03-30 14:14:30 +00:00
|
|
|
|
2020-08-24 16:21:27 +00:00
|
|
|
public LegacyColumnBackground()
|
2020-03-30 14:14:30 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
|
|
|
|
{
|
2020-06-20 06:53:25 +00:00
|
|
|
string lightImage = skin.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.LightImage)?.Value
|
2020-03-30 14:14:30 +00:00
|
|
|
?? "mania-stage-light";
|
|
|
|
|
2020-06-20 06:56:39 +00:00
|
|
|
float lightPosition = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.LightPosition)?.Value
|
2020-04-01 07:05:52 +00:00
|
|
|
?? 0;
|
|
|
|
|
2020-06-20 06:56:39 +00:00
|
|
|
Color4 lightColour = GetColumnSkinConfig<Color4>(skin, LegacyManiaSkinConfigurationLookups.ColumnLightColour)?.Value
|
2020-04-07 07:53:29 +00:00
|
|
|
?? Color4.White;
|
|
|
|
|
2020-08-24 13:36:37 +00:00
|
|
|
InternalChildren = new[]
|
2020-03-30 14:14:30 +00:00
|
|
|
{
|
|
|
|
lightContainer = new Container
|
|
|
|
{
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-04-01 07:05:52 +00:00
|
|
|
Padding = new MarginPadding { Bottom = lightPosition },
|
2020-03-30 14:14:30 +00:00
|
|
|
Child = light = new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2020-08-25 06:16:41 +00:00
|
|
|
Colour = LegacyColourCompatibility.DisallowZeroAlpha(lightColour),
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
light.FadeIn();
|
|
|
|
light.ScaleTo(Vector2.One);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
|
2020-03-30 14:14:30 +00:00
|
|
|
{
|
|
|
|
// Todo: Should be 400 * 100 / CurrentBPM
|
|
|
|
const double animation_length = 250;
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
if (e.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|