1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 21:17:33 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSliderHead.cs

80 lines
2.3 KiB
C#
Raw Normal View History

// 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
using System;
2018-11-09 12:58:46 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2020-11-12 14:59:48 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableSliderHead : DrawableHitCircle
{
private readonly IBindable<int> pathVersion = new Bindable<int>();
2018-11-09 12:58:46 +08:00
protected override OsuSkinComponents CirclePieceComponent => OsuSkinComponents.SliderHeadHitCircle;
2020-11-12 14:59:48 +08:00
private DrawableSlider drawableSlider;
2018-04-13 17:19:50 +08:00
2020-11-12 14:59:48 +08:00
private Slider slider => drawableSlider?.HitObject;
public DrawableSliderHead()
{
}
public DrawableSliderHead(SliderHeadCircle h)
2018-04-13 17:19:50 +08:00
: base(h)
{
2018-11-09 12:58:46 +08:00
}
2018-04-13 17:19:50 +08:00
2018-11-09 12:58:46 +08:00
[BackgroundDependencyLoader]
private void load()
{
2020-11-05 12:51:46 +08:00
PositionBindable.BindValueChanged(_ => updatePosition());
2020-11-12 14:59:48 +08:00
pathVersion.BindValueChanged(_ => updatePosition());
}
protected override void OnFree(HitObject hitObject)
{
base.OnFree(hitObject);
pathVersion.UnbindFrom(drawableSlider.PathVersion);
}
protected override void OnParentReceived(DrawableHitObject parent)
{
base.OnParentReceived(parent);
drawableSlider = (DrawableSlider)parent;
pathVersion.BindTo(drawableSlider.PathVersion);
OnShake = drawableSlider.Shake;
CheckHittable = (d, t) => drawableSlider.CheckHittable?.Invoke(d, t) ?? true;
2018-04-13 17:19:50 +08:00
}
protected override void Update()
{
base.Update();
double completionProgress = Math.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
2018-04-13 17:19:50 +08:00
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
if (!IsHit)
Position = slider.CurvePositionAt(completionProgress);
}
public Action<double> OnShake;
2020-11-12 14:59:48 +08:00
public override void Shake(double maximumLength) => OnShake?.Invoke(maximumLength);
2020-11-12 14:59:48 +08:00
private void updatePosition()
{
if (slider != null)
Position = HitObject.Position - slider.Position;
}
2018-04-13 17:19:50 +08:00
}
}