1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 17:57:29 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyReverseArrow.cs

97 lines
3.4 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.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public partial class LegacyReverseArrow : CompositeDrawable
{
[Resolved]
private DrawableHitObject drawableObject { get; set; } = null!;
private Drawable proxy = null!;
private Bindable<Color4> accentColour = null!;
private bool textureIsDefaultSkin;
private Drawable arrow = null!;
[BackgroundDependencyLoader]
private void load(ISkinSource skinSource)
{
AutoSizeAxes = Axes.Both;
string lookupName = new OsuSkinComponentLookup(OsuSkinComponents.ReverseArrow).LookupName;
2021-09-28 04:21:14 +08:00
var skin = skinSource.FindProvider(s => s.GetTexture(lookupName) != null);
2023-09-20 11:48:15 +08:00
InternalChild = arrow = (skin?.GetAnimation(lookupName, true, true, maxSize: OsuHitObject.OBJECT_DIMENSIONS) ?? Empty());
textureIsDefaultSkin = skin is ISkinTransformer transformer && transformer.Skin is DefaultLegacySkin;
drawableObject.ApplyCustomUpdateState += updateStateTransforms;
}
protected override void LoadComplete()
{
base.LoadComplete();
proxy = CreateProxy();
drawableObject.HitObjectApplied += onHitObjectApplied;
onHitObjectApplied(drawableObject);
accentColour = drawableObject.AccentColour.GetBoundCopy();
accentColour.BindValueChanged(c =>
{
arrow.Colour = textureIsDefaultSkin && c.NewValue.R + c.NewValue.G + c.NewValue.B > (600 / 255f) ? Color4.Black : Color4.White;
}, true);
}
private void onHitObjectApplied(DrawableHitObject drawableObject)
{
Debug.Assert(proxy.Parent == null);
// see logic in LegacySliderHeadHitCircle.
(drawableObject as DrawableSliderRepeat)?.DrawableSlider
.OverlayElementContainer.Add(proxy);
}
private void updateStateTransforms(DrawableHitObject hitObject, ArmedState state)
{
const double move_out_duration = 35;
const double move_in_duration = 250;
const double total = 300;
switch (state)
{
case ArmedState.Idle:
2023-10-02 18:22:24 +08:00
// TODO: rotate slightly if Version < 1 (aka UseNewLayout)
InternalChild.ScaleTo(1.3f, move_out_duration, Easing.Out)
.Then()
.ScaleTo(1f, move_in_duration, Easing.Out)
.Loop(total - (move_in_duration + move_out_duration));
break;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
drawableObject.HitObjectApplied -= onHitObjectApplied;
drawableObject.ApplyCustomUpdateState -= updateStateTransforms;
}
}
}