mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 10:03:05 +08:00
Merge pull request #9724 from peppy/spinner-spinning
This commit is contained in:
commit
2460488255
@ -70,6 +70,58 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bindable<bool> isSpinning;
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
isSpinning = RotationTracker.IsSpinning.GetBoundCopy();
|
||||||
|
isSpinning.BindValueChanged(updateSpinningSample);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SkinnableSound spinningSample;
|
||||||
|
|
||||||
|
private const float minimum_volume = 0.0001f;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Volume = { Value = minimum_volume },
|
||||||
|
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
|
||||||
|
{
|
||||||
|
spinningSample?.VolumeTo(minimum_volume, 200).Finally(_ => spinningSample.Stop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
base.AddNestedHitObject(hitObject);
|
base.AddNestedHitObject(hitObject);
|
||||||
@ -88,6 +140,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
|
|
||||||
using (BeginDelayedSequence(Spinner.Duration, true))
|
using (BeginDelayedSequence(Spinner.Duration, true))
|
||||||
this.FadeOut(160);
|
this.FadeOut(160);
|
||||||
|
|
||||||
|
// skin change does a rewind of transforms, which will stop the spinning sound from playing if it's currently in playback.
|
||||||
|
isSpinning?.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ClearNestedHitObjects()
|
protected override void ClearNestedHitObjects()
|
||||||
@ -151,8 +206,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (HandleUserInput)
|
if (HandleUserInput)
|
||||||
RotationTracker.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
|
RotationTracker.Tracking = !Result.HasResult && (OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
||||||
|
|
||||||
|
if (spinningSample != null)
|
||||||
|
// todo: implement SpinnerFrequencyModulate
|
||||||
|
spinningSample.Frequency.Value = 0.5f + Progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
|
@ -43,6 +43,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
/// </example>
|
/// </example>
|
||||||
public float CumulativeRotation { get; private set; }
|
public float CumulativeRotation { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the spinning is spinning at a reasonable speed to be considered visually spinning.
|
||||||
|
/// </summary>
|
||||||
|
public readonly BindableBool IsSpinning = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether currently in the correct time range to allow spinning.
|
/// Whether currently in the correct time range to allow spinning.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -73,7 +78,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
|
|
||||||
lastAngle = thisAngle;
|
lastAngle = thisAngle;
|
||||||
|
|
||||||
Rotation = (float)Interpolation.Lerp(Rotation, currentRotation / 2, Math.Clamp(Math.Abs(Time.Elapsed) / 40, 0, 1));
|
IsSpinning.Value = isSpinnableTime && Math.Abs(currentRotation / 2 - Rotation) > 5f;
|
||||||
|
|
||||||
|
Rotation = (float)Interpolation.Damp(Rotation, currentRotation / 2, 0.99, Math.Abs(Time.Elapsed));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user