2020-01-04 12:01:42 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-12-03 05:28:37 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2019-07-18 07:40:40 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-10-02 04:41:22 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-09 04:43:44 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-12-04 11:21:53 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2020-10-02 04:41:22 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2019-09-06 06:24:00 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
2021-04-26 06:22:17 +00:00
|
|
|
|
public class DrawableSliderRepeat : DrawableOsuHitObject, ITrackSnaking, IHasMainCirclePiece
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-11-12 06:59:48 +00:00
|
|
|
|
public new SliderRepeat HitObject => (SliderRepeat)base.HitObject;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-12-03 05:28:37 +00:00
|
|
|
|
[CanBeNull]
|
2020-12-03 11:10:16 +00:00
|
|
|
|
public Slider Slider => DrawableSlider?.HitObject;
|
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
protected DrawableSlider DrawableSlider => (DrawableSlider)ParentHitObject;
|
2020-12-03 05:28:37 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private double animDuration;
|
|
|
|
|
|
2021-04-25 23:39:18 +00:00
|
|
|
|
public SkinnableDrawable CirclePiece { get; private set; }
|
|
|
|
|
|
2021-04-26 06:22:42 +00:00
|
|
|
|
public ReverseArrowPiece Arrow { get; private set; }
|
|
|
|
|
|
2020-11-05 04:51:46 +00:00
|
|
|
|
private Drawable scaleContainer;
|
2020-10-02 09:41:28 +00:00
|
|
|
|
|
2020-07-22 10:30:10 +00:00
|
|
|
|
public override bool DisplayResult => false;
|
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
public DrawableSliderRepeat()
|
|
|
|
|
: base(null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawableSliderRepeat(SliderRepeat sliderRepeat)
|
2020-03-19 05:42:02 +00:00
|
|
|
|
: base(sliderRepeat)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-11-05 04:51:46 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-11-05 04:51:46 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Origin = Anchor.Centre;
|
2020-11-05 04:51:46 +00:00
|
|
|
|
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-10-02 04:41:22 +00:00
|
|
|
|
InternalChild = scaleContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2021-04-25 23:39:18 +00:00
|
|
|
|
Children = new Drawable[]
|
2020-10-02 04:41:22 +00:00
|
|
|
|
{
|
|
|
|
|
// no default for this; only visible in legacy skins.
|
2021-04-26 06:22:42 +00:00
|
|
|
|
CirclePiece = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SliderTailHitCircle), _ => Empty())
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
Arrow = new ReverseArrowPiece(),
|
2020-10-02 04:41:22 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 10:46:42 +00:00
|
|
|
|
protected override void OnApply()
|
2020-11-12 06:59:48 +00:00
|
|
|
|
{
|
2020-12-03 10:46:42 +00:00
|
|
|
|
base.OnApply();
|
2020-11-12 06:59:48 +00:00
|
|
|
|
|
2020-12-03 11:03:39 +00:00
|
|
|
|
Position = HitObject.Position - DrawableSlider.Position;
|
2019-07-18 07:40:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-11-12 06:59:48 +00:00
|
|
|
|
if (HitObject.StartTime <= Time.Current)
|
2020-12-03 11:03:39 +00:00
|
|
|
|
ApplyResult(r => r.Type = DrawableSlider.Tracking.Value ? r.Judgement.MaxResult : r.Judgement.MinResult);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 06:33:12 +00:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-11-12 06:59:48 +00:00
|
|
|
|
animDuration = Math.Min(300, HitObject.SpanDuration);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-07 03:55:05 +00:00
|
|
|
|
this.Animate(
|
|
|
|
|
d => d.FadeIn(animDuration),
|
|
|
|
|
d => d.ScaleTo(0.5f).ScaleTo(1f, animDuration * 2, Easing.OutElasticHalf)
|
|
|
|
|
);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 07:19:07 +00:00
|
|
|
|
protected override void UpdateHitStateTransforms(ArmedState state)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-11-04 07:19:07 +00:00
|
|
|
|
base.UpdateHitStateTransforms(state);
|
2019-09-13 09:49:21 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Idle:
|
|
|
|
|
this.Delay(HitObject.TimePreempt).FadeOut();
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ArmedState.Miss:
|
|
|
|
|
this.FadeOut(animDuration);
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ArmedState.Hit:
|
2021-04-26 06:22:42 +00:00
|
|
|
|
this.FadeOut(animDuration, Easing.Out);
|
|
|
|
|
|
2021-04-26 06:30:22 +00:00
|
|
|
|
const float final_scale = 1.5f;
|
|
|
|
|
|
|
|
|
|
Arrow.ScaleTo(Scale * final_scale, animDuration, Easing.Out);
|
|
|
|
|
CirclePiece.ScaleTo(Scale * final_scale, animDuration, Easing.Out);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 14:54:52 +00:00
|
|
|
|
private bool hasRotation;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public void UpdateSnakingPosition(Vector2 start, Vector2 end)
|
|
|
|
|
{
|
2020-03-30 09:35:01 +00:00
|
|
|
|
// When the repeat is hit, the arrow should fade out on spot rather than following the slider
|
2020-03-28 21:12:13 +00:00
|
|
|
|
if (IsHit) return;
|
|
|
|
|
|
2020-11-12 06:59:48 +00:00
|
|
|
|
bool isRepeatAtEnd = HitObject.RepeatIndex % 2 == 0;
|
2020-12-03 11:03:39 +00:00
|
|
|
|
List<Vector2> curve = ((PlaySliderBody)DrawableSlider.Body.Drawable).CurrentCurve;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
Position = isRepeatAtEnd ? end : start;
|
|
|
|
|
|
|
|
|
|
if (curve.Count < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int searchStart = isRepeatAtEnd ? curve.Count - 1 : 0;
|
|
|
|
|
int direction = isRepeatAtEnd ? -1 : 1;
|
|
|
|
|
|
2018-07-23 14:54:52 +00:00
|
|
|
|
Vector2 aimRotationVector = Vector2.Zero;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
// find the next vector2 in the curve which is not equal to our current position to infer a rotation.
|
|
|
|
|
for (int i = searchStart; i >= 0 && i < curve.Count; i += direction)
|
|
|
|
|
{
|
2018-06-18 15:22:01 +00:00
|
|
|
|
if (Precision.AlmostEquals(curve[i], Position))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2018-07-23 14:54:52 +00:00
|
|
|
|
aimRotationVector = curve[i];
|
2018-04-13 09:19:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-07-23 14:54:52 +00:00
|
|
|
|
|
2020-01-08 19:21:13 +00:00
|
|
|
|
float aimRotation = MathUtils.RadiansToDegrees(MathF.Atan2(aimRotationVector.Y - Position.Y, aimRotationVector.X - Position.X));
|
2021-04-26 06:22:42 +00:00
|
|
|
|
while (Math.Abs(aimRotation - Arrow.Rotation) > 180)
|
|
|
|
|
aimRotation += aimRotation < Arrow.Rotation ? 360 : -360;
|
2018-07-23 14:54:52 +00:00
|
|
|
|
|
2021-06-07 06:58:41 +00:00
|
|
|
|
// The clock may be paused in a scenario like the editor.
|
|
|
|
|
if (!hasRotation || !Clock.IsRunning)
|
2018-07-23 14:54:52 +00:00
|
|
|
|
{
|
2021-04-26 06:22:42 +00:00
|
|
|
|
Arrow.Rotation = aimRotation;
|
2018-07-23 14:54:52 +00:00
|
|
|
|
hasRotation = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-07-31 07:47:13 +00:00
|
|
|
|
// If we're already snaking, interpolate to smooth out sharp curves (linear sliders, mainly).
|
2021-04-26 06:22:42 +00:00
|
|
|
|
Arrow.Rotation = Interpolation.ValueAt(Math.Clamp(Clock.ElapsedFrameTime, 0, 100), Arrow.Rotation, aimRotation, 0, 50, Easing.OutQuint);
|
2018-07-23 14:54:52 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|