1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 05:37:24 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

393 lines
14 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
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Collections.Generic;
2020-07-22 15:37:38 +08:00
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Layout;
2020-11-19 19:40:30 +08:00
using osu.Game.Audio;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
2018-11-14 13:29:22 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Judgements;
2020-12-04 19:21:53 +08:00
using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Rulesets.Scoring;
2018-12-08 05:24:24 +08:00
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public partial class DrawableSlider : DrawableOsuHitObject
{
2020-11-05 12:51:46 +08:00
public new Slider HitObject => (Slider)base.HitObject;
public new OsuSliderJudgementResult Result => (OsuSliderJudgementResult)base.Result;
public DrawableSliderHead HeadCircle => headContainer.Child;
public DrawableSliderTail TailCircle => tailContainer.Child;
2018-04-13 17:19:50 +08:00
[Cached]
public DrawableSliderBall Ball { get; private set; }
2020-11-05 12:51:46 +08:00
public SkinnableDrawable Body { get; private set; }
2018-04-13 17:19:50 +08:00
private ShakeContainer shakeContainer;
protected override IEnumerable<Drawable> DimmablePieces => new Drawable[]
{
// HeadCircle should not be added to this list, as it handles dimming itself
TailCircle,
repeatContainer,
Body,
};
/// <summary>
/// A target container which can be used to add top level elements to the slider's display.
/// Intended to be used for proxy purposes only.
/// </summary>
public Container OverlayElementContainer { get; private set; }
public override bool DisplayResult => HitObject.ClassicSliderBehaviour;
[CanBeNull]
public PlaySliderBody SliderBody => Body.Drawable as PlaySliderBody;
2019-12-17 17:16:25 +08:00
public IBindable<int> PathVersion => pathVersion;
private readonly Bindable<int> pathVersion = new Bindable<int>();
public readonly SliderInputManager SliderInputManager;
2020-11-05 12:51:46 +08:00
private Container<DrawableSliderHead> headContainer;
private Container<DrawableSliderTail> tailContainer;
private Container<DrawableSliderTick> tickContainer;
private Container<DrawableSliderRepeat> repeatContainer;
2020-11-19 19:40:30 +08:00
private PausableSkinnableSound slidingSample;
private readonly LayoutValue relativeAnchorPositionLayout;
2020-11-10 23:22:06 +08:00
public DrawableSlider()
: this(null)
{
}
public DrawableSlider([CanBeNull] Slider s = null)
: base(s)
{
SliderInputManager = new SliderInputManager(this);
Ball = new DrawableSliderBall
{
BypassAutoSizeAxes = Axes.Both,
AlwaysPresent = true,
Alpha = 0
};
AddLayout(relativeAnchorPositionLayout = new LayoutValue(Invalidation.DrawSize | Invalidation.MiscGeometry));
2020-11-05 12:51:46 +08:00
}
2018-04-13 17:19:50 +08:00
2020-11-05 12:51:46 +08:00
[BackgroundDependencyLoader]
private void load()
{
Fix not being able to receive full score for extremely short sliders with repeats Closes #23862. Score V2 is a scoring algorithm, which aside from the raw numerical values of each judgement, incorporates a combo component, wherein each judgement's "combo score" is derived from both the raw numerical value of the object and the current combo after the given judgement. In particular, this means that Score V2 is sensitive to the _order_ of judging objects, as if two objects with the same start time are judged using different ordering, they can end up having a different "combo score". The issue that this change is fixing is an instance of one such reordering. Upon inspection, it turned out that the simulated autoplay run, which is used to determine max possible score so that it can be standardised to 1 million again, was processing a slider repeat before a slider tail circle, while actual gameplay was processing the same slider repeat _after_ the slider tail circle. The cause of that behaviour is unfortunately due to `LegacyLastTick`. The sliders which cause the issue are extremely short. Stable had a behaviour, in which to provide leniency, slider tails were artificially offset back by 36ms. However, if the slider is not long enough to make this possible, the last tick is placed in the middle of the slider. If that slider also happens to have exactly 1 repeat, then this means that the last tick and the repeat have the same time instant. Because of the time equality, what begins to matter now is the _order_ of processing the elements of the drawable slider in the hierarchy. For the purposes of legacy skins, tail circles were moved below ticks in fce3eacd7de3254ce75619efaa2d15d59d564623 - but in this particular case, it means that the order of processing the slider elements is now inadvertently inverted, causing the entire debacle. While the fact that scoring depends on order of processing of visuals is suboptimal, there isn't a great way to address this without significant restructuring. Due to the structure of processing judgements currently in place, in which each judgement is processed independently from others by its corresponding drawable hit object, this is probably the best that can be done for the time being at least.
2023-06-10 17:02:29 +08:00
tailContainer = new Container<DrawableSliderTail> { RelativeSizeAxes = Axes.Both };
AddRangeInternal(new Drawable[]
{
SliderInputManager,
shakeContainer = new ShakeContainer
{
ShakeDuration = 30,
RelativeSizeAxes = Axes.Both,
Fix not being able to receive full score for extremely short sliders with repeats Closes #23862. Score V2 is a scoring algorithm, which aside from the raw numerical values of each judgement, incorporates a combo component, wherein each judgement's "combo score" is derived from both the raw numerical value of the object and the current combo after the given judgement. In particular, this means that Score V2 is sensitive to the _order_ of judging objects, as if two objects with the same start time are judged using different ordering, they can end up having a different "combo score". The issue that this change is fixing is an instance of one such reordering. Upon inspection, it turned out that the simulated autoplay run, which is used to determine max possible score so that it can be standardised to 1 million again, was processing a slider repeat before a slider tail circle, while actual gameplay was processing the same slider repeat _after_ the slider tail circle. The cause of that behaviour is unfortunately due to `LegacyLastTick`. The sliders which cause the issue are extremely short. Stable had a behaviour, in which to provide leniency, slider tails were artificially offset back by 36ms. However, if the slider is not long enough to make this possible, the last tick is placed in the middle of the slider. If that slider also happens to have exactly 1 repeat, then this means that the last tick and the repeat have the same time instant. Because of the time equality, what begins to matter now is the _order_ of processing the elements of the drawable slider in the hierarchy. For the purposes of legacy skins, tail circles were moved below ticks in fce3eacd7de3254ce75619efaa2d15d59d564623 - but in this particular case, it means that the order of processing the slider elements is now inadvertently inverted, causing the entire debacle. While the fact that scoring depends on order of processing of visuals is suboptimal, there isn't a great way to address this without significant restructuring. Due to the structure of processing judgements currently in place, in which each judgement is processed independently from others by its corresponding drawable hit object, this is probably the best that can be done for the time being at least.
2023-06-10 17:02:29 +08:00
Children = new[]
{
Body = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderBody), _ => new DefaultSliderBody(), confineMode: ConfineMode.NoScaling),
Fix not being able to receive full score for extremely short sliders with repeats Closes #23862. Score V2 is a scoring algorithm, which aside from the raw numerical values of each judgement, incorporates a combo component, wherein each judgement's "combo score" is derived from both the raw numerical value of the object and the current combo after the given judgement. In particular, this means that Score V2 is sensitive to the _order_ of judging objects, as if two objects with the same start time are judged using different ordering, they can end up having a different "combo score". The issue that this change is fixing is an instance of one such reordering. Upon inspection, it turned out that the simulated autoplay run, which is used to determine max possible score so that it can be standardised to 1 million again, was processing a slider repeat before a slider tail circle, while actual gameplay was processing the same slider repeat _after_ the slider tail circle. The cause of that behaviour is unfortunately due to `LegacyLastTick`. The sliders which cause the issue are extremely short. Stable had a behaviour, in which to provide leniency, slider tails were artificially offset back by 36ms. However, if the slider is not long enough to make this possible, the last tick is placed in the middle of the slider. If that slider also happens to have exactly 1 repeat, then this means that the last tick and the repeat have the same time instant. Because of the time equality, what begins to matter now is the _order_ of processing the elements of the drawable slider in the hierarchy. For the purposes of legacy skins, tail circles were moved below ticks in fce3eacd7de3254ce75619efaa2d15d59d564623 - but in this particular case, it means that the order of processing the slider elements is now inadvertently inverted, causing the entire debacle. While the fact that scoring depends on order of processing of visuals is suboptimal, there isn't a great way to address this without significant restructuring. Due to the structure of processing judgements currently in place, in which each judgement is processed independently from others by its corresponding drawable hit object, this is probably the best that can be done for the time being at least.
2023-06-10 17:02:29 +08:00
// proxied here so that the tail is drawn under repeats/ticks - legacy skins rely on this
tailContainer.CreateProxy(),
tickContainer = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
repeatContainer = new Container<DrawableSliderRepeat> { RelativeSizeAxes = Axes.Both },
Fix not being able to receive full score for extremely short sliders with repeats Closes #23862. Score V2 is a scoring algorithm, which aside from the raw numerical values of each judgement, incorporates a combo component, wherein each judgement's "combo score" is derived from both the raw numerical value of the object and the current combo after the given judgement. In particular, this means that Score V2 is sensitive to the _order_ of judging objects, as if two objects with the same start time are judged using different ordering, they can end up having a different "combo score". The issue that this change is fixing is an instance of one such reordering. Upon inspection, it turned out that the simulated autoplay run, which is used to determine max possible score so that it can be standardised to 1 million again, was processing a slider repeat before a slider tail circle, while actual gameplay was processing the same slider repeat _after_ the slider tail circle. The cause of that behaviour is unfortunately due to `LegacyLastTick`. The sliders which cause the issue are extremely short. Stable had a behaviour, in which to provide leniency, slider tails were artificially offset back by 36ms. However, if the slider is not long enough to make this possible, the last tick is placed in the middle of the slider. If that slider also happens to have exactly 1 repeat, then this means that the last tick and the repeat have the same time instant. Because of the time equality, what begins to matter now is the _order_ of processing the elements of the drawable slider in the hierarchy. For the purposes of legacy skins, tail circles were moved below ticks in fce3eacd7de3254ce75619efaa2d15d59d564623 - but in this particular case, it means that the order of processing the slider elements is now inadvertently inverted, causing the entire debacle. While the fact that scoring depends on order of processing of visuals is suboptimal, there isn't a great way to address this without significant restructuring. Due to the structure of processing judgements currently in place, in which each judgement is processed independently from others by its corresponding drawable hit object, this is probably the best that can be done for the time being at least.
2023-06-10 17:02:29 +08:00
// actual tail container is placed here to ensure that tail hitobjects are processed after ticks/repeats.
// this is required for the correct operation of Score V2.
tailContainer,
}
},
// slider head is not included in shake as it handles hit detection, and handles its own shaking.
headContainer = new Container<DrawableSliderHead> { RelativeSizeAxes = Axes.Both },
OverlayElementContainer = new Container { RelativeSizeAxes = Axes.Both, },
Ball,
slidingSample = new PausableSkinnableSound
{
Looping = true,
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
}
});
2018-04-13 17:19:50 +08:00
PositionBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
StackHeightBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
ScaleBindable.BindValueChanged(scale => Ball.Scale = new Vector2(scale.NewValue));
2018-04-13 17:19:50 +08:00
2019-07-22 13:45:25 +08:00
AccentColour.BindValueChanged(colour =>
{
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
}
protected override JudgementResult CreateResult(Judgement judgement) => new OsuSliderJudgementResult(HitObject, judgement);
protected override void OnApply()
{
base.OnApply();
// Ensure that the version will change after the upcoming BindTo().
pathVersion.Value = int.MaxValue;
PathVersion.BindTo(HitObject.Path.Version);
}
public override void Shake() => shakeContainer.Shake();
protected override void OnFree()
{
base.OnFree();
PathVersion.UnbindFrom(HitObject.Path.Version);
slidingSample?.ClearSamples();
2020-11-19 19:40:30 +08:00
}
2020-07-22 15:37:38 +08:00
protected override void LoadSamples()
{
// Note: base.LoadSamples() isn't called since the slider plays the tail's hitsounds for the time being.
Samples.Samples = HitObject.TailSamples.Cast<ISampleInfo>().ToArray();
slidingSample.Samples = HitObject.CreateSlidingSamples().Cast<ISampleInfo>().ToArray();
2020-07-22 15:37:38 +08:00
}
public override void StopAllSamples()
{
base.StopAllSamples();
slidingSample?.Stop();
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
2019-10-17 11:53:54 +08:00
switch (hitObject)
{
case DrawableSliderHead head:
headContainer.Child = head;
break;
case DrawableSliderTail tail:
tailContainer.Child = tail;
break;
case DrawableSliderTick tick:
tickContainer.Add(tick);
break;
case DrawableSliderRepeat repeat:
repeatContainer.Add(repeat);
break;
}
relativeAnchorPositionLayout.Invalidate();
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
2020-11-12 14:59:48 +08:00
headContainer.Clear(false);
tailContainer.Clear(false);
repeatContainer.Clear(false);
tickContainer.Clear(false);
OverlayElementContainer.Clear(false);
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case SliderTailCircle tail:
2020-11-05 12:51:46 +08:00
return new DrawableSliderTail(tail);
case SliderHeadCircle head:
2020-11-12 14:59:48 +08:00
return new DrawableSliderHead(head);
case SliderTick tick:
2020-11-12 14:59:48 +08:00
return new DrawableSliderTick(tick);
2020-03-19 13:42:02 +08:00
case SliderRepeat repeat:
2020-11-12 14:59:48 +08:00
return new DrawableSliderRepeat(repeat);
}
return base.CreateNestedHitObject(hitObject);
}
public readonly Bindable<bool> Tracking = new Bindable<bool>();
2018-04-13 17:19:50 +08:00
protected override void Update()
2016-11-17 20:29:35 +08:00
{
base.Update();
2018-04-13 17:19:50 +08:00
Tracking.Value = SliderInputManager.Tracking;
2018-04-13 17:19:50 +08:00
if (slidingSample != null)
{
if (Tracking.Value && Time.Current >= HitObject.StartTime)
{
// keep the sliding sample playing at the current tracking position
2024-01-25 09:06:15 +08:00
if (!slidingSample.RequestedPlaying)
slidingSample.Play();
slidingSample.Balance.Value = CalculateSamplePlaybackBalance(CalculateDrawableRelativePosition(Ball));
}
2024-01-25 09:06:15 +08:00
else if (slidingSample.IsPlaying || slidingSample.RequestedPlaying)
slidingSample.Stop();
}
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
2020-07-22 15:37:38 +08:00
2024-01-15 19:51:08 +08:00
// During slider path editing, the PlaySliderBody is scheduled to refresh once on Update.
2024-01-15 19:49:40 +08:00
// It is crucial to perform the code below in UpdateAfterChildren. This ensures that the SliderBody has the opportunity
// to update its Size and PathOffset beforehand, ensuring correct placement.
2020-11-05 12:51:46 +08:00
double completionProgress = Math.Clamp((Time.Current - HitObject.StartTime) / HitObject.Duration, 0, 1);
2018-04-13 17:19:50 +08:00
Ball.UpdateProgress(completionProgress);
SliderBody?.UpdateProgress(HeadCircle.IsHit ? completionProgress : 0);
foreach (DrawableSliderRepeat repeat in repeatContainer)
repeat.UpdateSnakingPosition(HitObject.Path.PositionAt(SliderBody?.SnakedStart ?? 0), HitObject.Path.PositionAt(SliderBody?.SnakedEnd ?? 0));
2018-04-13 17:19:50 +08:00
Size = SliderBody?.Size ?? Vector2.Zero;
OriginPosition = SliderBody?.PathOffset ?? Vector2.Zero;
2018-04-13 17:19:50 +08:00
if (!relativeAnchorPositionLayout.IsValid)
{
Vector2 pos = Vector2.Divide(OriginPosition, DrawSize);
foreach (var obj in NestedHitObjects)
obj.RelativeAnchorPosition = pos;
Ball.RelativeAnchorPosition = pos;
relativeAnchorPositionLayout.Validate();
}
}
2018-04-13 17:19:50 +08:00
public override void OnKilled()
{
base.OnKilled();
SliderBody?.RecyclePath();
}
protected override void CheckForResult(bool userTriggered, double timeOffset)
2016-11-29 20:40:24 +08:00
{
if (userTriggered || !TailCircle.Judged || Time.Current < HitObject.EndTime)
return;
if (HitObject.ClassicSliderBehaviour)
{
// Classic behaviour means a slider is judged proportionally to the number of nested hitobjects hit. This is the classic osu!stable scoring.
ApplyResult(static (r, hitObject) =>
{
int totalTicks = hitObject.NestedHitObjects.Count;
int hitTicks = hitObject.NestedHitObjects.Count(h => h.IsHit);
if (hitTicks == totalTicks)
r.Type = HitResult.Great;
else if (hitTicks == 0)
r.Type = HitResult.Miss;
else
{
double hitFraction = (double)hitTicks / totalTicks;
r.Type = hitFraction >= 0.5 ? HitResult.Ok : HitResult.Meh;
}
});
}
else
{
// If only the nested hitobjects are judged, then the slider's own judgement is ignored for scoring purposes.
// But the slider needs to still be judged with a reasonable hit/miss result for visual purposes (hit/miss transforms, etc).
ApplyResult(static (r, hitObject) =>
{
r.Type = hitObject.NestedHitObjects.Any(h => h.Result.IsHit) ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
2020-03-26 18:51:02 +08:00
}
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 if we stop using LastTick.
if (!TailCircle.SamplePlaysOnlyOnHit || TailCircle.IsHit)
2020-03-26 18:51:02 +08:00
base.PlaySamples();
2016-11-29 20:40:24 +08:00
}
2018-04-13 17:19:50 +08:00
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
Body.FadeInFromZero(HitObject.TimeFadeIn);
}
2020-11-04 15:19:07 +08:00
protected override void UpdateStartTimeStateTransforms()
{
2020-11-04 15:19:07 +08:00
base.UpdateStartTimeStateTransforms();
2019-09-13 17:49:21 +08:00
Ball.FadeIn();
Ball.ScaleTo(HitObject.Scale);
2020-11-04 15:19:07 +08:00
}
2018-04-13 17:19:50 +08:00
2020-11-04 15:19:07 +08:00
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
2018-04-13 17:19:50 +08:00
2022-10-19 04:43:31 +08:00
const float fade_out_time = 240;
2018-04-13 17:19:50 +08:00
2020-11-04 15:19:07 +08:00
switch (state)
{
case ArmedState.Hit:
if (HeadCircle.IsHit && SliderBody?.SnakingOut.Value == true)
Body.FadeOut(40); // short fade to allow for any body colour to smoothly disappear.
2020-11-04 15:19:07 +08:00
break;
}
2020-11-04 15:19:07 +08:00
2022-10-19 04:43:42 +08:00
this.FadeOut(fade_out_time).Expire();
}
2018-04-13 17:19:50 +08:00
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => SliderBody?.ReceivePositionalInputAt(screenSpacePos) ?? base.ReceivePositionalInputAt(screenSpacePos);
private partial class DefaultSliderBody : PlaySliderBody
{
}
#region FOR EDITOR USE ONLY, DO NOT USE FOR ANY OTHER PURPOSE
internal void SuppressHitAnimations()
{
UpdateState(ArmedState.Idle);
HeadCircle.SuppressHitAnimations();
TailCircle.SuppressHitAnimations();
}
internal void RestoreHitAnimations()
{
UpdateState(ArmedState.Hit, force: true);
HeadCircle.RestoreHitAnimations();
TailCircle.RestoreHitAnimations();
}
#endregion
}
}