2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-03 20:56:35 +08:00
|
|
|
|
|
2017-02-13 03:38:05 +08:00
|
|
|
|
using OpenTK;
|
2016-11-28 15:52:57 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
2017-02-13 03:38:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-02-16 16:02:36 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-09-06 16:02:13 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
2017-12-01 23:26:02 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2018-01-23 12:37:25 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-12-31 04:23:18 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2016-11-17 16:20:51 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2017-02-14 09:22:28 +08:00
|
|
|
|
public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2017-12-28 22:36:27 +08:00
|
|
|
|
private readonly Slider slider;
|
2018-01-18 20:06:47 +08:00
|
|
|
|
private readonly List<Drawable> components = new List<Drawable>();
|
2016-11-28 11:40:24 +08:00
|
|
|
|
|
2018-01-30 15:24:23 +08:00
|
|
|
|
public readonly DrawableHitCircle HeadCircle;
|
2017-12-27 00:25:18 +08:00
|
|
|
|
public readonly SliderBody Body;
|
|
|
|
|
public readonly SliderBall Ball;
|
2016-12-06 23:02:27 +08:00
|
|
|
|
|
2017-12-30 14:21:25 +08:00
|
|
|
|
public DrawableSlider(Slider s)
|
|
|
|
|
: base(s)
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2017-12-28 22:36:27 +08:00
|
|
|
|
slider = s;
|
2016-11-27 22:36:31 +08:00
|
|
|
|
|
2018-01-30 15:24:23 +08:00
|
|
|
|
DrawableSliderTail tail;
|
|
|
|
|
Container<DrawableSliderTick> ticks;
|
|
|
|
|
Container<DrawableRepeatPoint> repeatPoints;
|
|
|
|
|
|
2016-11-28 11:40:24 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-28 11:15:25 +08:00
|
|
|
|
{
|
2017-12-27 00:25:18 +08:00
|
|
|
|
Body = new SliderBody(s)
|
2016-11-29 02:04:03 +08:00
|
|
|
|
{
|
2017-03-23 16:11:51 +08:00
|
|
|
|
AccentColour = AccentColour,
|
2017-02-09 15:29:21 +08:00
|
|
|
|
Position = s.StackedPosition,
|
2017-02-06 21:17:29 +08:00
|
|
|
|
PathWidth = s.Scale * 64,
|
2016-12-11 17:11:22 +08:00
|
|
|
|
},
|
2017-02-16 16:02:36 +08:00
|
|
|
|
ticks = new Container<DrawableSliderTick>(),
|
2017-09-27 23:28:44 +08:00
|
|
|
|
repeatPoints = new Container<DrawableRepeatPoint>(),
|
2017-12-27 00:25:18 +08:00
|
|
|
|
Ball = new SliderBall(s)
|
2016-12-11 17:11:22 +08:00
|
|
|
|
{
|
|
|
|
|
Scale = new Vector2(s.Scale),
|
2017-11-09 13:04:59 +08:00
|
|
|
|
AccentColour = AccentColour,
|
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
Alpha = 0
|
2016-11-29 02:04:03 +08:00
|
|
|
|
},
|
2018-01-30 15:24:23 +08:00
|
|
|
|
HeadCircle = new DrawableHitCircle(s.HeadCircle),
|
|
|
|
|
tail = new DrawableSliderTail(s.TailCircle)
|
2016-11-28 11:40:24 +08:00
|
|
|
|
};
|
2016-11-17 20:29:35 +08:00
|
|
|
|
|
2017-12-27 00:25:18 +08:00
|
|
|
|
components.Add(Body);
|
|
|
|
|
components.Add(Ball);
|
2017-02-16 16:02:36 +08:00
|
|
|
|
|
2018-01-30 14:50:48 +08:00
|
|
|
|
AddNested(HeadCircle);
|
2017-02-16 16:02:36 +08:00
|
|
|
|
|
2018-01-30 15:24:23 +08:00
|
|
|
|
AddNested(tail);
|
|
|
|
|
components.Add(tail);
|
2017-02-16 16:02:36 +08:00
|
|
|
|
|
2017-12-22 20:42:54 +08:00
|
|
|
|
foreach (var tick in s.NestedHitObjects.OfType<SliderTick>())
|
2017-02-16 16:02:36 +08:00
|
|
|
|
{
|
|
|
|
|
var drawableTick = new DrawableSliderTick(tick)
|
|
|
|
|
{
|
2018-01-25 17:52:03 +08:00
|
|
|
|
Position = tick.Position
|
2017-02-16 16:02:36 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ticks.Add(drawableTick);
|
2018-01-30 15:24:23 +08:00
|
|
|
|
components.Add(drawableTick);
|
2017-02-16 16:02:36 +08:00
|
|
|
|
AddNested(drawableTick);
|
|
|
|
|
}
|
2017-09-27 00:13:34 +08:00
|
|
|
|
|
2017-12-22 20:42:54 +08:00
|
|
|
|
foreach (var repeatPoint in s.NestedHitObjects.OfType<RepeatPoint>())
|
2017-09-27 00:13:34 +08:00
|
|
|
|
{
|
2017-09-27 23:28:44 +08:00
|
|
|
|
var drawableRepeatPoint = new DrawableRepeatPoint(repeatPoint, this)
|
2017-09-27 00:13:34 +08:00
|
|
|
|
{
|
2018-01-22 19:36:38 +08:00
|
|
|
|
Position = repeatPoint.Position
|
2017-09-27 00:13:34 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-27 23:28:44 +08:00
|
|
|
|
repeatPoints.Add(drawableRepeatPoint);
|
2018-01-18 20:06:47 +08:00
|
|
|
|
components.Add(drawableRepeatPoint);
|
2017-09-27 23:28:44 +08:00
|
|
|
|
AddNested(drawableRepeatPoint);
|
2017-09-27 00:13:34 +08:00
|
|
|
|
}
|
2016-12-03 20:56:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:37:25 +08:00
|
|
|
|
private int currentSpan;
|
2017-09-27 00:13:34 +08:00
|
|
|
|
public bool Tracking;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
protected override void Update()
|
2016-11-17 20:29:35 +08:00
|
|
|
|
{
|
2016-12-06 17:54:32 +08:00
|
|
|
|
base.Update();
|
2016-11-17 16:20:51 +08:00
|
|
|
|
|
2017-12-27 00:25:18 +08:00
|
|
|
|
Tracking = Ball.Tracking;
|
2017-09-27 00:13:34 +08:00
|
|
|
|
|
2017-12-28 22:36:27 +08:00
|
|
|
|
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
2016-11-28 15:31:19 +08:00
|
|
|
|
|
2018-01-23 12:37:25 +08:00
|
|
|
|
int span = slider.SpanAt(progress);
|
2017-12-28 22:36:27 +08:00
|
|
|
|
progress = slider.ProgressAt(progress);
|
2016-11-28 15:31:19 +08:00
|
|
|
|
|
2018-01-23 12:37:25 +08:00
|
|
|
|
if (span > currentSpan)
|
|
|
|
|
currentSpan = span;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
|
2016-12-07 13:52:34 +08:00
|
|
|
|
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
|
2018-01-30 15:28:38 +08:00
|
|
|
|
if (!HeadCircle.IsHit)
|
2018-01-30 14:50:48 +08:00
|
|
|
|
HeadCircle.Position = slider.Curve.PositionAt(progress);
|
2016-12-06 23:02:27 +08:00
|
|
|
|
|
2018-01-23 12:37:25 +08:00
|
|
|
|
foreach (var c in components.OfType<ISliderProgress>()) c.UpdateProgress(progress, span);
|
2018-01-18 20:06:47 +08:00
|
|
|
|
foreach (var c in components.OfType<ITrackSnaking>()) c.UpdateSnakingPosition(slider.Curve.PositionAt(Body.SnakedStart ?? 0), slider.Curve.PositionAt(Body.SnakedEnd ?? 0));
|
2018-01-30 15:24:23 +08:00
|
|
|
|
foreach (var t in components.OfType<IRequireTracking>()) t.Tracking = Ball.Tracking;
|
2016-12-03 21:40:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 16:02:13 +08:00
|
|
|
|
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
|
2016-11-29 20:40:24 +08:00
|
|
|
|
{
|
2017-12-28 22:36:27 +08:00
|
|
|
|
if (!userTriggered && Time.Current >= slider.EndTime)
|
2016-11-29 20:40:24 +08:00
|
|
|
|
{
|
2018-01-30 15:24:23 +08:00
|
|
|
|
var judgementsCount = NestedHitObjects.Count;
|
|
|
|
|
var judgementsHit = NestedHitObjects.Count(h => h.IsHit);
|
2017-02-13 03:38:05 +08:00
|
|
|
|
|
2017-09-27 00:21:39 +08:00
|
|
|
|
var hitFraction = (double)judgementsHit / judgementsCount;
|
2018-01-30 14:50:48 +08:00
|
|
|
|
if (hitFraction == 1 && HeadCircle.Judgements.Any(j => j.Result == HitResult.Great))
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(new OsuJudgement { Result = HitResult.Great });
|
2018-01-30 14:50:48 +08:00
|
|
|
|
else if (hitFraction >= 0.5 && HeadCircle.Judgements.Any(j => j.Result >= HitResult.Good))
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(new OsuJudgement { Result = HitResult.Good });
|
2017-02-13 03:38:05 +08:00
|
|
|
|
else if (hitFraction > 0)
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(new OsuJudgement { Result = HitResult.Meh });
|
2017-02-13 03:38:05 +08:00
|
|
|
|
else
|
2017-09-06 16:02:13 +08:00
|
|
|
|
AddJudgement(new OsuJudgement { Result = HitResult.Miss });
|
2016-11-29 20:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 16:37:38 +08:00
|
|
|
|
protected override void UpdateCurrentState(ArmedState state)
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2017-12-27 00:25:18 +08:00
|
|
|
|
Ball.FadeIn();
|
2018-01-04 19:53:33 +08:00
|
|
|
|
Ball.ScaleTo(HitObject.Scale);
|
2016-12-08 20:07:20 +08:00
|
|
|
|
|
2017-12-28 22:36:27 +08:00
|
|
|
|
using (BeginDelayedSequence(slider.Duration, true))
|
2017-07-17 22:05:24 +08:00
|
|
|
|
{
|
2018-01-04 19:43:42 +08:00
|
|
|
|
const float fade_out_time = 450;
|
2017-03-17 14:30:19 +08:00
|
|
|
|
|
2018-01-04 19:47:42 +08:00
|
|
|
|
// intentionally pile on an extra FadeOut to make it happen much faster.
|
2018-01-04 19:43:42 +08:00
|
|
|
|
Ball.FadeOut(fade_out_time / 4, Easing.Out);
|
2017-03-17 14:30:19 +08:00
|
|
|
|
|
2018-01-04 19:10:13 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Hit:
|
2018-01-04 19:43:42 +08:00
|
|
|
|
Ball.ScaleTo(HitObject.Scale * 1.4f, fade_out_time, Easing.Out);
|
2018-01-04 19:10:13 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 19:47:42 +08:00
|
|
|
|
this.FadeOut(fade_out_time, Easing.OutQuint).Expire();
|
2017-07-17 22:05:24 +08:00
|
|
|
|
}
|
2016-11-17 16:20:51 +08:00
|
|
|
|
}
|
2017-02-14 09:22:28 +08:00
|
|
|
|
|
2018-01-30 14:50:48 +08:00
|
|
|
|
public Drawable ProxiedLayer => HeadCircle.ApproachCircle;
|
2017-12-01 23:26:02 +08:00
|
|
|
|
|
2018-02-12 15:02:42 +08:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => Body.ReceiveMouseInputAt(screenSpacePos);
|
|
|
|
|
|
2017-12-27 00:25:18 +08:00
|
|
|
|
public override Vector2 SelectionPoint => ToScreenSpace(Body.Position);
|
|
|
|
|
public override Quad SelectionQuad => Body.PathDrawQuad;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
2017-04-27 16:37:38 +08:00
|
|
|
|
}
|