2020-03-31 06:29:25 +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;
|
2020-07-17 08:08:26 +00:00
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
2020-03-31 06:29:25 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning
|
|
|
|
{
|
|
|
|
public class LegacyNotePiece : LegacyManiaColumnElement
|
|
|
|
{
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
|
|
|
private Container directionContainer;
|
|
|
|
private Sprite noteSprite;
|
|
|
|
|
2020-04-07 07:07:18 +00:00
|
|
|
private float? minimumColumnWidth;
|
|
|
|
|
2020-03-31 06:29:25 +00:00
|
|
|
public LegacyNotePiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
|
|
|
|
{
|
2020-04-07 07:07:18 +00:00
|
|
|
minimumColumnWidth = skin.GetConfig<ManiaSkinConfigurationLookup, float>(new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.MinimumColumnWidth))?.Value;
|
|
|
|
|
2020-03-31 06:29:25 +00:00
|
|
|
InternalChild = directionContainer = new Container
|
|
|
|
{
|
2020-03-31 06:59:52 +00:00
|
|
|
Origin = Anchor.BottomCentre,
|
2020-03-31 06:29:25 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = noteSprite = new Sprite { Texture = GetTexture(skin) }
|
|
|
|
};
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
direction.BindValueChanged(OnDirectionChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (noteSprite.Texture != null)
|
|
|
|
{
|
2020-04-07 07:07:18 +00:00
|
|
|
// The height is scaled to the minimum column width, if provided.
|
|
|
|
float minimumWidth = minimumColumnWidth ?? DrawWidth;
|
|
|
|
|
|
|
|
noteSprite.Scale = Vector2.Divide(new Vector2(DrawWidth, minimumWidth), noteSprite.Texture.DisplayWidth);
|
2020-03-31 06:29:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
|
|
|
{
|
|
|
|
if (direction.NewValue == ScrollingDirection.Up)
|
|
|
|
{
|
2020-03-31 06:59:52 +00:00
|
|
|
directionContainer.Anchor = Anchor.TopCentre;
|
2020-03-31 06:29:25 +00:00
|
|
|
directionContainer.Scale = new Vector2(1, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-31 06:59:52 +00:00
|
|
|
directionContainer.Anchor = Anchor.BottomCentre;
|
2020-03-31 06:29:25 +00:00
|
|
|
directionContainer.Scale = Vector2.One;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual Texture GetTexture(ISkinSource skin) => GetTextureFromLookup(skin, LegacyManiaSkinConfigurationLookups.NoteImage);
|
|
|
|
|
|
|
|
protected Texture GetTextureFromLookup(ISkin skin, LegacyManiaSkinConfigurationLookups lookup)
|
|
|
|
{
|
|
|
|
string suffix = string.Empty;
|
|
|
|
|
|
|
|
switch (lookup)
|
|
|
|
{
|
|
|
|
case LegacyManiaSkinConfigurationLookups.HoldNoteHeadImage:
|
|
|
|
suffix = "H";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LegacyManiaSkinConfigurationLookups.HoldNoteTailImage:
|
|
|
|
suffix = "T";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-20 06:56:39 +00:00
|
|
|
string noteImage = GetColumnSkinConfig<string>(skin, lookup)?.Value
|
2020-03-31 06:29:25 +00:00
|
|
|
?? $"mania-note{FallbackColumnIndex}{suffix}";
|
|
|
|
|
2020-07-17 08:08:26 +00:00
|
|
|
return skin.GetTexture(noteImage, WrapMode.ClampToEdge, WrapMode.ClampToEdge);
|
2020-03-31 06:29:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|