From d0766fa1cdaa15c1a35a096e1364de4455dcefb5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Aug 2019 19:52:53 +0900 Subject: [PATCH] Add slider ball animation support --- .../Objects/Drawables/Pieces/SliderBall.cs | 12 +++++- osu.Game/Skinning/LegacySkin.cs | 42 +++++++++++++------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs index 8b72b23ca3..332e25750f 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs @@ -55,7 +55,6 @@ public SliderBall(Slider slider, DrawableSlider drawableSlider = null) Child = new Container { RelativeSizeAxes = Axes.Both, - // TODO: support skin filename animation (sliderb0, sliderb1...) Child = new SkinnableDrawable("Play/osu/sliderball", _ => new DefaultSliderBall()), } } @@ -168,9 +167,18 @@ private bool isValidTrackingAction(OsuAction action) return action == OsuAction.LeftButton || action == OsuAction.RightButton; } + private Vector2? lastPosition; + public void UpdateProgress(double completionProgress) { - Position = slider.CurvePositionAt(completionProgress); + var newPos = slider.CurvePositionAt(completionProgress); + + var diff = lastPosition.HasValue ? lastPosition.Value - newPos : newPos - slider.CurvePositionAt(completionProgress + 0.01f); + + Position = newPos; + Rotation = 90 + (float)(-Math.Atan2(diff.X, diff.Y) * 180 / Math.PI); + + lastPosition = newPos; } private class FollowCircleContainer : Container diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 94421b1251..883e0ce3fc 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -92,8 +92,20 @@ public override Drawable GetDrawableComponent(string componentName) return null; case "Play/osu/sliderball": - if (GetTexture("sliderb") != null) - return new LegacySliderBall(); + var sliderBallContent = getAnimation("sliderb", true, true, ""); + + if (sliderBallContent != null) + { + var size = sliderBallContent.Size; + + sliderBallContent.RelativeSizeAxes = Axes.Both; + sliderBallContent.Size = Vector2.One; + + return new LegacySliderBall(sliderBallContent) + { + Size = size + }; + } return null; @@ -169,16 +181,6 @@ private Drawable getAnimation(string componentName, bool animatable, bool loopin return (texture = GetTexture(componentName)) == null ? null : new Sprite { Texture = texture }; } - public class LegacySliderBall : Sprite - { - [BackgroundDependencyLoader] - private void load(ISkinSource skin) - { - Texture = skin.GetTexture("sliderb"); - Colour = skin.GetValue(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Color4.White; - } - } - public override Texture GetTexture(string componentName) { float ratio = 2; @@ -333,6 +335,20 @@ private void load(ISkinSource skin) } } + public class LegacySliderBall : CompositeDrawable + { + public LegacySliderBall(Drawable content) + { + InternalChild = content; + } + + [BackgroundDependencyLoader] + private void load(ISkinSource skin) + { + Colour = skin.GetValue(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Color4.White; + } + } + public class LegacyMainCirclePiece : CompositeDrawable { public LegacyMainCirclePiece()