1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 07:07:25 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySliderBall.cs

104 lines
3.3 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 osu.Framework.Allocation;
2022-07-02 12:12:36 +08:00
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.Skinning;
using osuTK.Graphics;
2020-12-04 19:21:53 +08:00
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public class LegacySliderBall : CompositeDrawable
{
private readonly Drawable animationContent;
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? drawableObject { get; set; }
2022-07-02 12:12:36 +08:00
private Sprite layerNd = null!;
private Sprite layerSpec = null!;
2021-06-08 11:10:14 +08:00
public LegacySliderBall(Drawable animationContent, ISkin skin)
{
this.animationContent = animationContent;
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(DrawableHitObject dho)
{
2020-08-21 23:20:33 +08:00
var ballColour = skin.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SliderBall)?.Value ?? Color4.White;
InternalChildren = new[]
{
layerNd = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-nd"),
Colour = new Color4(5, 5, 5, 255),
},
2020-08-25 14:16:41 +08:00
LegacyColourCompatibility.ApplyWithDoubledAlpha(animationContent.With(d =>
{
d.Anchor = Anchor.Centre;
d.Origin = Anchor.Centre;
2020-08-25 14:16:41 +08:00
}), ballColour),
layerSpec = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-spec"),
Blending = BlendingParameters.Additive,
},
};
2022-07-02 12:12:36 +08:00
}
2022-07-02 12:12:36 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
if (drawableObject != null)
{
drawableObject.ApplyCustomUpdateState += updateStateTransforms;
updateStateTransforms(drawableObject, drawableObject.State.Value);
}
}
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 obj, ArmedState _)
{
2022-07-02 12:12:36 +08:00
using (BeginAbsoluteSequence(drawableObject.AsNonNull().StateUpdateTime))
this.FadeIn();
2022-07-02 12:12:36 +08:00
using (BeginAbsoluteSequence(drawableObject.AsNonNull().HitStateUpdateTime))
this.FadeOut();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2022-07-02 12:12:36 +08:00
if (drawableObject != null)
drawableObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
}