2020-03-31 15:42:35 +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.
|
|
|
|
|
2020-08-26 19:21:56 +08:00
|
|
|
using System;
|
2023-02-10 19:36:58 +08:00
|
|
|
using System.Linq;
|
2020-03-31 15:42:35 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-11-09 12:37:04 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-03-31 15:42:35 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Animations;
|
2023-02-10 19:36:58 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-08-02 18:50:57 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2023-02-10 19:36:58 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-03-31 15:42:35 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-07 11:32:52 +08:00
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
|
2020-03-31 15:42:35 +08:00
|
|
|
{
|
|
|
|
public partial class LegacyBodyPiece : LegacyManiaColumnElement
|
|
|
|
{
|
2022-11-09 12:37:04 +08:00
|
|
|
private DrawableHoldNote holdNote = null!;
|
2020-11-13 22:16:33 +08:00
|
|
|
|
2020-03-31 15:42:35 +08:00
|
|
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
|
|
|
private readonly IBindable<bool> isHitting = new Bindable<bool>();
|
|
|
|
|
2020-11-14 04:47:55 +08:00
|
|
|
/// <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 readonly Bindable<double?> missFadeTime = new Bindable<double?>();
|
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
private Drawable? bodySprite;
|
2020-08-27 22:16:54 +08:00
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
private Drawable? lightContainer;
|
2020-08-27 22:16:54 +08:00
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
private Drawable? light;
|
2023-02-10 19:36:58 +08:00
|
|
|
private LegacyNoteBodyStyle? bodyStyle;
|
2020-03-31 15:42:35 +08:00
|
|
|
|
|
|
|
public LegacyBodyPiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin, IScrollingInfo scrollingInfo, DrawableHitObject drawableObject)
|
|
|
|
{
|
2020-11-13 22:16:33 +08:00
|
|
|
holdNote = (DrawableHoldNote)drawableObject;
|
|
|
|
|
2020-06-20 14:56:39 +08:00
|
|
|
string imageName = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.HoldNoteBodyImage)?.Value
|
2020-03-31 15:42:35 +08:00
|
|
|
?? $"mania-note{FallbackColumnIndex}L";
|
|
|
|
|
2020-08-26 19:21:56 +08:00
|
|
|
string lightImage = GetColumnSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.HoldNoteLightImage)?.Value
|
|
|
|
?? "lightingL";
|
|
|
|
|
|
|
|
float lightScale = GetColumnSkinConfig<float>(skin, LegacyManiaSkinConfigurationLookups.HoldNoteLightScale)?.Value
|
|
|
|
?? 1;
|
|
|
|
|
|
|
|
// Create a temporary animation to retrieve the number of frames, in an effort to calculate the intended frame length.
|
|
|
|
// This animation is discarded and re-queried with the appropriate frame length afterwards.
|
|
|
|
var tmp = skin.GetAnimation(lightImage, true, false);
|
|
|
|
double frameLength = 0;
|
|
|
|
if (tmp is IFramedAnimation tmpAnimation && tmpAnimation.FrameCount > 0)
|
|
|
|
frameLength = Math.Max(1000 / 60.0, 170.0 / tmpAnimation.FrameCount);
|
|
|
|
|
|
|
|
light = skin.GetAnimation(lightImage, true, true, frameLength: frameLength).With(d =>
|
|
|
|
{
|
|
|
|
if (d == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d.Origin = Anchor.Centre;
|
|
|
|
d.Blending = BlendingParameters.Additive;
|
|
|
|
d.Scale = new Vector2(lightScale);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (light != null)
|
2020-08-26 19:46:12 +08:00
|
|
|
{
|
|
|
|
lightContainer = new HitTargetInsetContainer
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
Child = light
|
|
|
|
};
|
|
|
|
}
|
2020-08-26 19:21:56 +08:00
|
|
|
|
2023-02-10 19:36:58 +08:00
|
|
|
bodyStyle = skin.GetConfig<ManiaSkinConfigurationLookup, LegacyNoteBodyStyle>(new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.NoteBodyStyle))?.Value;
|
|
|
|
|
|
|
|
var wrapMode = bodyStyle == LegacyNoteBodyStyle.Stretch ? WrapMode.ClampToEdge : WrapMode.Repeat;
|
|
|
|
|
|
|
|
direction.BindTo(scrollingInfo.Direction);
|
|
|
|
isHitting.BindTo(holdNote.IsHitting);
|
|
|
|
|
2023-10-21 05:22:29 +08:00
|
|
|
bodySprite = skin.GetAnimation(imageName, wrapMode, wrapMode, true, true, frameLength: 30).With(d =>
|
2020-03-31 15:42:35 +08:00
|
|
|
{
|
|
|
|
if (d == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d is TextureAnimation animation)
|
|
|
|
animation.IsPlaying = false;
|
|
|
|
|
|
|
|
d.Anchor = Anchor.TopCentre;
|
|
|
|
d.RelativeSizeAxes = Axes.Both;
|
|
|
|
d.Size = Vector2.One;
|
2023-01-24 14:48:57 +08:00
|
|
|
// Todo: Wrap?
|
2020-03-31 15:42:35 +08:00
|
|
|
});
|
|
|
|
|
2020-08-26 19:21:56 +08:00
|
|
|
if (bodySprite != null)
|
|
|
|
InternalChild = bodySprite;
|
2020-11-13 22:16:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
direction.BindValueChanged(onDirectionChanged, true);
|
2020-03-31 15:42:35 +08:00
|
|
|
isHitting.BindValueChanged(onIsHittingChanged, true);
|
2020-11-14 04:47:55 +08:00
|
|
|
missFadeTime.BindValueChanged(onMissFadeTimeChanged, true);
|
2020-11-13 22:16:33 +08:00
|
|
|
|
|
|
|
holdNote.ApplyCustomUpdateState += applyCustomUpdateState;
|
|
|
|
applyCustomUpdateState(holdNote, holdNote.State.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyCustomUpdateState(DrawableHitObject hitObject, ArmedState state)
|
|
|
|
{
|
2023-10-16 14:11:33 +08:00
|
|
|
switch (hitObject)
|
|
|
|
{
|
2023-10-16 14:57:35 +08:00
|
|
|
// Ensure that the hold note is also faded out when the head/tail/body is missed.
|
2023-10-16 14:14:26 +08:00
|
|
|
// Importantly, we filter out unrelated objects like DrawableNotePerfectBonus.
|
2023-10-16 14:11:33 +08:00
|
|
|
case DrawableHoldNoteTail:
|
|
|
|
case DrawableHoldNoteHead:
|
|
|
|
case DrawableHoldNoteBody:
|
|
|
|
if (state == ArmedState.Miss)
|
|
|
|
missFadeTime.Value ??= hitObject.HitStateUpdateTime;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-03-31 15:42:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onIsHittingChanged(ValueChangedEvent<bool> isHitting)
|
|
|
|
{
|
2020-08-26 19:21:56 +08:00
|
|
|
if (bodySprite is TextureAnimation bodyAnimation)
|
|
|
|
{
|
|
|
|
bodyAnimation.GotoFrame(0);
|
|
|
|
bodyAnimation.IsPlaying = isHitting.NewValue;
|
|
|
|
}
|
2020-03-31 15:42:35 +08:00
|
|
|
|
2020-08-27 22:09:54 +08:00
|
|
|
if (lightContainer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isHitting.NewValue)
|
2020-08-26 19:21:56 +08:00
|
|
|
{
|
2020-08-27 22:09:54 +08:00
|
|
|
// Clear the fade out and, more importantly, the removal.
|
|
|
|
lightContainer.ClearTransforms();
|
2020-08-26 19:46:12 +08:00
|
|
|
|
2020-08-27 22:09:54 +08:00
|
|
|
// Only add the container if the removal has taken place.
|
|
|
|
if (lightContainer.Parent == null)
|
|
|
|
Column.TopLevelContainer.Add(lightContainer);
|
2020-08-26 19:21:56 +08:00
|
|
|
|
2020-08-27 22:09:54 +08:00
|
|
|
// The light must be seeked only after being loaded, otherwise a nullref occurs (https://github.com/ppy/osu-framework/issues/3847).
|
|
|
|
if (light is TextureAnimation lightAnimation)
|
|
|
|
lightAnimation.GotoFrame(0);
|
2020-08-26 19:46:12 +08:00
|
|
|
|
2020-08-27 22:09:54 +08:00
|
|
|
lightContainer.FadeIn(80);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lightContainer.FadeOut(120)
|
2022-08-26 14:19:05 +08:00
|
|
|
.OnComplete(d => Column.TopLevelContainer.Remove(d, false));
|
2020-08-26 19:21:56 +08:00
|
|
|
}
|
2020-03-31 15:42:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
|
|
|
|
{
|
|
|
|
if (direction.NewValue == ScrollingDirection.Up)
|
|
|
|
{
|
2020-08-26 19:21:56 +08:00
|
|
|
if (bodySprite != null)
|
|
|
|
{
|
2023-03-03 17:03:06 +08:00
|
|
|
bodySprite.Origin = Anchor.TopCentre;
|
|
|
|
bodySprite.Anchor = Anchor.BottomCentre; // needs to be flipped due to scale flip in Update.
|
2020-08-26 19:21:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (light != null)
|
|
|
|
light.Anchor = Anchor.TopCentre;
|
2020-03-31 15:42:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-26 19:21:56 +08:00
|
|
|
if (bodySprite != null)
|
|
|
|
{
|
|
|
|
bodySprite.Origin = Anchor.TopCentre;
|
2023-03-03 17:03:06 +08:00
|
|
|
bodySprite.Anchor = Anchor.TopCentre;
|
2020-08-26 19:21:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (light != null)
|
|
|
|
light.Anchor = Anchor.BottomCentre;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 04:47:55 +08:00
|
|
|
private void onMissFadeTimeChanged(ValueChangedEvent<double?> missFadeTimeChange)
|
|
|
|
{
|
|
|
|
if (missFadeTimeChange.NewValue == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// this update could come from any nested object of the hold note (or even from an input).
|
|
|
|
// make sure the transforms are consistent across all affected parts.
|
|
|
|
using (BeginAbsoluteSequence(missFadeTimeChange.NewValue.Value))
|
|
|
|
{
|
|
|
|
// colour and duration matches stable
|
|
|
|
// transforms not applied to entire hold note in order to not affect hit lighting
|
2020-11-14 05:21:22 +08:00
|
|
|
const double fade_duration = 60;
|
|
|
|
|
|
|
|
holdNote.Head.FadeColour(Colour4.DarkGray, fade_duration);
|
|
|
|
holdNote.Tail.FadeColour(Colour4.DarkGray, fade_duration);
|
|
|
|
bodySprite?.FadeColour(Colour4.DarkGray, fade_duration);
|
2020-11-14 04:47:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2023-10-09 08:47:00 +08:00
|
|
|
|
2023-10-09 09:50:39 +08:00
|
|
|
if (holdNote.Body.HasHoldBreak)
|
|
|
|
missFadeTime.Value = holdNote.Body.Result.TimeAbsolute;
|
2023-02-10 19:36:58 +08:00
|
|
|
|
2023-03-03 17:03:06 +08:00
|
|
|
int scaleDirection = (direction.Value == ScrollingDirection.Down ? 1 : -1);
|
|
|
|
|
2023-02-10 19:36:58 +08:00
|
|
|
// here we go...
|
|
|
|
switch (bodyStyle)
|
|
|
|
{
|
|
|
|
case LegacyNoteBodyStyle.Stretch:
|
|
|
|
// this is how lazer works by default. nothing required.
|
2023-03-03 17:03:06 +08:00
|
|
|
if (bodySprite != null)
|
|
|
|
bodySprite.Scale = new Vector2(1, scaleDirection);
|
2023-02-10 19:36:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-12-13 14:04:52 +08:00
|
|
|
// this is where things get a bit messed up.
|
2023-02-10 19:36:58 +08:00
|
|
|
// honestly there's three modes to handle here but they seem really pointless?
|
|
|
|
// let's wait to see if anyone actually uses them in skins.
|
|
|
|
if (bodySprite != null)
|
|
|
|
{
|
|
|
|
var sprite = bodySprite as Sprite ?? bodySprite.ChildrenOfType<Sprite>().Single();
|
|
|
|
|
|
|
|
bodySprite.FillMode = FillMode.Stretch;
|
|
|
|
// i dunno this looks about right??
|
2023-03-03 17:03:06 +08:00
|
|
|
bodySprite.Scale = new Vector2(1, scaleDirection * 32800 / sprite.DrawHeight);
|
2023-02-10 19:36:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-11-14 04:47:55 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 19:21:56 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2022-11-09 12:37:04 +08:00
|
|
|
if (holdNote.IsNotNull())
|
2020-11-13 22:16:33 +08:00
|
|
|
holdNote.ApplyCustomUpdateState -= applyCustomUpdateState;
|
|
|
|
|
2020-08-26 19:21:56 +08:00
|
|
|
lightContainer?.Expire();
|
|
|
|
}
|
2020-03-31 15:42:35 +08:00
|
|
|
}
|
|
|
|
}
|