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;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-06 13:43:39 +08:00
|
|
|
|
using osu.Framework.Audio;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-07-29 19:01:01 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2019-12-12 20:15:16 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-07-29 19:01:01 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
2020-08-16 01:12:06 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-09-06 14:24:00 +08:00
|
|
|
|
using osu.Game.Screens.Ranking;
|
2020-07-29 15:37:23 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2020-07-29 19:01:01 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSpinner : DrawableOsuHitObject
|
|
|
|
|
{
|
|
|
|
|
protected readonly Spinner Spinner;
|
|
|
|
|
|
2019-08-21 02:50:49 +08:00
|
|
|
|
private readonly Container<DrawableSpinnerTick> ticks;
|
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
|
public readonly SpinnerRotationTracker RotationTracker;
|
2019-12-18 08:04:37 +08:00
|
|
|
|
public readonly SpinnerSpmCounter SpmCounter;
|
2020-07-21 18:03:17 +08:00
|
|
|
|
private readonly SpinnerBonusDisplay bonusDisplay;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
|
|
|
|
|
|
2020-08-16 01:12:06 +08:00
|
|
|
|
private bool spinnerFrequencyModulate;
|
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
|
public DrawableSpinner(Spinner s)
|
|
|
|
|
: base(s)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
Position = s.Position;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Spinner = s;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2019-08-21 02:50:49 +08:00
|
|
|
|
ticks = new Container<DrawableSpinnerTick>(),
|
2020-07-29 19:01:01 +08:00
|
|
|
|
new AspectContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2020-07-29 19:01:01 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-07-29 21:31:18 +08:00
|
|
|
|
new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SpinnerBody), _ => new DefaultSpinnerDisc()),
|
2020-07-29 19:01:01 +08:00
|
|
|
|
RotationTracker = new SpinnerRotationTracker(Spinner)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-12-18 08:04:37 +08:00
|
|
|
|
SpmCounter = new SpinnerSpmCounter
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Y = 120,
|
|
|
|
|
Alpha = 0
|
2019-08-21 02:50:49 +08:00
|
|
|
|
},
|
2020-07-21 18:03:17 +08:00
|
|
|
|
bonusDisplay = new SpinnerBonusDisplay
|
2019-08-21 02:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Y = -120,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2019-12-12 20:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 18:34:59 +08:00
|
|
|
|
private Bindable<bool> isSpinning;
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
isSpinning = RotationTracker.IsSpinning.GetBoundCopy();
|
|
|
|
|
isSpinning.BindValueChanged(updateSpinningSample);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SkinnableSound spinningSample;
|
|
|
|
|
|
|
|
|
|
protected override void LoadSamples()
|
|
|
|
|
{
|
|
|
|
|
base.LoadSamples();
|
|
|
|
|
|
|
|
|
|
spinningSample?.Expire();
|
|
|
|
|
spinningSample = null;
|
|
|
|
|
|
|
|
|
|
var firstSample = HitObject.Samples.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (firstSample != null)
|
|
|
|
|
{
|
|
|
|
|
var clone = HitObject.SampleControlPoint.ApplyTo(firstSample);
|
|
|
|
|
clone.Name = "spinnerspin";
|
|
|
|
|
|
|
|
|
|
AddInternal(spinningSample = new SkinnableSound(clone)
|
|
|
|
|
{
|
2020-08-06 18:16:26 +08:00
|
|
|
|
Volume = { Value = 0 },
|
2020-07-30 18:34:59 +08:00
|
|
|
|
Looping = true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateSpinningSample(ValueChangedEvent<bool> tracking)
|
|
|
|
|
{
|
|
|
|
|
// note that samples will not start playing if exiting a seek operation in the middle of a spinner.
|
|
|
|
|
// may be something we want to address at a later point, but not so easy to make happen right now
|
|
|
|
|
// (SkinnableSound would need to expose whether the sample is already playing and this logic would need to run in Update).
|
|
|
|
|
if (tracking.NewValue && ShouldPlaySamples)
|
|
|
|
|
{
|
|
|
|
|
spinningSample?.Play();
|
|
|
|
|
spinningSample?.VolumeTo(1, 200);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-06 18:16:26 +08:00
|
|
|
|
spinningSample?.VolumeTo(0, 200).Finally(_ => spinningSample.Stop());
|
2020-07-30 18:34:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 20:15:16 +08:00
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
base.AddNestedHitObject(hitObject);
|
2019-08-21 02:50:49 +08:00
|
|
|
|
|
2019-12-12 20:15:16 +08:00
|
|
|
|
switch (hitObject)
|
2019-08-21 02:50:49 +08:00
|
|
|
|
{
|
2019-12-12 20:15:16 +08:00
|
|
|
|
case DrawableSpinnerTick tick:
|
|
|
|
|
ticks.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-21 02:50:49 +08:00
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateStateTransforms(state);
|
|
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(Spinner.Duration, true))
|
|
|
|
|
this.FadeOut(160);
|
2020-07-30 18:34:59 +08:00
|
|
|
|
|
|
|
|
|
// skin change does a rewind of transforms, which will stop the spinning sound from playing if it's currently in playback.
|
|
|
|
|
isSpinning?.TriggerChange();
|
2020-07-29 19:01:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 20:15:16 +08:00
|
|
|
|
protected override void ClearNestedHitObjects()
|
|
|
|
|
{
|
|
|
|
|
base.ClearNestedHitObjects();
|
|
|
|
|
ticks.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
2020-07-21 17:22:37 +08:00
|
|
|
|
case SpinnerBonusTick bonusTick:
|
|
|
|
|
return new DrawableSpinnerBonusTick(bonusTick);
|
|
|
|
|
|
2019-12-12 20:15:16 +08:00
|
|
|
|
case SpinnerTick tick:
|
|
|
|
|
return new DrawableSpinnerTick(tick);
|
2019-08-21 02:50:49 +08:00
|
|
|
|
}
|
2019-12-12 20:15:16 +08:00
|
|
|
|
|
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
2018-11-09 12:58:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-08-16 01:12:06 +08:00
|
|
|
|
private void load(OsuColour colours, ISkinSource skin)
|
2018-11-09 12:58:46 +08:00
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
|
positionBindable.BindValueChanged(pos => Position = pos.NewValue);
|
2018-11-09 12:58:46 +08:00
|
|
|
|
positionBindable.BindTo(HitObject.PositionBindable);
|
2020-08-16 01:51:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ApplySkin(ISkinSource skin, bool allowFallback)
|
|
|
|
|
{
|
2020-08-16 01:12:06 +08:00
|
|
|
|
spinnerFrequencyModulate = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.SpinnerFrequencyModulate)?.Value ?? true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 11:55:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The completion progress of this spinner from 0..1 (clamped).
|
|
|
|
|
/// </summary>
|
2020-08-05 17:44:34 +08:00
|
|
|
|
public float Progress
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Spinner.SpinsRequired == 0)
|
|
|
|
|
// some spinners are so short they can't require an integer spin count.
|
|
|
|
|
// these become implicitly hit.
|
|
|
|
|
return 1;
|
|
|
|
|
|
2020-08-11 04:17:47 +08:00
|
|
|
|
return Math.Clamp(RotationTracker.RateAdjustedRotation / 360 / Spinner.SpinsRequired, 0, 1);
|
2020-08-05 17:44:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +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
|
|
|
|
{
|
|
|
|
|
if (Time.Current < HitObject.StartTime) return;
|
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
|
RotationTracker.Complete.Value = Progress >= 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-01 20:46:22 +08:00
|
|
|
|
if (userTriggered || Time.Current < Spinner.EndTime)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-21 18:03:17 +08:00
|
|
|
|
// Trigger a miss result for remaining ticks to avoid infinite gameplay.
|
|
|
|
|
foreach (var tick in ticks.Where(t => !t.IsHit))
|
2020-07-21 18:48:44 +08:00
|
|
|
|
tick.TriggerResult(false);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (Progress >= 1)
|
2018-08-02 19:36:38 +08:00
|
|
|
|
r.Type = HitResult.Great;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
else if (Progress > .9)
|
2018-08-02 19:36:38 +08:00
|
|
|
|
r.Type = HitResult.Good;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
else if (Progress > .75)
|
2018-08-02 19:36:38 +08:00
|
|
|
|
r.Type = HitResult.Meh;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
else if (Time.Current >= Spinner.EndTime)
|
2018-08-02 19:36:38 +08:00
|
|
|
|
r.Type = HitResult.Miss;
|
2018-08-01 20:46:22 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2020-07-30 18:34:59 +08:00
|
|
|
|
|
2020-03-29 13:31:03 +08:00
|
|
|
|
if (HandleUserInput)
|
2020-07-30 18:34:59 +08:00
|
|
|
|
RotationTracker.Tracking = !Result.HasResult && (OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
|
|
|
|
|
|
|
|
|
if (spinningSample != null)
|
2020-08-16 01:12:06 +08:00
|
|
|
|
spinningSample.Frequency.Value = spinnerFrequencyModulate ? 0.5f + Progress : 0.5f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
|
if (!SpmCounter.IsPresent && RotationTracker.Tracking)
|
2020-03-29 13:31:03 +08:00
|
|
|
|
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
2020-08-11 04:17:47 +08:00
|
|
|
|
SpmCounter.SetRotation(RotationTracker.RateAdjustedRotation);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
|
|
|
|
updateBonusScore();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-21 18:03:17 +08:00
|
|
|
|
private int wholeSpins;
|
|
|
|
|
|
|
|
|
|
private void updateBonusScore()
|
|
|
|
|
{
|
|
|
|
|
if (ticks.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-08-11 04:17:47 +08:00
|
|
|
|
int spins = (int)(RotationTracker.RateAdjustedRotation / 360);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
2020-07-21 18:21:30 +08:00
|
|
|
|
if (spins < wholeSpins)
|
2020-07-21 18:03:17 +08:00
|
|
|
|
{
|
2020-07-21 18:21:30 +08:00
|
|
|
|
// rewinding, silently handle
|
|
|
|
|
wholeSpins = spins;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
2020-07-21 18:21:30 +08:00
|
|
|
|
while (wholeSpins != spins)
|
|
|
|
|
{
|
|
|
|
|
var tick = ticks.FirstOrDefault(t => !t.IsHit);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
2020-07-21 18:21:30 +08:00
|
|
|
|
// tick may be null if we've hit the spin limit.
|
|
|
|
|
if (tick != null)
|
2020-07-21 18:03:17 +08:00
|
|
|
|
{
|
2020-07-21 18:48:44 +08:00
|
|
|
|
tick.TriggerResult(true);
|
2020-07-21 18:21:30 +08:00
|
|
|
|
if (tick is DrawableSpinnerBonusTick)
|
|
|
|
|
bonusDisplay.SetBonusCount(spins - Spinner.SpinsRequired);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
}
|
2020-07-21 18:21:30 +08:00
|
|
|
|
|
|
|
|
|
wholeSpins++;
|
2020-07-21 18:03:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|