From 55a91dbbe031df2bb677a6518cf035961d4faf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 13 Nov 2020 15:16:33 +0100 Subject: [PATCH] Add fading on hit state change --- .../Skinning/LegacyBodyPiece.cs | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Skinning/LegacyBodyPiece.cs b/osu.Game.Rulesets.Mania/Skinning/LegacyBodyPiece.cs index c0f0fcb4af..a9cd7b592f 100644 --- a/osu.Game.Rulesets.Mania/Skinning/LegacyBodyPiece.cs +++ b/osu.Game.Rulesets.Mania/Skinning/LegacyBodyPiece.cs @@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Mania.Skinning { public class LegacyBodyPiece : LegacyManiaColumnElement { + private DrawableHoldNote holdNote; + private readonly IBindable direction = new Bindable(); private readonly IBindable isHitting = new Bindable(); @@ -38,6 +40,8 @@ public LegacyBodyPiece() [BackgroundDependencyLoader] private void load(ISkinSource skin, IScrollingInfo scrollingInfo, DrawableHitObject drawableObject) { + holdNote = (DrawableHoldNote)drawableObject; + string imageName = GetColumnSkinConfig(skin, LegacyManiaSkinConfigurationLookups.HoldNoteBodyImage)?.Value ?? $"mania-note{FallbackColumnIndex}L"; @@ -92,11 +96,44 @@ private void load(ISkinSource skin, IScrollingInfo scrollingInfo, DrawableHitObj InternalChild = bodySprite; direction.BindTo(scrollingInfo.Direction); - direction.BindValueChanged(onDirectionChanged, true); - - var holdNote = (DrawableHoldNote)drawableObject; isHitting.BindTo(holdNote.IsHitting); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + direction.BindValueChanged(onDirectionChanged, true); isHitting.BindValueChanged(onIsHittingChanged, true); + + holdNote.ApplyCustomUpdateState += applyCustomUpdateState; + applyCustomUpdateState(holdNote, holdNote.State.Value); + } + + /// + /// Stores the start time of the fade animation that plays when any of the nested + /// hitobjects of the hold note are missed. + /// + private double? missFadeTime; + + private void applyCustomUpdateState(DrawableHitObject hitObject, ArmedState state) + { + switch (state) + { + case ArmedState.Miss: + missFadeTime ??= hitObject.StateUpdateTime; + + using (BeginAbsoluteSequence(missFadeTime.Value)) + { + // colour and duration matches stable + // transforms not applied to entire hold note in order to not affect hit lighting + holdNote.Head.FadeColour(Colour4.DarkGray, 60); + bodySprite?.FadeColour(Colour4.DarkGray, 60); + holdNote.Tail.FadeColour(Colour4.DarkGray, 60); + } + + break; + } } private void onIsHittingChanged(ValueChangedEvent isHitting) @@ -162,6 +199,9 @@ protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); + if (holdNote != null) + holdNote.ApplyCustomUpdateState -= applyCustomUpdateState; + lightContainer?.Expire(); } }