2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-07-06 02:52:58 +00:00
|
|
|
|
using System;
|
2020-12-03 05:28:37 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using JetBrains.Annotations;
|
2018-11-09 04:58:46 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2021-02-03 13:12:20 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSliderHead : DrawableHitCircle
|
|
|
|
|
{
|
2021-02-03 12:25:05 +00:00
|
|
|
|
public new SliderHeadCircle HitObject => (SliderHeadCircle)base.HitObject;
|
|
|
|
|
|
2020-12-03 05:28:37 +00:00
|
|
|
|
[CanBeNull]
|
2020-12-03 11:10:16 +00:00
|
|
|
|
public Slider Slider => DrawableSlider?.HitObject;
|
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
protected DrawableSlider DrawableSlider => (DrawableSlider)ParentHitObject;
|
2020-12-03 05:28:37 +00:00
|
|
|
|
|
2021-02-03 13:12:20 +00:00
|
|
|
|
public override bool DisplayResult => HitObject?.JudgeAsNormalHitCircle ?? base.DisplayResult;
|
|
|
|
|
|
2021-02-05 08:33:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes this <see cref="DrawableSliderHead"/> track the follow circle when the start time is reached.
|
|
|
|
|
/// If <c>false</c>, this <see cref="DrawableSliderHead"/> will be pinned to its initial position in the slider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool TrackFollowCircle = true;
|
|
|
|
|
|
2019-12-05 10:53:31 +00:00
|
|
|
|
private readonly IBindable<int> pathVersion = new Bindable<int>();
|
2018-11-09 04:58:46 +00:00
|
|
|
|
|
2020-03-28 04:39:08 +00:00
|
|
|
|
protected override OsuSkinComponents CirclePieceComponent => OsuSkinComponents.SliderHeadHitCircle;
|
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
public DrawableSliderHead()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawableSliderHead(SliderHeadCircle h)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
: base(h)
|
|
|
|
|
{
|
2018-11-09 04:58:46 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-09 04:58:46 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2020-11-05 04:51:46 +00:00
|
|
|
|
PositionBindable.BindValueChanged(_ => updatePosition());
|
2020-11-12 06:59:48 +00:00
|
|
|
|
pathVersion.BindValueChanged(_ => updatePosition());
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 01:13:05 +00:00
|
|
|
|
protected override void OnFree()
|
2020-11-12 06:59:48 +00:00
|
|
|
|
{
|
2020-11-27 01:13:05 +00:00
|
|
|
|
base.OnFree();
|
2020-11-12 06:59:48 +00:00
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
pathVersion.UnbindFrom(DrawableSlider.PathVersion);
|
2020-11-12 06:59:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 10:46:42 +00:00
|
|
|
|
protected override void OnApply()
|
2020-11-12 06:59:48 +00:00
|
|
|
|
{
|
2020-12-03 10:46:42 +00:00
|
|
|
|
base.OnApply();
|
2020-11-12 06:59:48 +00:00
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
pathVersion.BindTo(DrawableSlider.PathVersion);
|
2020-11-12 06:59:48 +00:00
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
OnShake = DrawableSlider.Shake;
|
|
|
|
|
CheckHittable = (d, t) => DrawableSlider.CheckHittable?.Invoke(d, t) ?? true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2020-12-03 05:28:37 +00:00
|
|
|
|
Debug.Assert(Slider != null);
|
2021-02-03 12:25:05 +00:00
|
|
|
|
Debug.Assert(HitObject != null);
|
2020-12-03 05:28:37 +00:00
|
|
|
|
|
2021-02-05 08:33:48 +00:00
|
|
|
|
if (TrackFollowCircle)
|
2021-02-03 12:25:05 +00:00
|
|
|
|
{
|
|
|
|
|
double completionProgress = Math.Clamp((Time.Current - Slider.StartTime) / Slider.Duration, 0, 1);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-02-03 12:25:05 +00:00
|
|
|
|
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
|
|
|
|
|
if (!IsHit)
|
|
|
|
|
Position = Slider.CurvePositionAt(completionProgress);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2018-07-06 02:52:58 +00:00
|
|
|
|
|
2021-02-03 13:12:20 +00:00
|
|
|
|
protected override HitResult ResultFor(double timeOffset)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(HitObject != null);
|
|
|
|
|
|
|
|
|
|
if (HitObject.JudgeAsNormalHitCircle)
|
|
|
|
|
return base.ResultFor(timeOffset);
|
|
|
|
|
|
2021-02-10 10:04:23 +00:00
|
|
|
|
// If not judged as a normal hitcircle, judge as a slider tick instead. This is the classic osu!stable scoring.
|
2021-02-03 13:12:20 +00:00
|
|
|
|
var result = base.ResultFor(timeOffset);
|
2021-02-10 09:38:31 +00:00
|
|
|
|
return result.IsHit() ? HitResult.LargeTickHit : HitResult.LargeTickMiss;
|
2021-02-03 13:12:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 08:24:30 +00:00
|
|
|
|
public Action<double> OnShake;
|
2018-07-06 02:52:58 +00:00
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
public override void Shake(double maximumLength) => OnShake?.Invoke(maximumLength);
|
2018-10-29 06:36:43 +00:00
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
private void updatePosition()
|
|
|
|
|
{
|
2020-12-03 05:28:37 +00:00
|
|
|
|
if (Slider != null)
|
|
|
|
|
Position = HitObject.Position - Slider.Position;
|
2020-11-12 06:59:48 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|