1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-24 07:23:26 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

228 lines
6.4 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
2022-06-17 15:37:17 +08:00
#nullable disable
2017-04-04 11:38:55 +08:00
using System;
using System.Linq;
using JetBrains.Annotations;
2017-03-28 14:05:45 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects.Drawables;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Objects;
2020-12-07 11:30:25 +08:00
using osu.Game.Rulesets.Taiko.Skinning.Default;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
public partial class DrawableSwell : DrawableTaikoHitObject<Swell>
{
2019-08-27 14:21:54 +08: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;
private Vector2 baseSize;
2022-06-20 23:22:41 +08:00
private readonly Container<DrawableSwellTick> ticks;
2018-04-13 17:19:50 +08:00
private double? lastPressHandleTime;
public override bool DisplayResult => false;
2024-06-13 20:49:56 +08:00
/// <summary>
/// Whether the player must alternate centre and rim hits.
/// </summary>
public bool MustAlternate { get; internal set; } = true;
public event Action<int> UpdateHitProgress;
public DrawableSwell()
: this(null)
{
}
public DrawableSwell([CanBeNull] Swell swell)
2017-03-25 19:57:49 +08:00
: base(swell)
{
FillMode = FillMode.Fit;
2018-04-13 17:19:50 +08:00
2022-06-20 23:22:41 +08:00
AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
2017-03-28 14:05:45 +08:00
}
2018-04-13 17:19:50 +08:00
2025-02-04 17:48:44 +08:00
protected override SkinnableDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponentLookup(TaikoSkinComponents.Swell),
_ => new DefaultSwell
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
});
protected override void RecreatePieces()
{
base.RecreatePieces();
Size = baseSize = new Vector2(TaikoHitObject.DEFAULT_SIZE);
}
protected override void OnFree()
2017-08-09 09:54:00 +08:00
{
base.OnFree();
UnproxyContent();
2018-04-13 17:19:50 +08:00
lastWasCentre = null;
lastPressHandleTime = null;
2017-08-09 09:54:00 +08:00
}
2018-04-13 17:19:50 +08:00
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
2019-10-17 11:53:54 +08:00
switch (hitObject)
{
case DrawableSwellTick tick:
2022-06-20 23:22:41 +08:00
ticks.Add(tick);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
2022-06-20 23:22:41 +08:00
ticks.Clear(false);
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case SwellTick tick:
return new DrawableSwellTick(tick);
}
return base.CreateNestedHitObject(hitObject);
}
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (userTriggered)
{
DrawableSwellTick nextTick = null;
2022-06-20 23:22:41 +08:00
foreach (var t in ticks)
{
if (!t.Result.HasResult)
{
nextTick = t;
break;
}
}
2018-04-13 17:19:50 +08:00
2020-09-29 14:13:11 +08:00
nextTick?.TriggerResult(true);
int numHits = ticks.Count(r => r.IsHit);
2022-06-20 23:22:41 +08:00
UpdateHitProgress?.Invoke(numHits);
2018-04-13 17:19:50 +08:00
if (numHits == HitObject.RequiredHits)
ApplyMaxResult();
}
else
{
if (timeOffset < 0)
return;
2018-04-13 17:19:50 +08:00
int numHits = 0;
2022-06-20 23:22:41 +08:00
foreach (var tick in ticks)
{
if (tick.IsHit)
{
numHits++;
continue;
}
if (!tick.Result.HasResult)
tick.TriggerResult(false);
}
if (numHits == HitObject.RequiredHits)
ApplyMaxResult();
else
ApplyMinResult();
}
}
2018-04-13 17:19:50 +08:00
2020-11-04 15:19:07 +08:00
protected override void UpdateHitStateTransforms(ArmedState state)
2017-03-24 14:05:54 +08:00
{
base.UpdateHitStateTransforms(state);
2017-03-28 14:05:45 +08:00
switch (state)
{
case ArmedState.Idle:
break;
2019-04-01 11:44:46 +08:00
case ArmedState.Miss:
this.Delay(300).FadeOut();
break;
2022-12-11 09:17:50 +08:00
case ArmedState.Hit:
this.Delay(660).FadeOut();
2017-03-28 14:05:45 +08:00
break;
}
2017-03-24 14:05:54 +08:00
}
2018-04-13 17:19:50 +08:00
protected override void Update()
{
base.Update();
2018-04-13 17:19:50 +08:00
Size = baseSize * Parent!.RelativeChildSize;
2018-04-13 17:19:50 +08:00
// Make the swell stop at the hit target
X = Math.Max(0, X);
2018-04-13 17:19:50 +08:00
2019-08-27 14:21:54 +08:00
if (Time.Current >= HitObject.StartTime - ring_appear_offset)
ProxyContent();
else
UnproxyContent();
if ((Clock as IGameplayClock)?.IsRewinding == true)
lastPressHandleTime = null;
}
2018-04-13 17:19:50 +08:00
private bool? lastWasCentre;
2018-04-13 17:19:50 +08:00
2021-09-16 17:26:12 +08:00
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
{
// Don't handle keys before the swell starts
if (Time.Current < HitObject.StartTime)
return false;
2018-04-13 17:19:50 +08:00
if (AllJudged)
return false;
bool isCentre = e.Action == TaikoAction.LeftCentre || e.Action == TaikoAction.RightCentre;
2018-04-13 17:19:50 +08:00
// Ensure alternating centre and rim hits
2024-06-13 20:49:56 +08:00
if (lastWasCentre == isCentre && MustAlternate)
return false;
2019-02-28 12:31:40 +08:00
// If we've already successfully judged a tick this frame, do not judge more.
// Note that the ordering is important here - this is intentionally placed after the alternating check.
// That is done to prevent accidental double inputs blocking simultaneous but legitimate hits from registering.
if (lastPressHandleTime == Time.Current)
return true;
lastWasCentre = isCentre;
lastPressHandleTime = Time.Current;
2018-04-13 17:19:50 +08:00
UpdateResult(true);
2018-04-13 17:19:50 +08:00
return true;
}
}
}