2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
|
using System;
|
2020-07-22 15:37:38 +08:00
|
|
|
|
using System.Linq;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-14 13:29:22 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-09-03 16:57:34 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning;
|
2020-07-22 15:37:38 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2020-03-26 16:18:27 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-12-08 05:24:24 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
|
|
|
|
|
{
|
2019-10-17 13:02:23 +08:00
|
|
|
|
public DrawableSliderHead HeadCircle => headContainer.Child;
|
|
|
|
|
public DrawableSliderTail TailCircle => tailContainer.Child;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public readonly SliderBall Ball;
|
2019-12-17 18:29:27 +08:00
|
|
|
|
public readonly SkinnableDrawable Body;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-19 13:44:48 +08:00
|
|
|
|
public override bool DisplayResult => false;
|
|
|
|
|
|
2019-12-17 20:26:23 +08:00
|
|
|
|
private PlaySliderBody sliderBody => Body.Drawable as PlaySliderBody;
|
2019-12-17 17:16:25 +08:00
|
|
|
|
|
2019-10-16 21:10:50 +08:00
|
|
|
|
private readonly Container<DrawableSliderHead> headContainer;
|
|
|
|
|
private readonly Container<DrawableSliderTail> tailContainer;
|
|
|
|
|
private readonly Container<DrawableSliderTick> tickContainer;
|
2020-03-19 13:26:24 +08:00
|
|
|
|
private readonly Container<DrawableSliderRepeat> repeatContainer;
|
2019-10-16 21:10:50 +08:00
|
|
|
|
|
|
|
|
|
private readonly Slider slider;
|
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
|
2019-10-21 15:15:41 +08:00
|
|
|
|
private readonly IBindable<int> stackHeightBindable = new Bindable<int>();
|
2020-02-02 05:50:29 +08:00
|
|
|
|
private readonly IBindable<float> scaleBindable = new BindableFloat();
|
2019-03-05 13:40:27 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public DrawableSlider(Slider s)
|
|
|
|
|
: base(s)
|
|
|
|
|
{
|
|
|
|
|
slider = s;
|
|
|
|
|
|
|
|
|
|
Position = s.StackedPosition;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2019-12-17 18:29:27 +08:00
|
|
|
|
Body = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SliderBody), _ => new DefaultSliderBody(), confineMode: ConfineMode.NoScaling),
|
2019-10-16 21:10:50 +08:00
|
|
|
|
tickContainer = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
|
2020-03-19 13:26:24 +08:00
|
|
|
|
repeatContainer = new Container<DrawableSliderRepeat> { RelativeSizeAxes = Axes.Both },
|
2018-07-05 21:48:54 +08:00
|
|
|
|
Ball = new SliderBall(s, this)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-21 09:57:14 +08:00
|
|
|
|
GetInitialHitAction = () => HeadCircle.HitAction,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
|
|
|
Scale = new Vector2(s.Scale),
|
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
Alpha = 0
|
|
|
|
|
},
|
2019-10-16 21:10:50 +08:00
|
|
|
|
headContainer = new Container<DrawableSliderHead> { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
tailContainer = new Container<DrawableSliderTail> { RelativeSizeAxes = Axes.Both },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
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]
|
2019-03-05 13:40:27 +08:00
|
|
|
|
private void load()
|
2018-11-09 12:58:46 +08:00
|
|
|
|
{
|
|
|
|
|
positionBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
|
2019-10-21 15:15:41 +08:00
|
|
|
|
stackHeightBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
|
2019-12-17 18:29:27 +08:00
|
|
|
|
scaleBindable.BindValueChanged(scale => Ball.Scale = new Vector2(scale.NewValue));
|
2018-10-29 14:36:43 +08:00
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
positionBindable.BindTo(HitObject.PositionBindable);
|
2019-10-21 15:15:41 +08:00
|
|
|
|
stackHeightBindable.BindTo(HitObject.StackHeightBindable);
|
2018-11-09 12:58:46 +08:00
|
|
|
|
scaleBindable.BindTo(HitObject.ScaleBindable);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-22 13:45:25 +08:00
|
|
|
|
AccentColour.BindValueChanged(colour =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-02 15:10:56 +08:00
|
|
|
|
foreach (var drawableHitObject in NestedHitObjects)
|
2019-07-22 13:45:25 +08:00
|
|
|
|
drawableHitObject.AccentColour.Value = colour.NewValue;
|
|
|
|
|
}, true);
|
2020-07-22 15:37:38 +08:00
|
|
|
|
|
|
|
|
|
Tracking.BindValueChanged(updateSlidingSample);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SkinnableSound slidingSample;
|
|
|
|
|
|
|
|
|
|
protected override void LoadSamples()
|
|
|
|
|
{
|
|
|
|
|
base.LoadSamples();
|
|
|
|
|
|
|
|
|
|
slidingSample?.Expire();
|
2020-07-23 20:24:31 +08:00
|
|
|
|
slidingSample = null;
|
2020-07-22 15:37:38 +08:00
|
|
|
|
|
|
|
|
|
var firstSample = HitObject.Samples.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (firstSample != null)
|
|
|
|
|
{
|
|
|
|
|
var clone = HitObject.SampleControlPoint.ApplyTo(firstSample);
|
|
|
|
|
clone.Name = "sliderslide";
|
|
|
|
|
|
|
|
|
|
AddInternal(slidingSample = new SkinnableSound(clone)
|
|
|
|
|
{
|
|
|
|
|
Looping = true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 14:07:55 +08:00
|
|
|
|
public override void StopAllSamples()
|
|
|
|
|
{
|
|
|
|
|
base.StopAllSamples();
|
|
|
|
|
slidingSample?.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 15:37:38 +08:00
|
|
|
|
private void updateSlidingSample(ValueChangedEvent<bool> tracking)
|
|
|
|
|
{
|
2020-09-29 11:45:20 +08:00
|
|
|
|
if (tracking.NewValue)
|
2020-07-22 15:37:38 +08:00
|
|
|
|
slidingSample?.Play();
|
|
|
|
|
else
|
|
|
|
|
slidingSample?.Stop();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
2019-10-16 21:10:50 +08:00
|
|
|
|
{
|
2019-10-17 12:52:21 +08:00
|
|
|
|
base.AddNestedHitObject(hitObject);
|
2019-10-16 21:10:50 +08:00
|
|
|
|
|
2019-10-17 11:53:54 +08:00
|
|
|
|
switch (hitObject)
|
2019-10-16 21:10:50 +08:00
|
|
|
|
{
|
|
|
|
|
case DrawableSliderHead head:
|
2019-10-17 13:02:23 +08:00
|
|
|
|
headContainer.Child = head;
|
2019-10-16 21:10:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableSliderTail tail:
|
2019-10-17 13:02:23 +08:00
|
|
|
|
tailContainer.Child = tail;
|
2019-10-16 21:10:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DrawableSliderTick tick:
|
|
|
|
|
tickContainer.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
|
2020-03-19 13:26:24 +08:00
|
|
|
|
case DrawableSliderRepeat repeat:
|
2019-10-16 21:10:50 +08:00
|
|
|
|
repeatContainer.Add(repeat);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override void ClearNestedHitObjects()
|
2019-10-16 21:10:50 +08:00
|
|
|
|
{
|
2019-10-17 12:52:21 +08:00
|
|
|
|
base.ClearNestedHitObjects();
|
2019-10-16 21:10:50 +08:00
|
|
|
|
|
|
|
|
|
headContainer.Clear();
|
|
|
|
|
tailContainer.Clear();
|
|
|
|
|
repeatContainer.Clear();
|
|
|
|
|
tickContainer.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
2019-10-16 21:10:50 +08:00
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case SliderTailCircle tail:
|
|
|
|
|
return new DrawableSliderTail(slider, tail);
|
|
|
|
|
|
2020-03-30 15:14:56 +08:00
|
|
|
|
case SliderHeadCircle head:
|
2020-04-17 13:33:29 +08:00
|
|
|
|
return new DrawableSliderHead(slider, head)
|
|
|
|
|
{
|
|
|
|
|
OnShake = Shake,
|
|
|
|
|
CheckHittable = (d, t) => CheckHittable?.Invoke(d, t) ?? true
|
|
|
|
|
};
|
2019-10-16 21:10:50 +08:00
|
|
|
|
|
|
|
|
|
case SliderTick tick:
|
|
|
|
|
return new DrawableSliderTick(tick) { Position = tick.Position - slider.Position };
|
|
|
|
|
|
2020-03-19 13:42:02 +08:00
|
|
|
|
case SliderRepeat repeat:
|
2020-03-19 13:26:24 +08:00
|
|
|
|
return new DrawableSliderRepeat(repeat, this) { Position = repeat.Position - slider.Position };
|
2019-10-16 21:10:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:52:21 +08:00
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
2019-10-16 21:10:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 20:41:18 +08:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateInitialTransforms();
|
|
|
|
|
|
|
|
|
|
Body.FadeInFromZero(HitObject.TimeFadeIn);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 09:47:22 +08:00
|
|
|
|
public readonly Bindable<bool> Tracking = new Bindable<bool>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-04-12 09:47:22 +08:00
|
|
|
|
Tracking.Value = Ball.Tracking;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-22 15:37:38 +08:00
|
|
|
|
if (Tracking.Value && slidingSample != null)
|
|
|
|
|
// keep the sliding sample playing at the current tracking position
|
|
|
|
|
slidingSample.Balance.Value = CalculateSamplePlaybackBalance(Ball.X / OsuPlayfield.BASE_SIZE.X);
|
|
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
|
double completionProgress = Math.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-10-16 21:10:50 +08:00
|
|
|
|
Ball.UpdateProgress(completionProgress);
|
2019-12-17 20:26:23 +08:00
|
|
|
|
sliderBody?.UpdateProgress(completionProgress);
|
2019-10-16 21:10:50 +08:00
|
|
|
|
|
|
|
|
|
foreach (DrawableHitObject hitObject in NestedHitObjects)
|
|
|
|
|
{
|
2019-12-17 20:26:23 +08:00
|
|
|
|
if (hitObject is ITrackSnaking s) s.UpdateSnakingPosition(slider.Path.PositionAt(sliderBody?.SnakedStart ?? 0), slider.Path.PositionAt(sliderBody?.SnakedEnd ?? 0));
|
2019-10-16 21:10:50 +08:00
|
|
|
|
if (hitObject is IRequireTracking t) t.Tracking = Ball.Tracking;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-17 20:26:23 +08:00
|
|
|
|
Size = sliderBody?.Size ?? Vector2.Zero;
|
|
|
|
|
OriginPosition = sliderBody?.PathOffset ?? Vector2.Zero;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (DrawSize != Vector2.Zero)
|
|
|
|
|
{
|
|
|
|
|
var childAnchorPosition = Vector2.Divide(OriginPosition, DrawSize);
|
|
|
|
|
foreach (var obj in NestedHitObjects)
|
|
|
|
|
obj.RelativeAnchorPosition = childAnchorPosition;
|
|
|
|
|
Ball.RelativeAnchorPosition = childAnchorPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 17:19:13 +08:00
|
|
|
|
public override void OnKilled()
|
|
|
|
|
{
|
|
|
|
|
base.OnKilled();
|
2019-12-17 20:26:23 +08:00
|
|
|
|
sliderBody?.RecyclePath();
|
2019-07-16 17:19:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 19:19:57 +08:00
|
|
|
|
protected override void ApplySkin(ISkinSource skin, bool allowFallback)
|
2018-12-08 05:24:24 +08:00
|
|
|
|
{
|
2019-09-18 19:19:57 +08:00
|
|
|
|
base.ApplySkin(skin, allowFallback);
|
2019-01-07 19:12:39 +08:00
|
|
|
|
|
2019-09-20 20:08:00 +08:00
|
|
|
|
bool allowBallTint = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.AllowSliderBallTint)?.Value ?? false;
|
2020-04-05 02:17:11 +08:00
|
|
|
|
Ball.AccentColour = allowBallTint ? AccentColour.Value : Color4.White;
|
2018-12-08 05:24:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-01 20:46:22 +08:00
|
|
|
|
if (userTriggered || Time.Current < slider.EndTime)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-03-26 18:51:02 +08:00
|
|
|
|
ApplyResult(r => r.Type = r.Judgement.MaxResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PlaySamples()
|
|
|
|
|
{
|
|
|
|
|
// rather than doing it this way, we should probably attach the sample to the tail circle.
|
|
|
|
|
// this can only be done after we stop using LegacyLastTick.
|
|
|
|
|
if (TailCircle.Result.Type != HitResult.Miss)
|
|
|
|
|
base.PlaySamples();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:33:12 +08:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-09-13 17:49:21 +08:00
|
|
|
|
base.UpdateStateTransforms(state);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Ball.FadeIn();
|
|
|
|
|
Ball.ScaleTo(HitObject.Scale);
|
|
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(slider.Duration, true))
|
|
|
|
|
{
|
|
|
|
|
const float fade_out_time = 450;
|
|
|
|
|
|
|
|
|
|
// intentionally pile on an extra FadeOut to make it happen much faster.
|
|
|
|
|
Ball.FadeOut(fade_out_time / 4, Easing.Out);
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
Ball.ScaleTo(HitObject.Scale * 1.4f, fade_out_time, Easing.Out);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 18:29:08 +08:00
|
|
|
|
this.FadeOut(fade_out_time, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 11:50:22 +08:00
|
|
|
|
public Drawable ProxiedLayer => HeadCircle.ProxiedLayer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-17 20:26:23 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => sliderBody?.ReceivePositionalInputAt(screenSpacePos) ?? base.ReceivePositionalInputAt(screenSpacePos);
|
2019-12-17 18:29:27 +08:00
|
|
|
|
|
|
|
|
|
private class DefaultSliderBody : PlaySliderBody
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|