2017-03-17 17:54:44 +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
|
|
|
|
|
|
2017-04-04 11:38:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2017-03-28 14:05:45 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
|
2017-04-04 11:38:55 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-09-06 16:02:13 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Judgements;
|
2017-03-17 17:54:44 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
2017-04-05 09:01:40 +08:00
|
|
|
|
public class DrawableSwell : DrawableTaikoHitObject<Swell>
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
2017-03-29 08:01:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when the swell has reached the hit target, i.e. when CurrentTime >= StartTime.
|
|
|
|
|
/// This is only ever invoked once.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event Action OnStart;
|
|
|
|
|
|
2017-03-31 10:20:04 +08:00
|
|
|
|
private const float target_ring_thick_border = 1.4f;
|
2017-03-28 14:05:45 +08:00
|
|
|
|
private const float target_ring_thin_border = 1f;
|
|
|
|
|
private const float target_ring_scale = 5f;
|
2017-03-31 10:20:04 +08:00
|
|
|
|
private const float inner_ring_alpha = 0.65f;
|
2017-03-28 14:05:45 +08:00
|
|
|
|
|
|
|
|
|
private readonly Container bodyContainer;
|
|
|
|
|
private readonly CircularContainer targetRing;
|
2017-03-31 10:20:04 +08:00
|
|
|
|
private readonly CircularContainer expandingRing;
|
2017-03-28 14:05:45 +08:00
|
|
|
|
|
2017-08-20 20:18:21 +08:00
|
|
|
|
private readonly TaikoAction[] rimActions = { TaikoAction.LeftRim, TaikoAction.RightRim };
|
|
|
|
|
private readonly TaikoAction[] centreActions = { TaikoAction.LeftCentre, TaikoAction.RightCentre };
|
|
|
|
|
private TaikoAction[] lastAction;
|
2017-03-29 14:59:12 +08:00
|
|
|
|
|
2017-03-17 17:54:44 +08:00
|
|
|
|
/// <summary>
|
2017-03-25 19:57:49 +08:00
|
|
|
|
/// The amount of times the user has hit this swell.
|
2017-03-17 17:54:44 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int userHits;
|
|
|
|
|
|
2017-03-29 08:01:40 +08:00
|
|
|
|
private bool hasStarted;
|
2017-03-31 10:20:04 +08:00
|
|
|
|
private readonly SwellSymbolPiece symbol;
|
2017-03-17 18:25:55 +08:00
|
|
|
|
|
2017-03-25 19:57:49 +08:00
|
|
|
|
public DrawableSwell(Swell swell)
|
|
|
|
|
: base(swell)
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
|
|
|
|
|
|
Add(bodyContainer = new Container
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Depth = 1,
|
|
|
|
|
Children = new Drawable[]
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
expandingRing = new CircularContainer
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
Name = "Expanding ring",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-07 21:46:21 +08:00
|
|
|
|
Blending = BlendingMode.Additive,
|
2017-08-03 12:24:13 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
new Box
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = inner_ring_alpha,
|
2017-03-28 14:05:45 +08:00
|
|
|
|
}
|
2017-08-03 12:24:13 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
targetRing = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Name = "Target ring (thick border)",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = target_ring_thick_border,
|
2017-09-07 21:46:21 +08:00
|
|
|
|
Blending = BlendingMode.Additive,
|
2017-08-03 12:24:13 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
new Box
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true
|
|
|
|
|
},
|
|
|
|
|
new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Name = "Target ring (thin border)",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = target_ring_thin_border,
|
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
Children = new[]
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
new Box
|
2017-03-28 14:05:45 +08:00
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true
|
2017-03-28 14:05:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-29 13:52:14 +08:00
|
|
|
|
}
|
2017-03-28 14:05:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-03 12:24:13 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MainPiece.Add(symbol = new SwellSymbolPiece());
|
2017-03-28 14:05:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2017-08-03 12:24:13 +08:00
|
|
|
|
MainPiece.AccentColour = colours.YellowDark;
|
2017-03-31 10:20:04 +08:00
|
|
|
|
expandingRing.Colour = colours.YellowLight;
|
2017-03-28 14:05:45 +08:00
|
|
|
|
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
|
2017-03-17 17:54:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 09:54:00 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
// We need to set this here because RelativeSizeAxes won't/can't set our size by default with a different RelativeChildSize
|
|
|
|
|
Width *= Parent.RelativeChildSize.X;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 16:02:13 +08:00
|
|
|
|
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
|
|
|
|
if (userTriggered)
|
|
|
|
|
{
|
|
|
|
|
userHits++;
|
|
|
|
|
|
2017-04-05 09:01:40 +08:00
|
|
|
|
var completion = (float)userHits / HitObject.RequiredHits;
|
2017-03-31 10:20:04 +08:00
|
|
|
|
|
2017-07-16 23:28:20 +08:00
|
|
|
|
expandingRing
|
|
|
|
|
.FadeTo(expandingRing.Alpha + MathHelper.Clamp(completion / 16, 0.1f, 0.6f), 50)
|
|
|
|
|
.Then()
|
2017-07-23 02:50:25 +08:00
|
|
|
|
.FadeTo(completion / 8, 2000, Easing.OutQuint);
|
2017-03-31 10:20:04 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
symbol.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint);
|
2017-03-31 10:20:04 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
|
2017-03-28 14:05:45 +08:00
|
|
|
|
|
2017-04-05 09:01:40 +08:00
|
|
|
|
if (userHits == HitObject.RequiredHits)
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(new TaikoJudgement { Result = HitResult.Great });
|
2017-03-17 17:54:44 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-06 16:02:13 +08:00
|
|
|
|
if (timeOffset < 0)
|
2017-03-17 17:54:44 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2017-03-29 12:33:52 +08:00
|
|
|
|
//TODO: THIS IS SHIT AND CAN'T EXIST POST-TAIKO WORLD CUP
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(userHits > HitObject.RequiredHits / 2
|
|
|
|
|
? new TaikoJudgement { Result = HitResult.Good }
|
|
|
|
|
: new TaikoJudgement { Result = HitResult.Miss });
|
2017-03-17 17:54:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 14:05:54 +08:00
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
2017-03-31 10:20:04 +08:00
|
|
|
|
const float preempt = 100;
|
2017-07-17 23:16:15 +08:00
|
|
|
|
const float out_transition_time = 300;
|
2017-03-29 12:33:52 +08:00
|
|
|
|
|
2017-07-17 23:16:15 +08:00
|
|
|
|
double untilStartTime = HitObject.StartTime - Time.Current;
|
2017-09-12 17:36:31 +08:00
|
|
|
|
double untilJudgement = untilStartTime + (Judgements.FirstOrDefault()?.TimeOffset ?? 0) + HitObject.Duration;
|
2017-03-29 12:33:52 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
targetRing.Delay(untilStartTime - preempt).ScaleTo(target_ring_scale, preempt * 4, Easing.OutQuint);
|
|
|
|
|
this.Delay(untilJudgement).FadeOut(out_transition_time, Easing.Out);
|
2017-03-31 10:20:04 +08:00
|
|
|
|
|
2017-03-28 14:05:45 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Hit:
|
2017-07-17 23:16:15 +08:00
|
|
|
|
bodyContainer.Delay(untilJudgement).ScaleTo(1.4f, out_transition_time);
|
2017-03-28 14:05:45 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-03-29 12:33:52 +08:00
|
|
|
|
|
|
|
|
|
Expire();
|
2017-03-24 14:05:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:01:18 +08:00
|
|
|
|
protected override void Update()
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
2017-08-08 15:01:18 +08:00
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
Size = BaseSize * Parent.RelativeChildSize;
|
|
|
|
|
|
2017-03-29 08:01:40 +08:00
|
|
|
|
// Make the swell stop at the hit target
|
2017-08-08 15:01:18 +08:00
|
|
|
|
X = (float)Math.Max(Time.Current, HitObject.StartTime);
|
2017-03-29 08:01:40 +08:00
|
|
|
|
|
2017-08-08 15:01:18 +08:00
|
|
|
|
double t = Math.Min(HitObject.StartTime, Time.Current);
|
2017-03-29 08:01:40 +08:00
|
|
|
|
if (t == HitObject.StartTime && !hasStarted)
|
|
|
|
|
{
|
|
|
|
|
OnStart?.Invoke();
|
|
|
|
|
hasStarted = true;
|
|
|
|
|
}
|
2017-03-17 17:54:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 20:18:21 +08:00
|
|
|
|
public override bool OnPressed(TaikoAction action)
|
2017-03-17 17:54:44 +08:00
|
|
|
|
{
|
2017-03-29 15:02:12 +08:00
|
|
|
|
// Don't handle keys before the swell starts
|
|
|
|
|
if (Time.Current < HitObject.StartTime)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-03-29 14:59:12 +08:00
|
|
|
|
// Find the keyset which this key corresponds to
|
2017-08-20 20:18:21 +08:00
|
|
|
|
var keySet = rimActions.Contains(action) ? rimActions : centreActions;
|
2017-03-29 14:59:12 +08:00
|
|
|
|
|
|
|
|
|
// Ensure alternating keysets
|
2017-08-20 20:18:21 +08:00
|
|
|
|
if (keySet == lastAction)
|
2017-03-29 14:59:12 +08:00
|
|
|
|
return false;
|
2017-08-20 20:18:21 +08:00
|
|
|
|
lastAction = keySet;
|
2017-03-29 14:59:12 +08:00
|
|
|
|
|
2017-03-17 17:54:44 +08:00
|
|
|
|
UpdateJudgement(true);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|