2020-04-24 13:57:16 +08: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.
|
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-04-24 13:57:16 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
2020-04-30 02:28:46 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2020-04-30 02:28:46 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2020-09-29 14:13:11 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-05-01 03:58:05 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Judgements;
|
2020-05-12 04:53:05 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.UI
|
|
|
|
|
{
|
2020-04-27 07:40:57 +08:00
|
|
|
|
public class DrawableTaikoMascot : BeatSyncedContainer
|
2020-04-24 12:59:05 +08:00
|
|
|
|
{
|
2020-05-12 04:53:05 +08:00
|
|
|
|
public readonly Bindable<TaikoMascotAnimationState> State;
|
2022-11-16 17:47:58 +08:00
|
|
|
|
public readonly Bindable<JudgementResult?> LastResult;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
|
2020-04-30 03:27:02 +08:00
|
|
|
|
private readonly Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation> animations;
|
2022-11-02 16:07:19 +08:00
|
|
|
|
|
|
|
|
|
private TaikoMascotAnimation? currentAnimation;
|
2020-04-30 02:28:46 +08:00
|
|
|
|
|
2020-05-01 04:03:39 +08:00
|
|
|
|
private bool lastObjectHit = true;
|
2020-04-30 02:28:46 +08:00
|
|
|
|
private bool kiaiMode;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
|
|
|
|
|
public DrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle)
|
|
|
|
|
{
|
2020-05-01 06:19:12 +08:00
|
|
|
|
Origin = Anchor = Anchor.BottomLeft;
|
2020-04-27 07:40:57 +08:00
|
|
|
|
|
2020-05-12 04:53:05 +08:00
|
|
|
|
State = new Bindable<TaikoMascotAnimationState>(startingState);
|
2022-11-16 17:47:58 +08:00
|
|
|
|
LastResult = new Bindable<JudgementResult?>();
|
2020-05-12 04:53:05 +08:00
|
|
|
|
|
2020-04-30 03:27:02 +08:00
|
|
|
|
animations = new Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation>();
|
2020-04-24 12:59:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 04:53:05 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-11-02 16:07:19 +08:00
|
|
|
|
private void load(GameplayState? gameplayState)
|
2020-04-24 12:59:05 +08:00
|
|
|
|
{
|
|
|
|
|
InternalChildren = new[]
|
|
|
|
|
{
|
2020-04-30 03:27:02 +08:00
|
|
|
|
animations[TaikoMascotAnimationState.Idle] = new TaikoMascotAnimation(TaikoMascotAnimationState.Idle),
|
|
|
|
|
animations[TaikoMascotAnimationState.Clear] = new TaikoMascotAnimation(TaikoMascotAnimationState.Clear),
|
|
|
|
|
animations[TaikoMascotAnimationState.Kiai] = new TaikoMascotAnimation(TaikoMascotAnimationState.Kiai),
|
|
|
|
|
animations[TaikoMascotAnimationState.Fail] = new TaikoMascotAnimation(TaikoMascotAnimationState.Fail),
|
2020-04-24 12:59:05 +08:00
|
|
|
|
};
|
2020-05-12 04:53:05 +08:00
|
|
|
|
|
2021-10-02 01:22:23 +08:00
|
|
|
|
if (gameplayState != null)
|
|
|
|
|
((IBindable<JudgementResult>)LastResult).BindTo(gameplayState.LastJudgementResult);
|
2020-04-27 07:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
protected override void LoadComplete()
|
2020-04-27 07:40:57 +08:00
|
|
|
|
{
|
2020-04-30 02:28:46 +08:00
|
|
|
|
base.LoadComplete();
|
2020-04-27 07:40:57 +08:00
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
animations.Values.ForEach(animation => animation.Hide());
|
2020-05-12 04:53:05 +08:00
|
|
|
|
|
|
|
|
|
State.BindValueChanged(mascotStateChanged, true);
|
|
|
|
|
LastResult.BindValueChanged(onNewResult);
|
2020-04-27 07:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 17:47:58 +08:00
|
|
|
|
private void onNewResult(ValueChangedEvent<JudgementResult?> resultChangedEvent)
|
2020-04-28 05:19:18 +08:00
|
|
|
|
{
|
2020-05-12 04:53:05 +08:00
|
|
|
|
var result = resultChangedEvent.NewValue;
|
|
|
|
|
if (result == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-05-01 03:58:05 +08:00
|
|
|
|
// TODO: missing support for clear/fail state transition at end of beatmap gameplay
|
|
|
|
|
|
|
|
|
|
if (triggerComboClear(result) || triggerSwellClear(result))
|
|
|
|
|
{
|
2020-05-12 04:53:05 +08:00
|
|
|
|
State.Value = TaikoMascotAnimationState.Clear;
|
2020-05-01 06:29:03 +08:00
|
|
|
|
// always consider a clear equivalent to a hit to avoid clear -> miss transitions
|
2020-05-01 04:16:25 +08:00
|
|
|
|
lastObjectHit = true;
|
2020-05-01 03:58:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 14:13:11 +08:00
|
|
|
|
if (!result.Type.AffectsCombo())
|
2020-05-01 03:58:05 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
lastObjectHit = result.IsHit;
|
2020-04-28 05:19:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 12:49:18 +08:00
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
2020-04-27 07:40:57 +08:00
|
|
|
|
{
|
2020-04-30 02:28:46 +08:00
|
|
|
|
kiaiMode = effectPoint.KiaiMode;
|
2020-04-27 07:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 06:14:27 +08:00
|
|
|
|
protected override void Update()
|
2020-04-27 07:40:57 +08:00
|
|
|
|
{
|
2020-04-30 06:14:27 +08:00
|
|
|
|
base.Update();
|
2020-05-12 04:53:05 +08:00
|
|
|
|
State.Value = getNextState();
|
2020-04-24 12:59:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
private TaikoMascotAnimationState getNextState()
|
2020-04-24 12:59:05 +08:00
|
|
|
|
{
|
2020-05-14 08:44:21 +08:00
|
|
|
|
// don't change state if current animation is still playing (and we haven't rewound before it).
|
|
|
|
|
// used for clear state - others are manually animated on new beats.
|
|
|
|
|
if (currentAnimation?.Completed == false && currentAnimation.DisplayTime <= Time.Current)
|
2020-05-12 04:53:05 +08:00
|
|
|
|
return State.Value;
|
2020-04-30 06:14:27 +08:00
|
|
|
|
|
2020-05-01 03:58:05 +08:00
|
|
|
|
if (!lastObjectHit)
|
2020-04-30 02:28:46 +08:00
|
|
|
|
return TaikoMascotAnimationState.Fail;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
return kiaiMode ? TaikoMascotAnimationState.Kiai : TaikoMascotAnimationState.Idle;
|
|
|
|
|
}
|
2020-04-24 12:59:05 +08:00
|
|
|
|
|
2020-04-30 02:28:46 +08:00
|
|
|
|
private void mascotStateChanged(ValueChangedEvent<TaikoMascotAnimationState> state)
|
|
|
|
|
{
|
|
|
|
|
currentAnimation?.Hide();
|
|
|
|
|
currentAnimation = animations[state.NewValue];
|
|
|
|
|
currentAnimation.Show();
|
2020-04-24 12:59:05 +08:00
|
|
|
|
}
|
2020-05-01 03:58:05 +08:00
|
|
|
|
|
|
|
|
|
private bool triggerComboClear(JudgementResult judgementResult)
|
2020-09-29 14:13:11 +08:00
|
|
|
|
=> (judgementResult.ComboAtJudgement + 1) % 50 == 0 && judgementResult.Type.AffectsCombo() && judgementResult.IsHit;
|
2020-05-01 03:58:05 +08:00
|
|
|
|
|
|
|
|
|
private bool triggerSwellClear(JudgementResult judgementResult)
|
|
|
|
|
=> judgementResult.Judgement is TaikoSwellJudgement && judgementResult.IsHit;
|
2020-04-24 12:59:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|