1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 04:27:34 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySliderBall.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
4.8 KiB
C#
Raw Normal View History

// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
2020-12-04 19:21:53 +08:00
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
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)]
private DrawableHitObject? parentObject { get; set; }
2022-07-02 12:12:36 +08:00
private Sprite layerNd = null!;
private Drawable ball = null!;
2022-07-02 12:12:36 +08:00
private Sprite layerSpec = null!;
public Color4 BallColour => ball.Colour;
public LegacySliderBall(ISkin skin)
{
2021-06-08 11:10:14 +08:00
this.skin = skin;
2020-04-02 18:30:58 +08:00
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
2020-08-21 23:20:33 +08:00
var ballColour = skin.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SliderBall)?.Value ?? Color4.White;
double? ballAnimationRate = null;
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;
ballAnimationRate = Math.Max(
150 / stableSliderVelocity * LegacySkinExtensions.SIXTY_FRAME_TIME,
LegacySkinExtensions.SIXTY_FRAME_TIME);
}
Vector2 maxSize = OsuLegacySkinTransformer.MAX_FOLLOW_CIRCLE_AREA_SIZE;
InternalChildren = new[]
{
layerNd = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-nd")?.WithMaximumSize(maxSize),
Colour = new Color4(5, 5, 5, 255),
},
ball = skin.GetAnimation("sliderb", true, true, animationSeparator: "", frameLength: ballAnimationRate, maxSize: maxSize).AsNonNull().With(d =>
{
d.Anchor = Anchor.Centre;
d.Origin = Anchor.Centre;
d.Colour = ballColour;
}),
layerSpec = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-spec")?.WithMaximumSize(maxSize),
Blending = BlendingParameters.Additive,
},
};
2022-07-02 12:12:36 +08:00
}
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
2022-07-02 12:12:36 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
if (parentObject != null)
2022-07-02 12:12:36 +08:00
{
parentObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(parentObject, parentObject.State.Value);
if (skin.GetConfig<SkinConfiguration.LegacySetting, bool>(SkinConfiguration.LegacySetting.AllowSliderBallTint)?.Value == true)
{
accentColour.BindTo(parentObject.AccentColour);
accentColour.BindValueChanged(a => ball.Colour = a.NewValue, true);
}
2022-07-02 12:12:36 +08:00
}
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
//undo rotation on layers which should not be rotated.
float appliedRotation = Parent!.Rotation;
layerNd.Rotation = -appliedRotation;
layerSpec.Rotation = -appliedRotation;
}
private void updateStateTransforms(DrawableHitObject drawableObject, ArmedState _)
{
// 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
if (drawableObject is not DrawableSlider)
return;
2022-07-02 12:22:48 +08:00
using (BeginAbsoluteSequence(drawableObject.StateUpdateTime))
this.FadeIn();
2022-07-02 12:22:48 +08:00
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
this.FadeOut();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (parentObject != null)
parentObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
}