2019-08-30 11:59:58 +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.
|
|
|
|
|
2023-10-21 03:47:45 +08:00
|
|
|
using System;
|
2019-08-30 11:59:58 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-10-20 08:32:04 +08:00
|
|
|
using osu.Framework.Bindables;
|
2023-10-21 03:47:45 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2019-08-30 11:59:58 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-07-02 09:21:03 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2022-07-02 12:19:54 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2019-08-30 11:59:58 +08:00
|
|
|
using osu.Game.Skinning;
|
2023-10-21 04:54:29 +08:00
|
|
|
using osuTK;
|
2019-08-30 11:59:58 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-04 19:21:53 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
|
|
|
public partial class LegacySliderBall : CompositeDrawable
|
|
|
|
{
|
2021-06-08 11:10:14 +08:00
|
|
|
private readonly ISkin skin;
|
|
|
|
|
2022-07-02 12:12:36 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2022-07-02 12:36:41 +08:00
|
|
|
private DrawableHitObject? parentObject { get; set; }
|
2022-07-02 09:21:03 +08:00
|
|
|
|
2022-07-02 12:12:36 +08:00
|
|
|
private Sprite layerNd = null!;
|
2023-10-21 03:47:45 +08:00
|
|
|
private Drawable ball = null!;
|
2022-07-02 12:12:36 +08:00
|
|
|
private Sprite layerSpec = null!;
|
2020-07-22 18:06:39 +08:00
|
|
|
|
2023-10-21 03:47:45 +08:00
|
|
|
public Color4 BallColour => ball.Colour;
|
|
|
|
|
|
|
|
public LegacySliderBall(ISkin skin)
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2021-06-08 11:10:14 +08:00
|
|
|
this.skin = skin;
|
2020-04-02 18:30:58 +08:00
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-10-23 16:46:21 +08:00
|
|
|
private void load()
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2020-08-21 23:20:33 +08:00
|
|
|
var ballColour = skin.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SliderBall)?.Value ?? Color4.White;
|
2019-08-30 11:59:58 +08:00
|
|
|
|
2023-10-23 16:46:21 +08:00
|
|
|
double? ballAnimationRate = null;
|
2023-10-21 03:47:45 +08:00
|
|
|
|
2023-10-23 16:46:21 +08:00
|
|
|
if (parentObject != null)
|
|
|
|
{
|
|
|
|
DrawableSlider drawableSlider = (DrawableSlider)parentObject;
|
|
|
|
|
|
|
|
// stable apparently calculates slider velocity in units of seconds rather than milliseconds.
|
|
|
|
double stableSliderVelocity = drawableSlider.HitObject.Velocity * 1000;
|
2023-10-21 03:47:45 +08:00
|
|
|
|
2023-10-23 16:46:21 +08:00
|
|
|
ballAnimationRate = Math.Max(
|
|
|
|
150 / stableSliderVelocity * LegacySkinExtensions.SIXTY_FRAME_TIME,
|
|
|
|
LegacySkinExtensions.SIXTY_FRAME_TIME);
|
|
|
|
}
|
2023-10-21 03:47:45 +08:00
|
|
|
|
2023-10-21 04:54:29 +08:00
|
|
|
Vector2 maxSize = OsuLegacySkinTransformer.MAX_FOLLOW_CIRCLE_AREA_SIZE;
|
2023-10-21 03:47:45 +08:00
|
|
|
|
2019-08-30 11:59:58 +08:00
|
|
|
InternalChildren = new[]
|
|
|
|
{
|
2020-07-22 18:06:39 +08:00
|
|
|
layerNd = new Sprite
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2020-07-22 18:06:39 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-10-21 04:54:29 +08:00
|
|
|
Texture = skin.GetTexture("sliderb-nd")?.WithMaximumSize(maxSize),
|
2019-08-30 11:59:58 +08:00
|
|
|
Colour = new Color4(5, 5, 5, 255),
|
|
|
|
},
|
2023-10-21 04:54:29 +08:00
|
|
|
ball = skin.GetAnimation("sliderb", true, true, animationSeparator: "", frameLength: ballAnimationRate, maxSize: maxSize).AsNonNull().With(d =>
|
2020-07-22 18:06:39 +08:00
|
|
|
{
|
|
|
|
d.Anchor = Anchor.Centre;
|
|
|
|
d.Origin = Anchor.Centre;
|
2023-10-21 04:54:29 +08:00
|
|
|
d.Colour = ballColour;
|
|
|
|
}),
|
2020-07-22 18:06:39 +08:00
|
|
|
layerSpec = new Sprite
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2020-07-22 18:06:39 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-10-21 04:54:29 +08:00
|
|
|
Texture = skin.GetTexture("sliderb-spec")?.WithMaximumSize(maxSize),
|
2019-08-30 11:59:58 +08:00
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
},
|
|
|
|
};
|
2022-07-02 12:12:36 +08:00
|
|
|
}
|
2022-07-02 09:21:03 +08:00
|
|
|
|
2022-10-20 08:32:04 +08:00
|
|
|
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
|
|
|
|
|
2022-07-02 12:12:36 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-07-02 12:36:41 +08:00
|
|
|
if (parentObject != null)
|
2022-07-02 12:12:36 +08:00
|
|
|
{
|
2022-07-02 12:36:41 +08:00
|
|
|
parentObject.ApplyCustomUpdateState += updateStateTransforms;
|
|
|
|
updateStateTransforms(parentObject, parentObject.State.Value);
|
2022-10-20 08:32:04 +08:00
|
|
|
|
|
|
|
if (skin.GetConfig<SkinConfiguration.LegacySetting, bool>(SkinConfiguration.LegacySetting.AllowSliderBallTint)?.Value == true)
|
|
|
|
{
|
|
|
|
accentColour.BindTo(parentObject.AccentColour);
|
2023-10-21 03:47:45 +08:00
|
|
|
accentColour.BindValueChanged(a => ball.Colour = a.NewValue, true);
|
2022-10-20 08:32:04 +08:00
|
|
|
}
|
2022-07-02 12:12:36 +08:00
|
|
|
}
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
2020-07-22 18:06:39 +08:00
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
//undo rotation on layers which should not be rotated.
|
2023-10-17 16:40:44 +08:00
|
|
|
float appliedRotation = Parent!.Rotation;
|
2020-07-22 18:06:39 +08:00
|
|
|
|
|
|
|
layerNd.Rotation = -appliedRotation;
|
|
|
|
layerSpec.Rotation = -appliedRotation;
|
|
|
|
}
|
2022-07-02 09:21:03 +08:00
|
|
|
|
2022-07-02 12:36:41 +08:00
|
|
|
private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState _)
|
2022-07-02 09:21:03 +08:00
|
|
|
{
|
2022-07-02 12:19:54 +08:00
|
|
|
// Gets called by slider ticks, tails, etc., leading to duplicated
|
|
|
|
// animations which in this case have no visual impact (due to
|
|
|
|
// instant fade) but may negatively affect performance
|
2022-07-02 12:36:41 +08:00
|
|
|
if (drawableObject is not DrawableSlider)
|
2022-07-02 12:19:54 +08:00
|
|
|
return;
|
|
|
|
|
2022-07-02 12:22:48 +08:00
|
|
|
using (BeginAbsoluteSequence(drawableObject.StateUpdateTime))
|
2022-07-02 09:21:03 +08:00
|
|
|
this.FadeIn();
|
|
|
|
|
2022-07-02 12:22:48 +08:00
|
|
|
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
|
2022-07-02 09:21:03 +08:00
|
|
|
this.FadeOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2022-07-02 12:36:41 +08:00
|
|
|
if (parentObject != null)
|
|
|
|
parentObject.ApplyCustomUpdateState -= updateStateTransforms;
|
2022-07-02 09:21:03 +08:00
|
|
|
}
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
|
|
|
}
|