1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs

92 lines
3.2 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;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Taiko.UI
{
2020-04-27 07:40:57 +08:00
public class DrawableTaikoMascot : BeatSyncedContainer
{
public IBindable<TaikoMascotAnimationState> State => state;
private readonly Bindable<TaikoMascotAnimationState> state;
private readonly Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation> animations;
private Drawable currentAnimation;
private bool lastHitMissed;
private bool kiaiMode;
public DrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle)
{
RelativeSizeAxes = Axes.Both;
2020-04-27 07:40:57 +08:00
state = new Bindable<TaikoMascotAnimationState>(startingState);
animations = new Dictionary<TaikoMascotAnimationState, TaikoMascotAnimation>();
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
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),
};
updateState();
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());
State.BindValueChanged(mascotStateChanged, true);
2020-04-27 07:40:57 +08:00
}
public void OnNewResult(JudgementResult result)
2020-04-28 05:19:18 +08:00
{
lastHitMissed = result.Type == HitResult.Miss && result.Judgement.AffectsCombo;
updateState();
2020-04-28 05:19:18 +08:00
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
2020-04-27 07:40:57 +08:00
{
kiaiMode = effectPoint.KiaiMode;
updateState();
2020-04-27 07:40:57 +08:00
}
private void updateState()
2020-04-27 07:40:57 +08:00
{
state.Value = getNextState();
}
private TaikoMascotAnimationState getNextState()
{
if (lastHitMissed)
return TaikoMascotAnimationState.Fail;
return kiaiMode ? TaikoMascotAnimationState.Kiai : TaikoMascotAnimationState.Idle;
}
private void mascotStateChanged(ValueChangedEvent<TaikoMascotAnimationState> state)
{
currentAnimation?.Hide();
currentAnimation = animations[state.NewValue];
currentAnimation.Show();
}
}
}