1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 12:22:55 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Skinning/Legacy/LegacyKeyArea.cs

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

113 lines
4.2 KiB
C#
Raw Normal View History

2020-03-31 10:23:33 +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.
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.Graphics.Textures;
2020-03-31 10:23:33 +08:00
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
2020-03-31 10:23:33 +08:00
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
using osuTK;
2020-12-07 11:32:52 +08:00
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
2020-03-31 10:23:33 +08:00
{
public partial class LegacyKeyArea : LegacyManiaColumnElement, IKeyBindingHandler<ManiaAction>
2020-03-31 10:23:33 +08:00
{
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private Container directionContainer = null!;
private Sprite upSprite = null!;
private Sprite downSprite = null!;
2020-03-31 10:23:33 +08:00
[Resolved]
private Column column { get; set; } = null!;
2020-03-31 10:23:33 +08:00
public LegacyKeyArea()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
{
string upImage = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.KeyImage)?.Value
?? $"mania-key{FallbackColumnIndex}";
2020-03-31 10:23:33 +08:00
string downImage = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.KeyImageDown)?.Value
?? $"mania-key{FallbackColumnIndex}D";
2020-03-31 10:23:33 +08:00
InternalChild = directionContainer = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
2024-03-06 23:39:18 +08:00
// Key images are placed side-to-side on the playfield, therefore ClampToEdge must be used to prevent any gaps between each key.
2020-03-31 10:23:33 +08:00
upSprite = new Sprite
{
Origin = Anchor.BottomCentre,
2024-03-06 23:39:18 +08:00
Texture = skin.GetTexture(upImage, WrapMode.ClampToEdge, default),
2020-03-31 10:23:33 +08:00
RelativeSizeAxes = Axes.X,
Width = 1
},
downSprite = new Sprite
{
Origin = Anchor.BottomCentre,
2024-03-06 23:39:18 +08:00
Texture = skin.GetTexture(downImage, WrapMode.ClampToEdge, default),
2020-03-31 10:23:33 +08:00
RelativeSizeAxes = Axes.X,
Width = 1,
Alpha = 0
}
}
};
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
if (GetColumnSkinConfig<bool>(skin, LegacyManiaSkinConfigurationLookups.KeysUnderNotes)?.Value ?? false)
Column.UnderlayElements.Add(CreateProxy());
2020-03-31 10:23:33 +08:00
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (direction.NewValue == ScrollingDirection.Up)
{
directionContainer.Anchor = directionContainer.Origin = Anchor.TopCentre;
upSprite.Anchor = downSprite.Anchor = Anchor.TopCentre;
upSprite.Scale = downSprite.Scale = new Vector2(1, -1);
}
else
{
directionContainer.Anchor = directionContainer.Origin = Anchor.BottomCentre;
upSprite.Anchor = downSprite.Anchor = Anchor.BottomCentre;
upSprite.Scale = downSprite.Scale = Vector2.One;
}
}
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<ManiaAction> e)
2020-03-31 10:23:33 +08:00
{
2021-09-16 17:26:12 +08:00
if (e.Action == column.Action.Value)
2020-03-31 10:23:33 +08:00
{
upSprite.FadeTo(0);
downSprite.FadeTo(1);
}
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
2020-03-31 10:23:33 +08:00
{
2021-09-16 17:26:12 +08:00
if (e.Action == column.Action.Value)
2020-03-31 10:23:33 +08:00
{
2021-03-22 15:18:31 +08:00
upSprite.Delay(LegacyHitExplosion.FADE_IN_DURATION).FadeTo(1);
downSprite.Delay(LegacyHitExplosion.FADE_IN_DURATION).FadeTo(0);
2020-03-31 10:23:33 +08:00
}
}
}
}