1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 10:17:38 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs

236 lines
8.1 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
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;
using osu.Framework.Graphics.Sprites;
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;
public readonly SpinnerDisc Disc;
public readonly SpinnerTicks Ticks;
2019-12-18 08:04:37 +08:00
public readonly SpinnerSpmCounter SpmCounter;
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;
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[]
{
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
{
Alpha = 0.6f,
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
}
};
2018-11-09 12:58:46 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
normalColour = baseColour;
Background.AccentColour = normalColour;
completeColour = colours.YellowLight.Opacity(0.75f);
Disc.AccentColour = fillColour;
circle.Colour = colours.BlueDark;
glow.Colour = colours.BlueDark;
2018-10-29 17:23:23 +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
}
public float Progress => Math.Clamp(Disc.CumulativeRotation / 360 / Spinner.SpinsRequired, 0, 1);
2018-04-13 17:19:50 +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;
const float duration = 200;
Disc.FadeAccent(completeColour, duration);
Background.FadeAccent(completeColour, duration);
Background.FadeOut(duration);
circle.FadeColour(completeColour, duration);
glow.FadeColour(completeColour, duration);
}
if (userTriggered || Time.Current < Spinner.EndTime)
return;
ApplyResult(r =>
2018-04-13 17:19:50 +08:00
{
if (Progress >= 1)
r.Type = HitResult.Great;
2018-04-13 17:19:50 +08:00
else if (Progress > .9)
r.Type = HitResult.Good;
2018-04-13 17:19:50 +08:00
else if (Progress > .75)
r.Type = HitResult.Meh;
2018-04-13 17:19:50 +08:00
else if (Time.Current >= Spinner.EndTime)
r.Type = HitResult.Miss;
});
2018-04-13 17:19:50 +08:00
}
protected override void Update()
{
base.Update();
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();
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;
SpmCounter.SetRotation(Disc.CumulativeRotation);
2018-04-13 17:19:50 +08:00
float relativeCircleScale = Spinner.Scale * circle.DrawHeight / mainContainer.DrawHeight;
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
}
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
circleContainer.ScaleTo(Spinner.Scale * 0.3f);
circleContainer.ScaleTo(Spinner.Scale, HitObject.TimePreempt / 1.4f, Easing.OutQuint);
mainContainer
.ScaleTo(0)
.ScaleTo(Spinner.Scale * circle.DrawHeight / DrawHeight * 1.4f, HitObject.TimePreempt - 150, Easing.OutQuint)
.Then()
.ScaleTo(1, 500, Easing.OutQuint);
}
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);
2018-04-13 17:19:50 +08:00
var sequence = this.Delay(Spinner.Duration).FadeOut(160);
switch (state)
{
case ArmedState.Hit:
sequence.ScaleTo(Scale * 1.2f, 320, Easing.Out);
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case ArmedState.Miss:
sequence.ScaleTo(Scale * 0.8f, 320, Easing.In);
break;
}
}
}
}