osu/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs

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

125 lines
4.7 KiB
C#
Raw Normal View History

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.
using System.Collections.Generic;
2020-04-24 05:57:16 +00: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.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
2020-09-29 06:13:11 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Judgements;
2020-05-11 20:53:05 +00:00
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Taiko.UI
{
2020-04-26 23:40:57 +00:00
public partial class DrawableTaikoMascot : BeatSyncedContainer
{
2020-05-11 20:53:05 +00:00
public readonly Bindable<TaikoMascotAnimationState> State;
public readonly Bindable<JudgementResult?> LastResult;
private readonly Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation> animations;
2022-11-02 08:07:19 +00:00
private TaikoMascotAnimation? currentAnimation;
2020-04-30 20:03:39 +00:00
private bool lastObjectHit = true;
private bool kiaiMode;
public DrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle)
{
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-05-11 20:53:05 +00:00
animations = new Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation>();
}
2020-05-11 20:53:05 +00:00
[BackgroundDependencyLoader(true)]
2022-11-02 08:07:19 +00:00
private void load(GameplayState? gameplayState)
{
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-11 20:53:05 +00:00
2021-10-01 17:22:23 +00:00
if (gameplayState != null)
((IBindable<JudgementResult>)LastResult).BindTo(gameplayState.LastJudgementResult);
2020-04-26 23:40:57 +00:00
}
protected override void LoadComplete()
2020-04-26 23:40:57 +00:00
{
base.LoadComplete();
2020-04-26 23:40:57 +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
}
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;
// 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-09-29 06:13:11 +00:00
if (!result.Type.AffectsCombo())
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
{
kiaiMode = effectPoint.KiaiMode;
2020-04-26 23:40:57 +00:00
}
protected override void Update()
2020-04-26 23:40:57 +00:00
{
base.Update();
2020-05-11 20:53:05 +00: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-11 20:53:05 +00: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 06:13:11 +00:00
=> (judgementResult.ComboAtJudgement + 1) % 50 == 0 && judgementResult.Type.AffectsCombo() && judgementResult.IsHit;
private bool triggerSwellClear(JudgementResult judgementResult)
=> judgementResult.Judgement is TaikoSwellJudgement && judgementResult.IsHit;
}
}