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.
|
|
|
|
|
2023-10-17 20:33:57 +08:00
|
|
|
using System;
|
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;
|
2023-10-02 21:28:33 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
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;
|
2023-10-19 19:01:13 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2025-01-02 17:36:58 +08:00
|
|
|
using osu.Framework.Utils;
|
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;
|
2025-01-02 17:36:58 +08:00
|
|
|
using osuTK;
|
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-17 20:33:57 +08:00
|
|
|
private DrawableSliderRepeat drawableRepeat { 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!;
|
|
|
|
|
2023-10-02 19:09:39 +08:00
|
|
|
private bool shouldRotate;
|
|
|
|
|
2021-09-19 00:24:36 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-10-17 20:33:57 +08:00
|
|
|
private void load(DrawableHitObject drawableObject, ISkinSource skinSource)
|
2021-09-01 18:34:57 +08:00
|
|
|
{
|
2024-01-17 18:27:44 +08:00
|
|
|
const string lookup_name = @"reversearrow";
|
|
|
|
|
2023-10-17 20:33:57 +08:00
|
|
|
drawableRepeat = (DrawableSliderRepeat)drawableObject;
|
|
|
|
|
2021-09-01 18:34:57 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2024-01-17 18:27:44 +08:00
|
|
|
var skin = skinSource.FindProvider(s => s.GetTexture(lookup_name) != null);
|
2023-05-03 11:37:07 +08:00
|
|
|
|
2023-10-19 19:01:13 +08:00
|
|
|
InternalChild = arrow = new Sprite
|
2023-10-03 11:32:52 +08:00
|
|
|
{
|
2023-10-19 19:01:13 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-01-17 18:27:44 +08:00
|
|
|
Texture = skin?.GetTexture(lookup_name)?.WithMaximumSize(maxSize: OsuHitObject.OBJECT_DIMENSIONS * 2),
|
2023-10-19 19:01:13 +08:00
|
|
|
};
|
2023-10-03 11:32:52 +08:00
|
|
|
|
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
|
|
|
|
2023-10-02 19:09:39 +08:00
|
|
|
shouldRotate = skinSource.GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version)?.Value <= 1;
|
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-17 20:33:57 +08:00
|
|
|
drawableRepeat.HitObjectApplied += onHitObjectApplied;
|
|
|
|
onHitObjectApplied(drawableRepeat);
|
2021-09-18 22:27:30 +08:00
|
|
|
|
2023-10-17 20:33:57 +08:00
|
|
|
accentColour = drawableRepeat.AccentColour.GetBoundCopy();
|
2023-10-02 18:17:45 +08:00
|
|
|
accentColour.BindValueChanged(c =>
|
|
|
|
{
|
2025-01-02 17:36:58 +08:00
|
|
|
arrow.Colour = textureIsDefaultSkin && c.NewValue.R + c.NewValue.G + c.NewValue.B > 600 / 255f ? Color4.Black : Color4.White;
|
2023-10-02 18:17:45 +08:00
|
|
|
}, 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.
|
2023-10-17 20:33:57 +08:00
|
|
|
drawableRepeat.DrawableSlider.OverlayElementContainer.Add(proxy);
|
2021-09-18 22:27:30 +08:00
|
|
|
}
|
|
|
|
|
2025-01-02 17:36:58 +08:00
|
|
|
protected override void Update()
|
2023-10-02 18:17:45 +08:00
|
|
|
{
|
2025-01-02 17:36:58 +08:00
|
|
|
base.Update();
|
2023-10-02 18:17:45 +08:00
|
|
|
|
2025-01-02 17:36:58 +08:00
|
|
|
if (Time.Current >= drawableRepeat.HitStateUpdateTime && drawableRepeat.State.Value == ArmedState.Hit)
|
|
|
|
{
|
|
|
|
double animDuration = Math.Min(300, drawableRepeat.HitObject.SpanDuration);
|
|
|
|
arrow.Scale = new Vector2(Interpolation.ValueAt(Time.Current, 1, 1.4f, drawableRepeat.HitStateUpdateTime, drawableRepeat.HitStateUpdateTime + animDuration, Easing.Out));
|
|
|
|
}
|
|
|
|
else
|
2023-10-02 18:17:45 +08:00
|
|
|
{
|
2025-01-02 17:36:58 +08:00
|
|
|
const double duration = 300;
|
|
|
|
const float rotation = 5.625f;
|
|
|
|
|
|
|
|
double loopCurrentTime = (Time.Current - drawableRepeat.AnimationStartTime.Value) % duration;
|
|
|
|
|
2025-01-07 15:54:11 +08:00
|
|
|
// Reference: https://github.com/peppy/osu-stable-reference/blob/2280c4c436f80d04f9c79d3c905db00ac2902273/osu!/GameplayElements/HitObjects/Osu/HitCircleSliderEnd.cs#L79-L96
|
2025-01-02 17:36:58 +08:00
|
|
|
if (shouldRotate)
|
2025-01-07 15:54:11 +08:00
|
|
|
{
|
2025-01-02 17:36:58 +08:00
|
|
|
arrow.Rotation = Interpolation.ValueAt(loopCurrentTime, rotation, -rotation, 0, duration);
|
2025-01-07 15:54:11 +08:00
|
|
|
arrow.Scale = new Vector2(Interpolation.ValueAt(loopCurrentTime, 1.3f, 1, 0, duration));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arrow.Scale = new Vector2(Interpolation.ValueAt(loopCurrentTime, 1.3f, 1, 0, duration, Easing.Out));
|
|
|
|
}
|
2023-10-02 18:17:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-10-17 20:33:57 +08:00
|
|
|
if (drawableRepeat.IsNotNull())
|
2023-10-02 21:28:33 +08:00
|
|
|
{
|
2023-10-17 20:33:57 +08:00
|
|
|
drawableRepeat.HitObjectApplied -= onHitObjectApplied;
|
2023-10-02 21:28:33 +08:00
|
|
|
}
|
2021-09-01 18:34:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|