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.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-12-12 20:15:16 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-07-05 06:25:01 +08:00
|
|
|
|
using osu.Framework.Utils;
|
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;
|
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;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public readonly SpinnerDisc Disc;
|
|
|
|
|
public readonly SpinnerTicks Ticks;
|
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
|
|
|
|
|
|
|
|
|
private readonly Container mainContainer;
|
|
|
|
|
|
|
|
|
|
public readonly SpinnerBackground Background;
|
|
|
|
|
private readonly Container circleContainer;
|
|
|
|
|
private readonly CirclePiece circle;
|
|
|
|
|
private readonly GlowPiece glow;
|
|
|
|
|
|
|
|
|
|
private readonly SpriteIcon symbol;
|
|
|
|
|
|
2020-03-11 09:18:41 +08:00
|
|
|
|
private readonly Color4 baseColour = Color4Extensions.FromHex(@"002c3c");
|
|
|
|
|
private readonly Color4 fillColour = Color4Extensions.FromHex(@"005b7c");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private Color4 normalColour;
|
|
|
|
|
private Color4 completeColour;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// we are slightly bigger than our parent, to clip the top and bottom of the circle
|
|
|
|
|
Height = 1.3f;
|
|
|
|
|
|
|
|
|
|
Spinner = s;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2019-08-21 02:50:49 +08:00
|
|
|
|
ticks = new Container<DrawableSpinnerTick>(),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
circleContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
glow = new GlowPiece(),
|
|
|
|
|
circle = new CirclePiece
|
|
|
|
|
{
|
|
|
|
|
Position = Vector2.Zero,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
new RingPiece(),
|
|
|
|
|
symbol = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(48),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.Asterisk,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Shadow = false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mainContainer = new AspectContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2018-04-20 17:19:17 +08:00
|
|
|
|
Children = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Background = new SpinnerBackground
|
|
|
|
|
{
|
2020-07-20 16:48:35 +08:00
|
|
|
|
Disc =
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0f,
|
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
Disc = new SpinnerDisc(Spinner)
|
|
|
|
|
{
|
|
|
|
|
Scale = Vector2.Zero,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
circleContainer.CreateProxy(),
|
|
|
|
|
Ticks = new SpinnerTicks
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
normalColour = baseColour;
|
2020-07-20 16:48:35 +08:00
|
|
|
|
completeColour = colours.YellowLight;
|
2018-11-09 12:58:46 +08:00
|
|
|
|
|
|
|
|
|
Background.AccentColour = normalColour;
|
2020-07-20 16:48:35 +08:00
|
|
|
|
Ticks.AccentColour = normalColour;
|
2018-11-09 12:58:46 +08:00
|
|
|
|
|
|
|
|
|
Disc.AccentColour = fillColour;
|
|
|
|
|
circle.Colour = colours.BlueDark;
|
|
|
|
|
glow.Colour = colours.BlueDark;
|
2018-10-29 17:23:23 +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);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 11:01:00 +08:00
|
|
|
|
public float Progress => Math.Clamp(Disc.CumulativeRotation / 360 / Spinner.SpinsRequired, 0, 1);
|
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;
|
|
|
|
|
|
|
|
|
|
if (Progress >= 1 && !Disc.Complete)
|
|
|
|
|
{
|
|
|
|
|
Disc.Complete = true;
|
2020-07-20 16:22:17 +08:00
|
|
|
|
transformFillColour(completeColour, 200);
|
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))
|
|
|
|
|
tick.TriggerResult(HitResult.Miss);
|
|
|
|
|
|
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-03-29 13:31:03 +08:00
|
|
|
|
if (HandleUserInput)
|
|
|
|
|
Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
2020-03-29 13:31:03 +08:00
|
|
|
|
if (!SpmCounter.IsPresent && Disc.Tracking)
|
|
|
|
|
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
circle.Rotation = Disc.Rotation;
|
|
|
|
|
Ticks.Rotation = Disc.Rotation;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
|
2020-07-09 11:01:00 +08:00
|
|
|
|
SpmCounter.SetRotation(Disc.CumulativeRotation);
|
2020-07-21 18:03:17 +08:00
|
|
|
|
|
|
|
|
|
updateBonusScore();
|
2019-08-21 02:50:49 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
float relativeCircleScale = Spinner.Scale * circle.DrawHeight / mainContainer.DrawHeight;
|
2020-07-05 06:25:01 +08:00
|
|
|
|
float targetScale = relativeCircleScale + (1 - relativeCircleScale) * Progress;
|
|
|
|
|
Disc.Scale = new Vector2((float)Interpolation.Lerp(Disc.Scale.X, targetScale, Math.Clamp(Math.Abs(Time.Elapsed) / 100, 0, 1)));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-09 02:56:47 +08:00
|
|
|
|
symbol.Rotation = (float)Interpolation.Lerp(symbol.Rotation, Disc.Rotation / 2, Math.Clamp(Math.Abs(Time.Elapsed) / 40, 0, 1));
|
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;
|
|
|
|
|
|
|
|
|
|
int spins = (int)(Disc.CumulativeRotation / 360);
|
|
|
|
|
|
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:21:30 +08:00
|
|
|
|
tick.TriggerResult(HitResult.Great);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:33:12 +08:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-07-22 14:33:12 +08:00
|
|
|
|
base.UpdateInitialTransforms();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-20 14:19:17 +08:00
|
|
|
|
circleContainer.ScaleTo(0);
|
|
|
|
|
mainContainer.ScaleTo(0);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-20 14:19:17 +08:00
|
|
|
|
using (BeginDelayedSequence(HitObject.TimePreempt / 2, true))
|
|
|
|
|
{
|
2020-07-20 16:22:17 +08:00
|
|
|
|
float phaseOneScale = Spinner.Scale * 0.7f;
|
2020-07-20 14:19:17 +08:00
|
|
|
|
|
2020-07-20 16:22:17 +08:00
|
|
|
|
circleContainer.ScaleTo(phaseOneScale, HitObject.TimePreempt / 4, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-20 14:19:17 +08:00
|
|
|
|
mainContainer
|
2020-07-20 16:52:59 +08:00
|
|
|
|
.ScaleTo(phaseOneScale * circle.DrawHeight / DrawHeight * 1.6f, HitObject.TimePreempt / 4, Easing.OutQuint)
|
2020-07-20 16:22:17 +08:00
|
|
|
|
.RotateTo((float)(25 * Spinner.Duration / 2000), HitObject.TimePreempt + Spinner.Duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-20 14:19:17 +08:00
|
|
|
|
using (BeginDelayedSequence(HitObject.TimePreempt / 2, true))
|
|
|
|
|
{
|
2020-07-20 16:22:17 +08:00
|
|
|
|
circleContainer.ScaleTo(Spinner.Scale, 400, Easing.OutQuint);
|
|
|
|
|
mainContainer.ScaleTo(1, 400, Easing.OutQuint);
|
2020-07-20 14:19:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
2020-07-20 16:22:17 +08:00
|
|
|
|
using (BeginDelayedSequence(Spinner.Duration, true))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-07-20 16:22:17 +08:00
|
|
|
|
this.FadeOut(160);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2020-07-20 16:22:17 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
transformFillColour(completeColour, 0);
|
|
|
|
|
this.ScaleTo(Scale * 1.2f, 320, Easing.Out);
|
|
|
|
|
mainContainer.RotateTo(mainContainer.Rotation + 180, 320);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ArmedState.Miss:
|
|
|
|
|
this.ScaleTo(Scale * 0.8f, 320, Easing.In);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-20 16:22:17 +08:00
|
|
|
|
|
|
|
|
|
private void transformFillColour(Colour4 colour, double duration)
|
|
|
|
|
{
|
|
|
|
|
Disc.FadeAccent(colour, duration);
|
|
|
|
|
|
|
|
|
|
Background.FadeAccent(colour.Darken(1), duration);
|
2020-07-20 16:48:35 +08:00
|
|
|
|
Ticks.FadeAccent(colour, duration);
|
2020-07-20 16:22:17 +08:00
|
|
|
|
|
|
|
|
|
circle.FadeColour(colour, duration);
|
|
|
|
|
glow.FadeColour(colour, duration);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|