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