2020-02-02 13:34:06 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-01-21 01:57:14 +00:00
|
|
|
|
using System;
|
2019-07-25 06:35:51 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-25 06:35:51 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-02-23 11:51:26 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2022-06-29 08:23:35 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2018-07-29 19:28:13 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-29 08:23:35 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2023-12-15 07:13:32 +00:00
|
|
|
|
public partial class DrawableSliderBall : CircularContainer, ISliderProgress
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2022-07-03 20:51:30 +00:00
|
|
|
|
public const float FOLLOW_AREA = 2.4f;
|
|
|
|
|
|
2022-06-29 08:23:35 +00:00
|
|
|
|
private DrawableSlider drawableSlider;
|
|
|
|
|
private Drawable ball;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-29 08:23:35 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(DrawableHitObject drawableSlider)
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2022-06-29 08:23:35 +00:00
|
|
|
|
this.drawableSlider = (DrawableSlider)drawableSlider;
|
2019-07-25 06:35:51 +00:00
|
|
|
|
|
2016-12-06 09:54:32 +00:00
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-09-20 03:48:15 +00:00
|
|
|
|
Size = OsuHitObject.OBJECT_DIMENSIONS;
|
2019-07-25 06:35:51 +00:00
|
|
|
|
|
2018-07-29 19:28:13 +00:00
|
|
|
|
Children = new[]
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2022-11-09 07:04:56 +00:00
|
|
|
|
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderFollowCircle), _ => new DefaultFollowCircle())
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2019-07-25 06:35:51 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-12-06 09:54:32 +00:00
|
|
|
|
},
|
2022-11-09 07:04:56 +00:00
|
|
|
|
ball = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderBall), _ => new DefaultSliderBall())
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2020-07-22 10:06:39 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
2016-12-06 09:54:32 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-01-03 12:55:24 +00:00
|
|
|
|
public override void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null)
|
2017-11-03 06:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
// 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.
|
2018-01-03 07:13:58 +00:00
|
|
|
|
base.ClearTransformsAfter(time, false, targetMember);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-14 09:51:28 +00:00
|
|
|
|
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.
|
2022-10-29 09:09:27 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable once RedundantArgumentDefaultValue
|
|
|
|
|
base.ApplyTransformsAt(time, false);
|
2019-03-14 09:51:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 08:10:18 +00:00
|
|
|
|
public void UpdateProgress(double completionProgress)
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2024-05-28 17:38:33 +00:00
|
|
|
|
Slider slider = drawableSlider.HitObject;
|
|
|
|
|
Position = slider.CurvePositionAt(completionProgress);
|
2022-05-12 08:55:12 +00:00
|
|
|
|
|
2024-05-28 17:38:33 +00:00
|
|
|
|
//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));
|
2022-10-10 06:24:17 +00:00
|
|
|
|
|
2022-05-12 08:55:12 +00:00
|
|
|
|
// Ensure the value is substantially high enough to allow for Atan2 to get a valid angle.
|
2024-05-28 17:38:33 +00:00
|
|
|
|
// Needed for when near completion, or in case of a very short slider.
|
2022-05-12 08:55:12 +00:00
|
|
|
|
if (diff.LengthFast < 0.01f)
|
2019-08-20 04:18:34 +00:00
|
|
|
|
return;
|
2019-08-19 10:52:53 +00:00
|
|
|
|
|
2024-05-28 17:38:33 +00:00
|
|
|
|
ball.Rotation = -90 + (float)(-Math.Atan2(diff.X, diff.Y) * 180 / Math.PI);
|
2016-12-06 09:54:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-03 07:13:58 +00:00
|
|
|
|
}
|