2020-03-31 15:42:35 +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.Animations;
|
2020-07-17 16:08:26 +08:00
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
2020-03-31 15:42:35 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning
|
|
|
|
{
|
|
|
|
public class LegacyBodyPiece : LegacyManiaColumnElement
|
|
|
|
{
|
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
private readonly IBindable<bool> isHitting = new Bindable<bool>();
|
|
|
|
|
|
|
|
private Drawable sprite;
|
|
|
|
|
|
|
|
public LegacyBodyPiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo, DrawableHitObject drawableObject)
|
|
|
|
{
|
2020-06-20 14:56:39 +08:00
|
|
|
string imageName = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.HoldNoteBodyImage)?.Value
|
2020-03-31 15:42:35 +08:00
|
|
|
?? $"mania-note{FallbackColumnIndex}L";
|
|
|
|
|
2020-07-17 16:08:26 +08:00
|
|
|
sprite = skin.GetAnimation(imageName, WrapMode.ClampToEdge, WrapMode.ClampToEdge, true, true).With(d =>
|
2020-03-31 15:42:35 +08:00
|
|
|
{
|
|
|
|
if (d == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d is TextureAnimation animation)
|
|
|
|
animation.IsPlaying = false;
|
|
|
|
|
|
|
|
d.Anchor = Anchor.TopCentre;
|
|
|
|
d.RelativeSizeAxes = Axes.Both;
|
|
|
|
d.Size = Vector2.One;
|
|
|
|
d.FillMode = FillMode.Stretch;
|
|
|
|
// Todo: Wrap
|
|
|
|
});
|
|
|
|
|
|
|
|
if (sprite != null)
|
|
|
|
InternalChild = sprite;
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
direction.BindValueChanged(onDirectionChanged, true);
|
|
|
|
|
|
|
|
var holdNote = (DrawableHoldNote)drawableObject;
|
|
|
|
isHitting.BindTo(holdNote.IsHitting);
|
|
|
|
isHitting.BindValueChanged(onIsHittingChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onIsHittingChanged(ValueChangedEvent<bool> isHitting)
|
|
|
|
{
|
|
|
|
if (!(sprite is TextureAnimation animation))
|
|
|
|
return;
|
|
|
|
|
2020-04-02 16:09:08 +08:00
|
|
|
animation.GotoFrame(0);
|
2020-03-31 15:42:35 +08:00
|
|
|
animation.IsPlaying = isHitting.NewValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
|
|
|
{
|
|
|
|
if (sprite == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (direction.NewValue == ScrollingDirection.Up)
|
|
|
|
{
|
|
|
|
sprite.Origin = Anchor.BottomCentre;
|
|
|
|
sprite.Scale = new Vector2(1, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite.Origin = Anchor.TopCentre;
|
|
|
|
sprite.Scale = Vector2.One;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|