1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 11:47:52 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSliderBall.cs

81 lines
3.1 KiB
C#
Raw Normal View History

2020-02-02 21:34:06 +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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2019-01-21 09:57:14 +08:00
using System;
using osu.Framework.Allocation;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Skinning;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
2018-04-13 17:19:50 +08:00
{
public partial class DrawableSliderBall : CircularContainer, ISliderProgress
2018-04-13 17:19:50 +08:00
{
public const float FOLLOW_AREA = 2.4f;
private DrawableSlider drawableSlider;
private Drawable ball;
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableSlider)
2018-04-13 17:19:50 +08:00
{
this.drawableSlider = (DrawableSlider)drawableSlider;
2018-04-13 17:19:50 +08:00
Origin = Anchor.Centre;
2023-09-20 11:48:15 +08:00
Size = OsuHitObject.OBJECT_DIMENSIONS;
Children = new[]
2018-04-13 17:19:50 +08:00
{
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderFollowCircle), _ => new DefaultFollowCircle())
2018-04-13 17:19:50 +08:00
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
2018-04-13 17:19:50 +08:00
},
ball = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderBall), _ => new DefaultSliderBall())
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
2018-04-13 17:19:50 +08:00
};
}
public override void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null)
{
// Consider the case of rewinding - children's transforms are handled internally, so propagating down
// any further will cause weirdness with the Tracking bool below. Let's not propagate further at this point.
base.ClearTransformsAfter(time, false, targetMember);
}
public override void ApplyTransformsAt(double time, bool propagateChildren = false)
{
// For the same reasons as above w.r.t rewinding, we shouldn't propagate to children here either.
// ReSharper disable once RedundantArgumentDefaultValue
base.ApplyTransformsAt(time, false);
}
2018-04-13 17:19:50 +08:00
public void UpdateProgress(double completionProgress)
{
Slider slider = drawableSlider.HitObject;
Position = slider.CurvePositionAt(completionProgress);
//0.1 / slider.Path.Distance is the additional progress needed to ensure the diff length is 0.1
var diff = slider.CurvePositionAt(completionProgress) - slider.CurvePositionAt(Math.Min(1, completionProgress + 0.1 / slider.Path.Distance));
// Ensure the value is substantially high enough to allow for Atan2 to get a valid angle.
// Needed for when near completion, or in case of a very short slider.
if (diff.LengthFast < 0.01f)
return;
2019-08-19 18:52:53 +08:00
ball.Rotation = -90 + (float)(-Math.Atan2(diff.X, diff.Y) * 180 / Math.PI);
2018-04-13 17:19:50 +08:00
}
}
}