1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 16:42:55 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs

125 lines
4.8 KiB
C#
Raw Normal View History

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.
using System.Collections.Generic;
2020-04-24 13:57:16 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
2020-09-29 14:13:11 +08:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Judgements;
2020-05-12 04:53:05 +08:00
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Taiko.UI
{
2020-04-27 07:40:57 +08:00
public class DrawableTaikoMascot : BeatSyncedContainer
{
2020-05-12 04:53:05 +08:00
public readonly Bindable<TaikoMascotAnimationState> State;
public readonly Bindable<JudgementResult> LastResult;
private readonly Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation> animations;
private TaikoMascotAnimation currentAnimation;
2020-05-01 04:03:39 +08:00
private bool lastObjectHit = true;
private bool kiaiMode;
public DrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle)
{
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);
LastResult = new Bindable<JudgementResult>();
animations = new Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation>();
}
2020-05-12 04:53:05 +08:00
[BackgroundDependencyLoader(true)]
private void load(TextureStore textures, GameplayBeatmap gameplayBeatmap)
{
InternalChildren = new[]
{
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-05-12 04:53:05 +08:00
if (gameplayBeatmap != null)
((IBindable<JudgementResult>)LastResult).BindTo(gameplayBeatmap.LastJudgementResult);
2020-04-27 07:40:57 +08:00
}
protected override void LoadComplete()
2020-04-27 07:40:57 +08:00
{
base.LoadComplete();
2020-04-27 07:40:57 +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
}
2020-05-12 04:53:05 +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;
// 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-09-29 14:13:11 +08:00
if (!result.Type.AffectsCombo())
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
{
kiaiMode = effectPoint.KiaiMode;
2020-04-27 07:40:57 +08:00
}
protected override void Update()
2020-04-27 07:40:57 +08:00
{
base.Update();
2020-05-12 04:53:05 +08:00
State.Value = getNextState();
}
private TaikoMascotAnimationState getNextState()
{
// 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;
if (!lastObjectHit)
return TaikoMascotAnimationState.Fail;
return kiaiMode ? TaikoMascotAnimationState.Kiai : TaikoMascotAnimationState.Idle;
}
private void mascotStateChanged(ValueChangedEvent<TaikoMascotAnimationState> state)
{
currentAnimation?.Hide();
currentAnimation = animations[state.NewValue];
currentAnimation.Show();
}
private bool triggerComboClear(JudgementResult judgementResult)
2020-09-29 14:13:11 +08:00
=> (judgementResult.ComboAtJudgement + 1) % 50 == 0 && judgementResult.Type.AffectsCombo() && judgementResult.IsHit;
private bool triggerSwellClear(JudgementResult judgementResult)
=> judgementResult.Judgement is TaikoSwellJudgement && judgementResult.IsHit;
}
}