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;
|
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;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSliderHead : DrawableHitCircle
|
|
|
|
|
{
|
2018-11-09 04:58:46 +00:00
|
|
|
|
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
|
2019-12-05 10:53:31 +00:00
|
|
|
|
private readonly IBindable<int> pathVersion = new Bindable<int>();
|
2018-11-09 04:58:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly Slider slider;
|
|
|
|
|
|
|
|
|
|
public DrawableSliderHead(Slider slider, HitCircle h)
|
|
|
|
|
: base(h)
|
|
|
|
|
{
|
|
|
|
|
this.slider = slider;
|
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()
|
|
|
|
|
{
|
|
|
|
|
positionBindable.BindTo(HitObject.PositionBindable);
|
2019-12-05 10:53:31 +00:00
|
|
|
|
pathVersion.BindTo(slider.Path.Version);
|
2018-11-14 05:29:22 +00:00
|
|
|
|
|
|
|
|
|
positionBindable.BindValueChanged(_ => updatePosition());
|
2019-12-05 10:53:31 +00:00
|
|
|
|
pathVersion.BindValueChanged(_ => updatePosition(), true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-11-20 12:19:49 +00:00
|
|
|
|
double completionProgress = Math.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
2018-04-13 09:19:50 +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-07-06 02:52:58 +00:00
|
|
|
|
|
2018-07-06 08:24:30 +00:00
|
|
|
|
public Action<double> OnShake;
|
2018-07-06 02:52:58 +00:00
|
|
|
|
|
2018-07-06 08:24:30 +00:00
|
|
|
|
protected override void Shake(double maximumLength) => OnShake?.Invoke(maximumLength);
|
2018-10-29 06:36:43 +00:00
|
|
|
|
|
|
|
|
|
private void updatePosition() => Position = HitObject.Position - slider.Position;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|