2019-01-24 08:43:03 +00:00
|
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-08-02 07:09:04 +00:00
|
|
|
|
using System.Linq;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-10-17 02:57:00 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableSwell : DrawableTaikoHitObject<Swell>
|
|
|
|
|
{
|
|
|
|
|
private const float target_ring_thick_border = 1.4f;
|
|
|
|
|
private const float target_ring_thin_border = 1f;
|
|
|
|
|
private const float target_ring_scale = 5f;
|
|
|
|
|
private const float inner_ring_alpha = 0.65f;
|
|
|
|
|
|
2019-08-27 06:21:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Offset away from the start time of the swell at which the ring starts appearing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double ring_appear_offset = 100;
|
|
|
|
|
|
2019-10-17 02:57:00 +00:00
|
|
|
|
private readonly Container<DrawableSwellTick> ticks;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly Container bodyContainer;
|
|
|
|
|
private readonly CircularContainer targetRing;
|
|
|
|
|
private readonly CircularContainer expandingRing;
|
|
|
|
|
|
|
|
|
|
private readonly SwellSymbolPiece symbol;
|
|
|
|
|
|
|
|
|
|
public DrawableSwell(Swell swell)
|
|
|
|
|
: base(swell)
|
|
|
|
|
{
|
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
|
|
2018-06-11 12:45:19 +00:00
|
|
|
|
Content.Add(bodyContainer = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Depth = 1,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
expandingRing = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Name = "Expanding ring",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-08-21 04:29:50 +00:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
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,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = target_ring_thick_border,
|
2019-08-21 04:29:50 +00:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Children = new 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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-17 02:57:00 +00:00
|
|
|
|
AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
|
2018-08-03 07:35:29 +00:00
|
|
|
|
|
2019-10-17 02:57:00 +00:00
|
|
|
|
MainPiece.Add(symbol = new SwellSymbolPiece());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
MainPiece.AccentColour = colours.YellowDark;
|
|
|
|
|
expandingRing.Colour = colours.YellowLight;
|
|
|
|
|
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
2019-10-17 02:57:00 +00:00
|
|
|
|
{
|
2019-10-17 04:52:21 +00:00
|
|
|
|
base.AddNestedHitObject(hitObject);
|
2019-10-17 02:57:00 +00:00
|
|
|
|
|
2019-10-17 03:53:54 +00:00
|
|
|
|
switch (hitObject)
|
2019-10-17 02:57:00 +00:00
|
|
|
|
{
|
|
|
|
|
case DrawableSwellTick tick:
|
|
|
|
|
ticks.Add(tick);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override void ClearNestedHitObjects()
|
2019-10-17 02:57:00 +00:00
|
|
|
|
{
|
2019-10-17 04:52:21 +00:00
|
|
|
|
base.ClearNestedHitObjects();
|
2019-10-17 02:57:00 +00:00
|
|
|
|
ticks.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
2019-10-17 02:57:00 +00:00
|
|
|
|
{
|
|
|
|
|
switch (hitObject)
|
|
|
|
|
{
|
|
|
|
|
case SwellTick tick:
|
|
|
|
|
return new DrawableSwellTick(tick);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 04:52:21 +00:00
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
2019-10-17 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (userTriggered)
|
|
|
|
|
{
|
2019-10-17 02:57:00 +00:00
|
|
|
|
DrawableSwellTick nextTick = null;
|
|
|
|
|
|
|
|
|
|
foreach (var t in ticks)
|
|
|
|
|
{
|
|
|
|
|
if (!t.IsHit)
|
|
|
|
|
{
|
|
|
|
|
nextTick = t;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-03 07:35:29 +00:00
|
|
|
|
nextTick?.TriggerResult(HitResult.Great);
|
2018-08-02 07:09:04 +00:00
|
|
|
|
|
2018-08-03 07:35:29 +00:00
|
|
|
|
var numHits = ticks.Count(r => r.IsHit);
|
2018-08-02 07:09:04 +00:00
|
|
|
|
|
|
|
|
|
var completion = (float)numHits / HitObject.RequiredHits;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
expandingRing
|
2019-11-20 12:19:49 +00:00
|
|
|
|
.FadeTo(expandingRing.Alpha + Math.Clamp(completion / 16, 0.1f, 0.6f), 50)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
.Then()
|
|
|
|
|
.FadeTo(completion / 8, 2000, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
symbol.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
|
|
|
|
|
|
2018-08-02 07:09:04 +00:00
|
|
|
|
if (numHits == HitObject.RequiredHits)
|
2018-08-03 07:35:29 +00:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Great);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (timeOffset < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-02 07:09:04 +00:00
|
|
|
|
int numHits = 0;
|
|
|
|
|
|
2018-08-03 07:35:29 +00:00
|
|
|
|
foreach (var tick in ticks)
|
2018-08-02 07:09:04 +00:00
|
|
|
|
{
|
2018-08-03 07:35:29 +00:00
|
|
|
|
if (tick.IsHit)
|
2018-08-02 07:09:04 +00:00
|
|
|
|
{
|
|
|
|
|
numHits++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 07:35:29 +00:00
|
|
|
|
tick.TriggerResult(HitResult.Miss);
|
2018-08-02 07:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 11:36:08 +00:00
|
|
|
|
var hitResult = numHits > HitObject.RequiredHits / 2 ? HitResult.Good : HitResult.Miss;
|
|
|
|
|
|
2018-08-03 07:35:29 +00:00
|
|
|
|
ApplyResult(r => r.Type = hitResult);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 06:19:16 +00:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateInitialTransforms();
|
2019-08-27 02:03:56 +00:00
|
|
|
|
|
2019-08-27 06:21:54 +00:00
|
|
|
|
using (BeginAbsoluteSequence(HitObject.StartTime - ring_appear_offset, true))
|
2019-08-27 06:19:16 +00:00
|
|
|
|
targetRing.ScaleTo(target_ring_scale, 400, Easing.OutQuint);
|
|
|
|
|
}
|
2019-08-27 02:03:56 +00:00
|
|
|
|
|
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-08-27 02:03:56 +00:00
|
|
|
|
const double transition_duration = 300;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2018-06-11 13:32:08 +00:00
|
|
|
|
case ArmedState.Idle:
|
|
|
|
|
expandingRing.FadeTo(0);
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-06-11 13:32:08 +00:00
|
|
|
|
case ArmedState.Miss:
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ArmedState.Hit:
|
2019-08-27 02:03:56 +00:00
|
|
|
|
using (BeginAbsoluteSequence(Time.Current, true))
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut(transition_duration, Easing.Out);
|
|
|
|
|
bodyContainer.ScaleTo(1.4f, transition_duration);
|
|
|
|
|
}
|
2018-06-11 13:32:08 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
Size = BaseSize * Parent.RelativeChildSize;
|
|
|
|
|
|
|
|
|
|
// Make the swell stop at the hit target
|
|
|
|
|
X = Math.Max(0, X);
|
|
|
|
|
|
2019-08-27 06:21:54 +00:00
|
|
|
|
if (Time.Current >= HitObject.StartTime - ring_appear_offset)
|
2018-06-11 12:45:19 +00:00
|
|
|
|
ProxyContent();
|
2019-08-27 06:19:16 +00:00
|
|
|
|
else
|
|
|
|
|
UnproxyContent();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool? lastWasCentre;
|
|
|
|
|
|
|
|
|
|
public override bool OnPressed(TaikoAction action)
|
|
|
|
|
{
|
|
|
|
|
// Don't handle keys before the swell starts
|
|
|
|
|
if (Time.Current < HitObject.StartTime)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var isCentre = action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre;
|
|
|
|
|
|
|
|
|
|
// Ensure alternating centre and rim hits
|
|
|
|
|
if (lastWasCentre == isCentre)
|
|
|
|
|
return false;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
lastWasCentre = isCentre;
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
UpdateResult(true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|