2017-02-14 17:55:54 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Modes.Objects.Drawables;
|
|
|
|
|
using osu.Game.Modes.Osu.Objects.Drawables.Pieces;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-04-18 11:19:39 +08:00
|
|
|
|
using osu.Game.Modes.Osu.UI;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Modes.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSpinner : DrawableOsuHitObject
|
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Spinner spinner;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly SpinnerDisc disc;
|
|
|
|
|
private readonly SpinnerBackground background;
|
|
|
|
|
private readonly Container circleContainer;
|
|
|
|
|
private readonly DrawableHitCircle circle;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
public DrawableSpinner(Spinner s) : base(s)
|
|
|
|
|
{
|
2017-03-16 16:38:36 +08:00
|
|
|
|
AlwaysReceiveInput = true;
|
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
Position = s.Position;
|
|
|
|
|
|
|
|
|
|
//take up full playfield.
|
2017-04-18 11:19:39 +08:00
|
|
|
|
Size = OsuPlayfield.BASE_SIZE;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
spinner = s;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new SpinnerBackground
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
DiscColour = Color4.Black
|
|
|
|
|
},
|
|
|
|
|
disc = new SpinnerDisc
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-03-23 14:37:16 +08:00
|
|
|
|
DiscColour = AccentColour
|
2017-02-14 17:55:54 +08:00
|
|
|
|
},
|
2017-02-15 22:24:08 +08:00
|
|
|
|
circleContainer = new Container
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-02-15 22:24:08 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-02-14 17:55:54 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2017-02-15 22:24:08 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new []
|
|
|
|
|
{
|
|
|
|
|
circle = new DrawableHitCircle(s)
|
|
|
|
|
{
|
|
|
|
|
Interactive = false,
|
|
|
|
|
Position = Vector2.Zero,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
background.Scale = scaleToCircle;
|
|
|
|
|
disc.Scale = scaleToCircle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void CheckJudgement(bool userTriggered)
|
|
|
|
|
{
|
|
|
|
|
if (Time.Current < HitObject.StartTime) return;
|
|
|
|
|
|
|
|
|
|
disc.ScaleTo(Interpolation.ValueAt(Math.Sqrt(Progress), scaleToCircle, Vector2.One, 0, 1), 100);
|
|
|
|
|
|
2017-02-15 22:24:08 +08:00
|
|
|
|
if (Progress >= 1)
|
|
|
|
|
disc.Complete = true;
|
|
|
|
|
|
2017-03-13 18:15:25 +08:00
|
|
|
|
if (!userTriggered && Time.Current >= spinner.EndTime)
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
|
|
|
|
if (Progress >= 1)
|
|
|
|
|
{
|
2017-03-15 17:58:41 +08:00
|
|
|
|
Judgement.Score = OsuScoreResult.Hit300;
|
|
|
|
|
Judgement.Result = HitResult.Hit;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Progress > .9)
|
|
|
|
|
{
|
2017-03-15 17:58:41 +08:00
|
|
|
|
Judgement.Score = OsuScoreResult.Hit100;
|
|
|
|
|
Judgement.Result = HitResult.Hit;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
else if (Progress > .75)
|
|
|
|
|
{
|
2017-03-15 17:58:41 +08:00
|
|
|
|
Judgement.Score = OsuScoreResult.Hit50;
|
|
|
|
|
Judgement.Result = HitResult.Hit;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-15 17:58:41 +08:00
|
|
|
|
Judgement.Score = OsuScoreResult.Miss;
|
2017-03-13 18:15:25 +08:00
|
|
|
|
if (Time.Current >= spinner.EndTime)
|
2017-03-15 17:58:41 +08:00
|
|
|
|
Judgement.Result = HitResult.Miss;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private Vector2 scaleToCircle => circle.Scale * circle.DrawWidth / DrawWidth * 0.95f;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
2017-03-23 12:52:38 +08:00
|
|
|
|
private const float spins_per_minute_needed = 100 + 5 * 15; //TODO: read per-map OD and place it on the 5
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
2017-03-23 12:52:38 +08:00
|
|
|
|
private float rotationsNeeded => (float)(spins_per_minute_needed * (spinner.EndTime - spinner.StartTime) / 60000f);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
public float Progress => MathHelper.Clamp(disc.RotationAbsolute / 360 / rotationsNeeded, 0, 1);
|
|
|
|
|
|
|
|
|
|
protected override void UpdatePreemptState()
|
|
|
|
|
{
|
|
|
|
|
base.UpdatePreemptState();
|
|
|
|
|
|
2017-02-15 22:24:08 +08:00
|
|
|
|
circleContainer.ScaleTo(1, 400, EasingTypes.OutElastic);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
2017-02-22 17:08:31 +08:00
|
|
|
|
background.Delay(TIME_PREEMPT - 500);
|
|
|
|
|
|
|
|
|
|
background.ScaleTo(scaleToCircle * 1.2f, 400, EasingTypes.OutQuint);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
background.FadeIn(200);
|
2017-02-22 17:08:31 +08:00
|
|
|
|
|
|
|
|
|
background.Delay(400);
|
|
|
|
|
background.ScaleTo(1, 250, EasingTypes.OutQuint);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
disc.Delay(TIME_PREEMPT - 50);
|
|
|
|
|
disc.FadeIn(200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
2017-03-13 18:15:25 +08:00
|
|
|
|
Delay(spinner.Duration, true);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
FadeOut(160);
|
2017-02-15 22:24:08 +08:00
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
ScaleTo(Scale * 1.2f, 320, EasingTypes.Out);
|
2017-03-17 14:30:19 +08:00
|
|
|
|
Expire();
|
2017-02-14 17:55:54 +08:00
|
|
|
|
break;
|
|
|
|
|
case ArmedState.Miss:
|
|
|
|
|
ScaleTo(Scale * 0.8f, 320, EasingTypes.In);
|
2017-03-17 14:30:19 +08:00
|
|
|
|
Expire();
|
2017-02-14 17:55:54 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|