1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 22:27:39 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs

168 lines
6.5 KiB
C#
Raw Normal View History

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