diff --git a/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs b/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs index 81ea9c0755..0018899769 100644 --- a/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs +++ b/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -50,6 +52,31 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning AddStep("fail state", () => SetContents(() => new TaikoMascotAnimation(TaikoMascotAnimationState.Fail))); } + [Test] + public void TestClearStateTransition() + { + AddStep("set beatmap", () => setBeatmap()); + + // the bindables need to be independent for each content cell to prevent interference, + // as if some of the skins don't implement the animation they'll immediately revert to the previous state from the clear state. + var states = new List>(); + + AddStep("create mascot", () => SetContents(() => + { + var state = new Bindable(TaikoMascotAnimationState.Clear); + states.Add(state); + return new DrawableTaikoMascot { State = { BindTarget = state } }; + })); + + AddStep("set clear state", () => states.ForEach(state => state.Value = TaikoMascotAnimationState.Clear)); + AddStep("miss", () => mascots.ForEach(mascot => mascot.OnNewResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Miss }))); + AddAssert("skins with animations remain in clear state", () => mascots.Any(mascot => mascot.State.Value == TaikoMascotAnimationState.Clear)); + AddUntilStep("state reverts to fail", () => someMascotsIn(TaikoMascotAnimationState.Fail)); + + AddStep("set clear state again", () => states.ForEach(state => state.Value = TaikoMascotAnimationState.Clear)); + AddAssert("skins with animations change to clear", () => someMascotsIn(TaikoMascotAnimationState.Clear)); + } + [Test] public void TestPlayfield() { @@ -65,13 +92,13 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning }); AddStep("miss result for normal hit", () => addJudgement(HitResult.Miss, new TaikoJudgement())); - AddUntilStep("state is fail", () => assertState(TaikoMascotAnimationState.Fail)); + AddUntilStep("state is fail", () => allMascotsIn(TaikoMascotAnimationState.Fail)); AddStep("great result for normal hit", () => addJudgement(HitResult.Great, new TaikoJudgement())); - AddUntilStep("state is idle", () => assertState(TaikoMascotAnimationState.Idle)); + AddUntilStep("state is idle", () => allMascotsIn(TaikoMascotAnimationState.Idle)); AddStep("miss result for strong hit", () => addJudgement(HitResult.Miss, new TaikoStrongJudgement())); - AddAssert("state remains idle", () => assertState(TaikoMascotAnimationState.Idle)); + AddAssert("state remains idle", () => allMascotsIn(TaikoMascotAnimationState.Idle)); } [Test] @@ -92,10 +119,10 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning }); }); - AddUntilStep("state is fail", () => assertState(TaikoMascotAnimationState.Fail)); + AddUntilStep("state is fail", () => allMascotsIn(TaikoMascotAnimationState.Fail)); AddStep("great result for normal hit", () => addJudgement(HitResult.Great, new TaikoJudgement())); - AddUntilStep("state is kiai", () => assertState(TaikoMascotAnimationState.Kiai)); + AddUntilStep("state is kiai", () => allMascotsIn(TaikoMascotAnimationState.Kiai)); } private void setBeatmap(bool kiai = false) @@ -135,6 +162,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning } } - private bool assertState(TaikoMascotAnimationState state) => mascots.All(d => d.State.Value == state); + private bool allMascotsIn(TaikoMascotAnimationState state) => mascots.All(d => d.State.Value == state); + private bool someMascotsIn(TaikoMascotAnimationState state) => mascots.Any(d => d.State.Value == state); } } diff --git a/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs b/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs index bfc1d958c2..f4bc841c15 100644 --- a/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs +++ b/osu.Game.Rulesets.Taiko/UI/DrawableTaikoMascot.cs @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Taiko.UI private readonly Bindable state; private readonly Dictionary animations; - private Drawable currentAnimation; + private TaikoMascotAnimation currentAnimation; private bool lastHitMissed; private bool kiaiMode; @@ -44,8 +44,6 @@ namespace osu.Game.Rulesets.Taiko.UI animations[TaikoMascotAnimationState.Kiai] = new TaikoMascotAnimation(TaikoMascotAnimationState.Kiai), animations[TaikoMascotAnimationState.Fail] = new TaikoMascotAnimation(TaikoMascotAnimationState.Fail), }; - - updateState(); } protected override void LoadComplete() @@ -53,28 +51,32 @@ namespace osu.Game.Rulesets.Taiko.UI base.LoadComplete(); animations.Values.ForEach(animation => animation.Hide()); - State.BindValueChanged(mascotStateChanged, true); + state.BindValueChanged(mascotStateChanged, true); } public void OnNewResult(JudgementResult result) { lastHitMissed = result.Type == HitResult.Miss && result.Judgement.AffectsCombo; - updateState(); } protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) { kiaiMode = effectPoint.KiaiMode; - updateState(); } - private void updateState() + protected override void Update() { + base.Update(); state.Value = getNextState(); } private TaikoMascotAnimationState getNextState() { + // don't change state if current animation is playing + // (used for clear state - others are manually animated on new beats) + if (currentAnimation != null && !currentAnimation.Completed) + return state.Value; + if (lastHitMissed) return TaikoMascotAnimationState.Fail; diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoMascotAnimation.cs b/osu.Game.Rulesets.Taiko/UI/TaikoMascotAnimation.cs index ee1389147d..165e00cc73 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoMascotAnimation.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoMascotAnimation.cs @@ -29,6 +29,15 @@ namespace osu.Game.Rulesets.Taiko.UI RelativeSizeAxes = Axes.Both; Origin = Anchor = Anchor.BottomLeft; + AlwaysPresent = true; + } + + public bool Completed => !textureAnimation.IsPlaying || textureAnimation.PlaybackPosition >= textureAnimation.Duration; + + public override void Show() + { + base.Show(); + textureAnimation.Seek(0); } protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) @@ -93,6 +102,7 @@ namespace osu.Game.Rulesets.Taiko.UI public ClearMascotTextureAnimation() { DefaultFrameLength = clear_animation_speed; + Loop = false; } [BackgroundDependencyLoader]