1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 02:07:24 +08:00
osu-lazer/osu.Game.Modes.Taiko/Objects/Drawable/DrawableSwell.cs

206 lines
7.3 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-03-28 14:05:45 +08:00
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
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.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Judgements;
2017-03-28 14:05:45 +08:00
using osu.Game.Modes.Taiko.Objects.Drawable.Pieces;
using System;
namespace osu.Game.Modes.Taiko.Objects.Drawable
{
2017-03-25 19:57:49 +08:00
public class DrawableSwell : DrawableTaikoHitObject
{
/// <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-28 14:05:45 +08:00
private const float target_ring_thick_border = 4f;
private const float target_ring_thin_border = 1f;
private const float target_ring_scale = 5f;
private const float inner_ring_alpha = 0.35f;
/// <summary>
2017-03-25 19:57:49 +08:00
/// The amount of times the user has hit this swell.
/// </summary>
private int userHits;
2017-03-25 19:57:49 +08:00
private readonly Swell swell;
2017-03-17 18:25:55 +08:00
2017-03-28 14:05:45 +08:00
private readonly Container bodyContainer;
private readonly CircularContainer targetRing;
private readonly CircularContainer innerRing;
private bool hasStarted;
2017-03-25 19:57:49 +08:00
public DrawableSwell(Swell swell)
: base(swell)
{
2017-03-25 19:57:49 +08:00
this.swell = swell;
2017-03-28 14:05:45 +08:00
Children = new Framework.Graphics.Drawable[]
{
bodyContainer = new Container
{
Children = new Framework.Graphics.Drawable[]
{
innerRing = new CircularContainer
{
Name = "Inner ring",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(TaikoHitObject.CIRCLE_RADIUS * 2),
Masking = true,
Children = new []
{
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.CIRCLE_RADIUS * 2),
Masking = true,
BorderThickness = target_ring_thick_border,
Children = new Framework.Graphics.Drawable[]
{
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
}
}
}
}
},
new SwellCirclePiece(new CirclePiece())
}
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
innerRing.Colour = colours.YellowDark;
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
}
protected override void CheckJudgement(bool userTriggered)
{
if (userTriggered)
{
if (Time.Current < HitObject.StartTime)
return;
userHits++;
2017-03-28 14:05:45 +08:00
innerRing.FadeTo(1);
innerRing.FadeTo(inner_ring_alpha, 500, EasingTypes.OutQuint);
innerRing.ScaleTo(1f + (target_ring_scale - 1) * userHits / swell.RequiredHits, 1200, EasingTypes.OutElastic);
2017-03-25 19:57:49 +08:00
if (userHits == swell.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
2017-03-25 19:57:49 +08:00
if (userHits > swell.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-29 12:33:52 +08:00
const float preempt = 300;
Delay(HitObject.StartTime - Time.Current - preempt, true);
targetRing.ScaleTo(target_ring_scale, preempt, EasingTypes.Out);
Delay(preempt, true);
Delay(Judgement.TimeOffset + swell.Duration, true);
2017-03-28 14:05:45 +08:00
switch (state)
{
case ArmedState.Hit:
bodyContainer.ScaleTo(1.2f, 400, EasingTypes.OutQuad);
break;
}
2017-03-29 12:33:52 +08:00
FadeOut(600);
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.HasValue)
return false;
UpdateJudgement(true);
return true;
}
}
}