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