2021-09-01 10:34:57 +00: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.
|
|
|
|
|
2021-09-18 14:27:30 +00:00
|
|
|
using System.Diagnostics;
|
2021-09-01 10:34:57 +00:00
|
|
|
using osu.Framework.Allocation;
|
2023-05-03 03:37:07 +00:00
|
|
|
using osu.Framework.Bindables;
|
2021-09-01 10:34:57 +00:00
|
|
|
using osu.Framework.Graphics;
|
2023-10-02 10:17:45 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-09-01 10:34:57 +00:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2023-09-19 01:37:09 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2021-09-01 10:34:57 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Skinning;
|
2023-05-03 03:37:07 +00:00
|
|
|
using osuTK.Graphics;
|
2021-09-01 10:34:57 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|
|
|
{
|
2023-10-02 10:17:45 +00:00
|
|
|
public partial class LegacyReverseArrow : CompositeDrawable
|
2021-09-01 10:34:57 +00:00
|
|
|
{
|
2023-10-02 08:41:08 +00:00
|
|
|
[Resolved]
|
2023-10-02 10:17:45 +00:00
|
|
|
private DrawableHitObject drawableObject { get; set; } = null!;
|
2021-09-01 10:34:57 +00:00
|
|
|
|
2022-11-09 04:36:52 +00:00
|
|
|
private Drawable proxy = null!;
|
2021-09-18 14:27:30 +00:00
|
|
|
|
2023-05-03 03:37:07 +00:00
|
|
|
private Bindable<Color4> accentColour = null!;
|
|
|
|
|
|
|
|
private bool textureIsDefaultSkin;
|
|
|
|
|
|
|
|
private Drawable arrow = null!;
|
|
|
|
|
2023-10-02 11:09:39 +00:00
|
|
|
private bool shouldRotate;
|
|
|
|
|
2021-09-18 16:24:36 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-09-27 19:45:26 +00:00
|
|
|
private void load(ISkinSource skinSource)
|
2021-09-01 10:34:57 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2022-11-09 07:04:56 +00:00
|
|
|
string lookupName = new OsuSkinComponentLookup(OsuSkinComponents.ReverseArrow).LookupName;
|
2021-09-01 10:34:57 +00:00
|
|
|
|
2021-09-27 20:21:14 +00:00
|
|
|
var skin = skinSource.FindProvider(s => s.GetTexture(lookupName) != null);
|
2023-05-03 03:37:07 +00:00
|
|
|
|
2023-09-20 03:48:15 +00:00
|
|
|
InternalChild = arrow = (skin?.GetAnimation(lookupName, true, true, maxSize: OsuHitObject.OBJECT_DIMENSIONS) ?? Empty());
|
2023-05-03 03:37:07 +00:00
|
|
|
textureIsDefaultSkin = skin is ISkinTransformer transformer && transformer.Skin is DefaultLegacySkin;
|
2023-10-02 10:17:45 +00:00
|
|
|
|
|
|
|
drawableObject.ApplyCustomUpdateState += updateStateTransforms;
|
2023-10-02 11:09:39 +00:00
|
|
|
|
|
|
|
shouldRotate = skinSource.GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version)?.Value <= 1;
|
2021-09-01 10:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-09-18 14:27:30 +00:00
|
|
|
proxy = CreateProxy();
|
|
|
|
|
2023-10-02 10:17:45 +00:00
|
|
|
drawableObject.HitObjectApplied += onHitObjectApplied;
|
|
|
|
onHitObjectApplied(drawableObject);
|
2021-09-18 14:27:30 +00:00
|
|
|
|
2023-10-02 10:17:45 +00:00
|
|
|
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);
|
2023-10-02 08:41:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-18 14:27:30 +00:00
|
|
|
private void onHitObjectApplied(DrawableHitObject drawableObject)
|
|
|
|
{
|
|
|
|
Debug.Assert(proxy.Parent == null);
|
|
|
|
|
2021-09-01 10:34:57 +00:00
|
|
|
// see logic in LegacySliderHeadHitCircle.
|
2021-09-18 14:27:30 +00:00
|
|
|
(drawableObject as DrawableSliderRepeat)?.DrawableSlider
|
|
|
|
.OverlayElementContainer.Add(proxy);
|
|
|
|
}
|
|
|
|
|
2023-10-02 10:17:45 +00:00
|
|
|
private void updateStateTransforms(DrawableHitObject hitObject, ArmedState state)
|
|
|
|
{
|
2023-10-02 13:26:57 +00:00
|
|
|
const double duration = 300;
|
|
|
|
const float rotation = 5.625f;
|
2023-10-02 10:17:45 +00:00
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case ArmedState.Idle:
|
2023-10-02 11:09:39 +00:00
|
|
|
if (shouldRotate)
|
|
|
|
{
|
2023-10-02 13:26:57 +00:00
|
|
|
InternalChild.ScaleTo(1.3f)
|
|
|
|
.RotateTo(rotation)
|
2023-10-02 11:09:39 +00:00
|
|
|
.Then()
|
2023-10-02 13:26:57 +00:00
|
|
|
.ScaleTo(1f, duration)
|
|
|
|
.RotateTo(-rotation, duration)
|
|
|
|
.Loop();
|
2023-10-02 11:09:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-02 13:26:57 +00:00
|
|
|
InternalChild.ScaleTo(1.3f).Then()
|
|
|
|
.ScaleTo(1f, duration, Easing.Out)
|
|
|
|
.Loop();
|
2023-10-02 11:09:39 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 10:17:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-18 14:27:30 +00:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
2023-10-02 10:17:45 +00:00
|
|
|
|
|
|
|
drawableObject.HitObjectApplied -= onHitObjectApplied;
|
|
|
|
drawableObject.ApplyCustomUpdateState -= updateStateTransforms;
|
2021-09-01 10:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|