2022-03-10 13:09:07 +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.
|
|
|
|
|
2023-06-30 06:07:07 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-03-10 13:09:07 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
2023-06-30 08:02:08 +00:00
|
|
|
using osu.Game.Rulesets.Taiko.Objects.Drawables;
|
2022-03-10 13:09:07 +00:00
|
|
|
using osu.Game.Rulesets.UI;
|
2023-07-08 16:29:49 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2022-03-10 13:09:07 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.UI
|
|
|
|
{
|
2023-06-30 08:02:08 +00:00
|
|
|
internal partial class DrumSamplePlayer : CompositeDrawable, IKeyBindingHandler<TaikoAction>
|
2022-03-11 11:36:03 +00:00
|
|
|
{
|
2023-06-30 08:02:08 +00:00
|
|
|
private DrumSampleTriggerSource leftCentreTrigger = null!;
|
|
|
|
private DrumSampleTriggerSource rightCentreTrigger = null!;
|
|
|
|
private DrumSampleTriggerSource leftRimTrigger = null!;
|
|
|
|
private DrumSampleTriggerSource rightRimTrigger = null!;
|
|
|
|
private DrumSampleTriggerSource strongCentreTrigger = null!;
|
|
|
|
private DrumSampleTriggerSource strongRimTrigger = null!;
|
|
|
|
|
|
|
|
private double lastHitTime;
|
|
|
|
private TaikoAction? lastAction;
|
2022-03-10 13:09:07 +00:00
|
|
|
|
2023-06-30 06:07:07 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2023-07-05 09:41:32 +00:00
|
|
|
private void load(Playfield playfield)
|
2022-03-11 11:36:03 +00:00
|
|
|
{
|
2023-07-05 09:41:32 +00:00
|
|
|
var hitObjectContainer = playfield.HitObjectContainer;
|
2022-06-02 05:39:57 +00:00
|
|
|
InternalChildren = new Drawable[]
|
2022-03-10 13:09:07 +00:00
|
|
|
{
|
2023-06-30 08:02:08 +00:00
|
|
|
leftCentreTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Left),
|
|
|
|
rightCentreTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Right),
|
|
|
|
leftRimTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Left),
|
|
|
|
rightRimTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Right),
|
|
|
|
strongCentreTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Centre),
|
|
|
|
strongRimTrigger = CreateTriggerSource(hitObjectContainer, SampleBalance.Centre)
|
2022-03-10 13:09:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-30 07:14:52 +00:00
|
|
|
protected virtual DrumSampleTriggerSource CreateTriggerSource(HitObjectContainer hitObjectContainer, SampleBalance balance)
|
2023-06-30 07:03:11 +00:00
|
|
|
=> new DrumSampleTriggerSource(hitObjectContainer);
|
|
|
|
|
2022-03-10 13:09:07 +00:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
|
|
|
{
|
2023-07-08 16:29:49 +00:00
|
|
|
if ((Clock as IGameplayClock)?.IsRewinding == true)
|
2023-07-03 04:49:14 +00:00
|
|
|
return false;
|
|
|
|
|
2023-06-30 08:02:08 +00:00
|
|
|
HitType hitType;
|
|
|
|
|
|
|
|
DrumSampleTriggerSource triggerSource;
|
|
|
|
|
|
|
|
bool strong = checkStrongValidity(e.Action, lastAction, Time.Current - lastHitTime);
|
|
|
|
|
2022-03-11 11:33:03 +00:00
|
|
|
switch (e.Action)
|
2022-03-10 13:09:07 +00:00
|
|
|
{
|
2022-03-11 11:33:03 +00:00
|
|
|
case TaikoAction.LeftCentre:
|
2023-06-30 08:02:08 +00:00
|
|
|
hitType = HitType.Centre;
|
|
|
|
triggerSource = strong ? strongCentreTrigger : leftCentreTrigger;
|
2022-03-11 11:33:03 +00:00
|
|
|
break;
|
2022-06-02 05:36:07 +00:00
|
|
|
|
2022-03-11 11:33:03 +00:00
|
|
|
case TaikoAction.RightCentre:
|
2023-06-30 08:02:08 +00:00
|
|
|
hitType = HitType.Centre;
|
|
|
|
triggerSource = strong ? strongCentreTrigger : rightCentreTrigger;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TaikoAction.LeftRim:
|
|
|
|
hitType = HitType.Rim;
|
|
|
|
triggerSource = strong ? strongRimTrigger : leftRimTrigger;
|
2022-03-11 11:33:03 +00:00
|
|
|
break;
|
2022-06-02 05:36:07 +00:00
|
|
|
|
2022-03-11 11:33:03 +00:00
|
|
|
case TaikoAction.RightRim:
|
2023-06-30 08:02:08 +00:00
|
|
|
hitType = HitType.Rim;
|
|
|
|
triggerSource = strong ? strongRimTrigger : rightRimTrigger;
|
2022-03-11 11:33:03 +00:00
|
|
|
break;
|
2023-06-30 08:02:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2022-03-10 13:09:07 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 05:05:47 +00:00
|
|
|
if (strong)
|
|
|
|
{
|
|
|
|
switch (hitType)
|
|
|
|
{
|
|
|
|
case HitType.Centre:
|
|
|
|
flushCenterTriggerSources();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HitType.Rim:
|
|
|
|
flushRimTriggerSources();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 08:02:08 +00:00
|
|
|
|
2023-07-07 05:46:36 +00:00
|
|
|
Play(triggerSource, hitType, strong);
|
2023-06-30 08:02:08 +00:00
|
|
|
|
|
|
|
lastHitTime = Time.Current;
|
|
|
|
lastAction = e.Action;
|
|
|
|
|
2022-03-10 13:09:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-07 05:46:36 +00:00
|
|
|
protected virtual void Play(DrumSampleTriggerSource triggerSource, HitType hitType, bool strong) =>
|
|
|
|
triggerSource.Play(hitType, strong);
|
|
|
|
|
2023-06-30 08:02:08 +00:00
|
|
|
private bool checkStrongValidity(TaikoAction newAction, TaikoAction? lastAction, double timeBetweenActions)
|
|
|
|
{
|
|
|
|
if (lastAction == null)
|
|
|
|
return false;
|
|
|
|
|
2023-07-07 06:13:25 +00:00
|
|
|
if (timeBetweenActions < 0 || timeBetweenActions > DrawableHit.StrongNestedHit.SECOND_HIT_WINDOW)
|
2023-06-30 08:02:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (newAction)
|
|
|
|
{
|
|
|
|
case TaikoAction.LeftCentre:
|
|
|
|
return lastAction == TaikoAction.RightCentre;
|
|
|
|
|
|
|
|
case TaikoAction.RightCentre:
|
|
|
|
return lastAction == TaikoAction.LeftCentre;
|
|
|
|
|
|
|
|
case TaikoAction.LeftRim:
|
|
|
|
return lastAction == TaikoAction.RightRim;
|
|
|
|
|
|
|
|
case TaikoAction.RightRim:
|
|
|
|
return lastAction == TaikoAction.LeftRim;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void flushCenterTriggerSources()
|
|
|
|
{
|
|
|
|
leftCentreTrigger.StopAllPlayback();
|
|
|
|
rightCentreTrigger.StopAllPlayback();
|
2023-07-07 05:28:57 +00:00
|
|
|
strongCentreTrigger.StopAllPlayback();
|
2023-06-30 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void flushRimTriggerSources()
|
|
|
|
{
|
|
|
|
leftRimTrigger.StopAllPlayback();
|
|
|
|
rightRimTrigger.StopAllPlayback();
|
2023-07-07 15:44:26 +00:00
|
|
|
strongRimTrigger.StopAllPlayback();
|
2023-06-30 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 13:09:07 +00:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|