1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 16:13:21 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs

243 lines
8.9 KiB
C#
Raw Normal View History

// 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.Judgements;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
2017-04-04 11:38:55 +08:00
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics.Shapes;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
public class DrawableSwell : DrawableTaikoHitObject<Swell>
{
/// <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
private readonly CirclePiece circlePiece;
private readonly Key[] rimKeys = { Key.D, Key.K };
private readonly Key[] centreKeys = { Key.F, Key.J };
private Key[] lastKeySet;
/// <summary>
2017-03-25 19:57:49 +08:00
/// The amount of times the user has hit this swell.
/// </summary>
private int userHits;
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-04-04 11:38:55 +08:00
Children = new Drawable[]
2017-03-28 14:05:45 +08:00
{
bodyContainer = new Container
{
AutoSizeAxes = Axes.Both,
2017-04-04 11:38:55 +08:00
Children = new Drawable[]
2017-03-28 14:05:45 +08:00
{
2017-03-31 10:20:04 +08:00
expandingRing = new CircularContainer
2017-03-28 14:05:45 +08:00
{
2017-03-31 10:20:04 +08:00
Name = "Expanding ring",
2017-03-28 14:05:45 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-03-31 10:20:04 +08:00
Alpha = 0,
Size = new Vector2(TaikoHitObject.DEFAULT_CIRCLE_DIAMETER),
2017-03-31 10:20:04 +08:00
BlendingMode = BlendingMode.Additive,
2017-03-28 14:05:45 +08:00
Masking = true,
2017-06-08 15:27:35 +08:00
Children = new[]
2017-03-28 14:05:45 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = inner_ring_alpha,
}
}
},
targetRing = new CircularContainer
{
Name = "Target ring (thick border)",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(TaikoHitObject.DEFAULT_CIRCLE_DIAMETER),
2017-03-28 14:05:45 +08:00
Masking = true,
BorderThickness = target_ring_thick_border,
2017-03-31 10:20:04 +08:00
BlendingMode = BlendingMode.Additive,
2017-04-04 11:38:55 +08:00
Children = new Drawable[]
2017-03-28 14:05:45 +08:00
{
new Box
{
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[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
}
}
},
circlePiece = new CirclePiece
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-06-08 15:27:35 +08:00
Children = new[]
{
2017-03-31 10:20:04 +08:00
symbol = new SwellSymbolPiece()
}
}
2017-03-28 14:05:45 +08:00
}
}
};
2017-04-03 13:40:12 +08:00
circlePiece.KiaiMode = HitObject.Kiai;
2017-03-28 14:05:45 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
circlePiece.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);
}
protected override void CheckJudgement(bool userTriggered)
{
if (userTriggered)
{
userHits++;
var completion = (float)userHits / HitObject.RequiredHits;
2017-03-31 10:20:04 +08:00
expandingRing.FadeTo(expandingRing.Alpha + MathHelper.Clamp(completion / 16, 0.1f, 0.6f), 50);
using (expandingRing.BeginDelayedSequence(50))
expandingRing.FadeTo(completion / 8, 2000, EasingTypes.OutQuint);
2017-03-31 10:20:04 +08:00
symbol.RotateTo((float)(completion * HitObject.Duration / 8), 4000, EasingTypes.OutQuint);
2017-03-31 10:20:04 +08:00
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, EasingTypes.OutQuint);
2017-03-28 14:05:45 +08:00
if (userHits == HitObject.RequiredHits)
{
Judgement.Result = HitResult.Hit;
2017-03-22 00:55:31 +08:00
Judgement.TaikoResult = TaikoHitResult.Great;
}
}
else
{
if (Judgement.TimeOffset < 0)
return;
2017-03-29 12:33:52 +08:00
//TODO: THIS IS SHIT AND CAN'T EXIST POST-TAIKO WORLD CUP
if (userHits > HitObject.RequiredHits / 2)
{
Judgement.Result = HitResult.Hit;
2017-03-22 00:55:31 +08:00
Judgement.TaikoResult = TaikoHitResult.Good;
}
else
Judgement.Result = HitResult.Miss;
}
}
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-03-29 12:33:52 +08:00
Delay(HitObject.StartTime - Time.Current - preempt, true);
2017-03-31 10:20:04 +08:00
targetRing.ScaleTo(target_ring_scale, preempt * 4, EasingTypes.OutQuint);
2017-03-29 12:33:52 +08:00
Delay(preempt, true);
Delay(Judgement.TimeOffset + HitObject.Duration, true);
2017-03-29 12:33:52 +08:00
2017-03-31 10:20:04 +08:00
const float out_transition_time = 300;
2017-03-28 14:05:45 +08:00
switch (state)
{
case ArmedState.Hit:
2017-03-31 10:20:04 +08:00
bodyContainer.ScaleTo(1.4f, out_transition_time);
2017-03-28 14:05:45 +08:00
break;
}
2017-03-29 12:33:52 +08:00
2017-03-31 10:20:04 +08:00
FadeOut(out_transition_time, EasingTypes.Out);
2017-03-29 12:33:52 +08:00
Expire();
2017-03-24 14:05:54 +08:00
}
protected override void UpdateScrollPosition(double time)
{
// Make the swell stop at the hit target
double t = Math.Min(HitObject.StartTime, time);
if (t == HitObject.StartTime && !hasStarted)
{
OnStart?.Invoke();
hasStarted = true;
}
base.UpdateScrollPosition(t);
}
protected override bool HandleKeyPress(Key key)
{
if (Judgement.Result != HitResult.None)
return false;
// Don't handle keys before the swell starts
if (Time.Current < HitObject.StartTime)
return false;
// Find the keyset which this key corresponds to
var keySet = rimKeys.Contains(key) ? rimKeys : centreKeys;
// Ensure alternating keysets
if (keySet == lastKeySet)
return false;
lastKeySet = keySet;
UpdateJudgement(true);
return true;
}
}
}