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