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