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

171 lines
6.7 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 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;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
{
private readonly Slider slider;
private readonly DrawableHitCircle initialCircle;
private readonly List<ISliderProgress> components = new List<ISliderProgress>();
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;
private readonly SliderBody body;
private readonly SliderBall ball;
public DrawableSlider(Slider s) : base(s)
{
2016-11-28 11:40:24 +08:00
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
},
initialCircle = new DrawableHitCircle(new HitCircle
2016-11-28 11:40:24 +08:00
{
2017-02-15 22:23:55 +08:00
//todo: avoid creating this temporary HitCircle.
2016-11-28 11:40:24 +08:00
StartTime = s.StartTime,
Position = s.StackedPosition,
2017-02-15 22:23:55 +08:00
ComboIndex = s.ComboIndex,
Scale = s.Scale,
ComboColour = s.ComboColour,
Samples = s.Samples,
SampleControlPoint = s.SampleControlPoint
})
2016-11-28 11:40:24 +08:00
};
2016-11-17 20:29:35 +08:00
components.Add(body);
components.Add(ball);
AddNested(initialCircle);
var repeatDuration = s.Curve.Distance / s.Velocity;
foreach (var tick in s.NestedHitObjects.OfType<SliderTick>())
{
var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration;
var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2);
var fadeOutTime = repeatStartTime + repeatDuration;
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 repeatStartTime = s.StartTime + repeatPoint.RepeatIndex * repeatDuration;
var fadeInTime = repeatStartTime + (repeatPoint.StartTime - repeatStartTime) / 2 - (repeatPoint.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2);
2017-09-27 00:13:34 +08:00
var fadeOutTime = repeatStartTime + repeatDuration;
2017-09-27 23:28:44 +08:00
var drawableRepeatPoint = new DrawableRepeatPoint(repeatPoint, this)
2017-09-27 00:13:34 +08:00
{
FadeInTime = fadeInTime,
FadeOutTime = fadeOutTime,
2017-09-27 23:28:44 +08:00
Position = repeatPoint.Position,
2017-09-27 00:13:34 +08:00
};
2017-09-27 23:28:44 +08:00
repeatPoints.Add(drawableRepeatPoint);
AddNested(drawableRepeatPoint);
2017-09-27 00:13:34 +08:00
}
}
2017-03-07 09:59:19 +08:00
private int currentRepeat;
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();
2017-09-27 00:13:34 +08:00
Tracking = ball.Tracking;
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
2016-11-28 15:31:19 +08:00
int repeat = slider.RepeatAt(progress);
progress = slider.ProgressAt(progress);
2016-11-28 15:31:19 +08:00
2016-12-08 18:54:22 +08:00
if (repeat > currentRepeat)
currentRepeat = repeat;
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
if (!initialCircle.Judgements.Any(j => j.IsHit))
initialCircle.Position = slider.Curve.PositionAt(progress);
foreach (var c in components) c.UpdateProgress(progress, repeat);
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 (initialCircle.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 && initialCircle.Judgements.Any(j => j.Result == HitResult.Great))
AddJudgement(new OsuJudgement { Result = HitResult.Great });
else if (hitFraction >= 0.5 && initialCircle.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();
using (BeginDelayedSequence(slider.Duration, true))
{
body.FadeOut(160);
ball.FadeOut(160);
this.FadeOut(800)
.Expire();
}
}
public Drawable ProxiedLayer => initialCircle.ApproachCircle;
public override Vector2 SelectionPoint => ToScreenSpace(body.Position);
public override Quad SelectionQuad => body.PathDrawQuad;
}
}