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

112 lines
3.9 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.
2020-04-26 23:40:57 +00:00
using System;
2020-04-24 05:57:16 +00:00
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
namespace osu.Game.Rulesets.Taiko.UI
{
2020-04-26 23:40:57 +00:00
public class DrawableTaikoMascot : BeatSyncedContainer
{
2020-04-26 23:40:57 +00:00
private TaikoMascotTextureAnimation idleDrawable, clearDrawable, kiaiDrawable, failDrawable;
private EffectControlPoint lastEffectControlPoint;
2020-04-27 21:19:18 +00:00
private TaikoMascotAnimationState playfieldState;
2020-04-26 23:40:57 +00:00
public TaikoMascotAnimationState State { get; private set; }
public DrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle)
{
RelativeSizeAxes = Axes.Both;
2020-04-26 23:40:57 +00:00
State = startingState;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
InternalChildren = new[]
{
idleDrawable = new TaikoMascotTextureAnimation(TaikoMascotAnimationState.Idle),
clearDrawable = new TaikoMascotTextureAnimation(TaikoMascotAnimationState.Clear),
kiaiDrawable = new TaikoMascotTextureAnimation(TaikoMascotAnimationState.Kiai),
failDrawable = new TaikoMascotTextureAnimation(TaikoMascotAnimationState.Fail),
};
2020-04-26 23:40:57 +00:00
ShowState(State);
}
public void ShowState(TaikoMascotAnimationState state)
{
foreach (var child in InternalChildren)
child.Hide();
State = state;
2020-04-26 23:40:57 +00:00
var drawable = getStateDrawable(State);
drawable.Show();
}
2020-04-27 21:19:18 +00:00
/// <summary>
/// Sets the playfield state used for determining the final state.
/// </summary>
/// <remarks>
/// If you're looking to change the state manually, please look at <see cref="ShowState"/>.
/// </remarks>
public void SetPlayfieldState(TaikoMascotAnimationState state)
{
playfieldState = state;
if (lastEffectControlPoint != null)
ShowState(GetFinalAnimationState(lastEffectControlPoint, playfieldState));
}
2020-04-26 23:40:57 +00:00
private TaikoMascotTextureAnimation getStateDrawable(TaikoMascotAnimationState state)
{
switch (state)
{
case TaikoMascotAnimationState.Idle:
return idleDrawable;
case TaikoMascotAnimationState.Clear:
return clearDrawable;
case TaikoMascotAnimationState.Kiai:
return kiaiDrawable;
case TaikoMascotAnimationState.Fail:
return failDrawable;
default:
throw new ArgumentOutOfRangeException(nameof(state), $"There's no animation available for state {state}");
2020-04-26 23:40:57 +00:00
}
}
protected virtual TaikoMascotAnimationState GetFinalAnimationState(EffectControlPoint effectPoint, TaikoMascotAnimationState playfieldState)
{
if (playfieldState == TaikoMascotAnimationState.Fail)
return playfieldState;
return effectPoint.KiaiMode ? TaikoMascotAnimationState.Kiai : TaikoMascotAnimationState.Idle;
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
{
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
2020-04-27 21:19:18 +00:00
var state = GetFinalAnimationState(lastEffectControlPoint = effectPoint, playfieldState);
2020-04-26 23:40:57 +00:00
ShowState(state);
2020-04-26 23:40:57 +00:00
if (state == TaikoMascotAnimationState.Clear)
return;
2020-04-26 23:40:57 +00:00
var drawable = getStateDrawable(state);
drawable.Move();
}
}
}