Add fading on hit state change

This commit is contained in:
Bartłomiej Dach 2020-11-13 15:16:33 +01:00
parent 2ccc81ccc0
commit 55a91dbbe0
1 changed files with 43 additions and 3 deletions

View File

@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Mania.Skinning
{
public class LegacyBodyPiece : LegacyManiaColumnElement
{
private DrawableHoldNote holdNote;
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private readonly IBindable<bool> isHitting = new Bindable<bool>();
@ -38,6 +40,8 @@ public LegacyBodyPiece()
[BackgroundDependencyLoader]
private void load(ISkinSource skin, IScrollingInfo scrollingInfo, DrawableHitObject drawableObject)
{
holdNote = (DrawableHoldNote)drawableObject;
string imageName = GetColumnSkinConfig<string>(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);
}
/// <summary>
/// Stores the start time of the fade animation that plays when any of the nested
/// hitobjects of the hold note are missed.
/// </summary>
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<bool> isHitting)
@ -162,6 +199,9 @@ protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (holdNote != null)
holdNote.ApplyCustomUpdateState -= applyCustomUpdateState;
lightContainer?.Expire();
}
}