2020-03-31 14:29:25 +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;
|
2021-09-14 16:45:23 +08:00
|
|
|
using osu.Framework.Graphics.Animations;
|
2020-03-31 14:29:25 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
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 14:29:25 +08:00
|
|
|
{
|
|
|
|
public partial class LegacyNotePiece : LegacyManiaColumnElement
|
|
|
|
{
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
private Container directionContainer = null!;
|
2021-09-15 12:26:39 +08:00
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
private Drawable noteAnimation = null!;
|
2020-03-31 14:29:25 +08:00
|
|
|
|
2020-04-07 15:07:18 +08:00
|
|
|
private float? minimumColumnWidth;
|
|
|
|
|
2020-03-31 14:29:25 +08:00
|
|
|
public LegacyNotePiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
|
|
|
|
{
|
2020-04-07 15:07:18 +08:00
|
|
|
minimumColumnWidth = skin.GetConfig<ManiaSkinConfigurationLookup, float>(new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.MinimumColumnWidth))?.Value;
|
|
|
|
|
2020-03-31 14:29:25 +08:00
|
|
|
InternalChild = directionContainer = new Container
|
|
|
|
{
|
2020-03-31 14:59:52 +08:00
|
|
|
Origin = Anchor.BottomCentre,
|
2020-03-31 14:29:25 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-09-15 12:26:39 +08:00
|
|
|
Child = noteAnimation = GetAnimation(skin) ?? Empty()
|
2020-03-31 14:29:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
direction.BindValueChanged(OnDirectionChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
Texture? texture = null;
|
2021-09-14 16:45:23 +08:00
|
|
|
|
|
|
|
if (noteAnimation is Sprite sprite)
|
|
|
|
texture = sprite.Texture;
|
2021-09-14 16:47:12 +08:00
|
|
|
else if (noteAnimation is TextureAnimation textureAnimation && textureAnimation.FrameCount > 0)
|
2021-09-14 16:45:23 +08:00
|
|
|
texture = textureAnimation.CurrentFrame;
|
|
|
|
|
|
|
|
if (texture != null)
|
2020-03-31 14:29:25 +08:00
|
|
|
{
|
2020-04-07 15:07:18 +08:00
|
|
|
// The height is scaled to the minimum column width, if provided.
|
|
|
|
float minimumWidth = minimumColumnWidth ?? DrawWidth;
|
2021-09-14 16:45:23 +08:00
|
|
|
noteAnimation.Scale = Vector2.Divide(new Vector2(DrawWidth, minimumWidth), texture.DisplayWidth);
|
2020-03-31 14:29:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
|
|
|
{
|
|
|
|
if (direction.NewValue == ScrollingDirection.Up)
|
|
|
|
{
|
2020-03-31 14:59:52 +08:00
|
|
|
directionContainer.Anchor = Anchor.TopCentre;
|
2020-03-31 14:29:25 +08:00
|
|
|
directionContainer.Scale = new Vector2(1, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-31 14:59:52 +08:00
|
|
|
directionContainer.Anchor = Anchor.BottomCentre;
|
2020-03-31 14:29:25 +08:00
|
|
|
directionContainer.Scale = Vector2.One;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
protected virtual Drawable? GetAnimation(ISkinSource skin) => GetAnimationFromLookup(skin, LegacyManiaSkinConfigurationLookups.NoteImage);
|
2020-03-31 14:29:25 +08:00
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
protected Drawable? GetAnimationFromLookup(ISkin skin, LegacyManiaSkinConfigurationLookups lookup)
|
2020-03-31 14:29:25 +08:00
|
|
|
{
|
|
|
|
string suffix = string.Empty;
|
|
|
|
|
|
|
|
switch (lookup)
|
|
|
|
{
|
|
|
|
case LegacyManiaSkinConfigurationLookups.HoldNoteHeadImage:
|
|
|
|
suffix = "H";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LegacyManiaSkinConfigurationLookups.HoldNoteTailImage:
|
|
|
|
suffix = "T";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-20 14:56:39 +08:00
|
|
|
string noteImage = GetColumnSkinConfig<string>(skin, lookup)?.Value
|
2020-03-31 14:29:25 +08:00
|
|
|
?? $"mania-note{FallbackColumnIndex}{suffix}";
|
|
|
|
|
2021-09-14 16:45:23 +08:00
|
|
|
return skin.GetAnimation(noteImage, WrapMode.ClampToEdge, WrapMode.ClampToEdge, true, true);
|
2020-03-31 14:29:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|