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.
|
|
|
|
|
2023-10-17 12:33:57 +00:00
|
|
|
using System;
|
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;
|
2023-10-02 13:28:33 +00:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
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;
|
2023-10-19 11:01:13 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
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-17 12:33:57 +00:00
|
|
|
private DrawableSliderRepeat drawableRepeat { 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]
|
2023-10-17 12:33:57 +00:00
|
|
|
private void load(DrawableHitObject drawableObject, ISkinSource skinSource)
|
2021-09-01 10:34:57 +00:00
|
|
|
{
|
2023-10-17 12:33:57 +00:00
|
|
|
drawableRepeat = (DrawableSliderRepeat)drawableObject;
|
|
|
|
|
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-10-19 11:01:13 +00:00
|
|
|
InternalChild = arrow = new Sprite
|
2023-10-03 03:32:52 +00:00
|
|
|
{
|
2023-10-19 11:01:13 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Texture = skin?.GetTexture(lookupName)?.WithMaximumSize(maxSize: OsuHitObject.OBJECT_DIMENSIONS * 2),
|
|
|
|
};
|
2023-10-03 03:32:52 +00:00
|
|
|
|
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-17 12:33:57 +00:00
|
|
|
drawableRepeat.HitObjectApplied += onHitObjectApplied;
|
|
|
|
onHitObjectApplied(drawableRepeat);
|
2021-09-18 14:27:30 +00:00
|
|
|
|
2023-10-17 12:33:57 +00:00
|
|
|
accentColour = drawableRepeat.AccentColour.GetBoundCopy();
|
2023-10-02 10:17:45 +00:00
|
|
|
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.
|
2023-10-17 12:33:57 +00:00
|
|
|
drawableRepeat.DrawableSlider.OverlayElementContainer.Add(proxy);
|
2021-09-18 14:27:30 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-10-17 12:33:57 +00:00
|
|
|
|
|
|
|
case ArmedState.Hit:
|
|
|
|
double animDuration = Math.Min(300, drawableRepeat.HitObject.SpanDuration);
|
|
|
|
InternalChild.ScaleTo(1.4f, animDuration, Easing.Out);
|
|
|
|
break;
|
2023-10-02 10:17:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-10-17 12:33:57 +00:00
|
|
|
if (drawableRepeat.IsNotNull())
|
2023-10-02 13:28:33 +00:00
|
|
|
{
|
2023-10-17 12:33:57 +00:00
|
|
|
drawableRepeat.HitObjectApplied -= onHitObjectApplied;
|
|
|
|
drawableRepeat.ApplyCustomUpdateState -= updateStateTransforms;
|
2023-10-02 13:28:33 +00:00
|
|
|
}
|
2021-09-01 10:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|