1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 18:53:51 +08:00

Merge pull request #359 from Damnae/slider_ticks

Add slider ticks.
This commit is contained in:
Thomas Müller 2017-02-16 10:31:05 +01:00 committed by GitHub
commit e10c5644fe
11 changed files with 317 additions and 53 deletions

View File

@ -37,7 +37,7 @@ namespace osu.Desktop.VisualTests.Tests
playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; };
} }
HitObjectType mode = HitObjectType.Spinner; HitObjectType mode = HitObjectType.Slider;
BindableNumber<double> playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; BindableNumber<double> playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 };
private Container playfieldContainer; private Container playfieldContainer;
@ -75,6 +75,7 @@ namespace osu.Desktop.VisualTests.Tests
Length = 400, Length = 400,
Position = new Vector2(-200, 0), Position = new Vector2(-200, 0),
Velocity = 1, Velocity = 1,
TickDistance = 100,
})); }));
break; break;
case HitObjectType.Spinner: case HitObjectType.Spinner:

View File

@ -84,18 +84,18 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
double hitOffset = Math.Abs(Judgement.TimeOffset); double hitOffset = Math.Abs(Judgement.TimeOffset);
OsuJudgementInfo osuJudgement = Judgement as OsuJudgementInfo;
if (hitOffset < hit50) if (hitOffset < hit50)
{ {
Judgement.Result = HitResult.Hit; Judgement.Result = HitResult.Hit;
OsuJudgementInfo osuInfo = Judgement as OsuJudgementInfo;
if (hitOffset < hit300) if (hitOffset < hit300)
osuInfo.Score = OsuScoreResult.Hit300; osuJudgement.Score = OsuScoreResult.Hit300;
else if (hitOffset < hit100) else if (hitOffset < hit100)
osuInfo.Score = OsuScoreResult.Hit100; osuJudgement.Score = OsuScoreResult.Hit100;
else if (hitOffset < hit50) else if (hitOffset < hit50)
osuInfo.Score = OsuScoreResult.Hit50; osuJudgement.Score = OsuScoreResult.Hit50;
} }
else else
Judgement.Result = HitResult.Miss; Judgement.Result = HitResult.Miss;

View File

@ -4,7 +4,6 @@
using System.ComponentModel; using System.ComponentModel;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Framework.Graphics;
namespace osu.Game.Modes.Osu.Objects.Drawables namespace osu.Game.Modes.Osu.Objects.Drawables
{ {
@ -19,7 +18,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
{ {
} }
public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo(); public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 };
protected override void UpdateState(ArmedState state) protected override void UpdateState(ArmedState state)
{ {
@ -49,7 +48,37 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
public class OsuJudgementInfo : PositionalJudgementInfo public class OsuJudgementInfo : PositionalJudgementInfo
{ {
/// <summary>
/// The score the user achieved.
/// </summary>
public OsuScoreResult Score; public OsuScoreResult Score;
/// <summary>
/// The score which would be achievable on a perfect hit.
/// </summary>
public OsuScoreResult MaxScore = OsuScoreResult.Hit300;
public int ScoreValue => scoreToInt(Score);
public int MaxScoreValue => scoreToInt(MaxScore);
private int scoreToInt(OsuScoreResult result)
{
switch (result)
{
default:
return 0;
case OsuScoreResult.Hit50:
return 50;
case OsuScoreResult.Hit100:
return 100;
case OsuScoreResult.Hit300:
return 300;
case OsuScoreResult.SliderTick:
return 10;
}
}
public ComboResult Combo; public ComboResult Combo;
} }
@ -73,5 +102,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
Hit100, Hit100,
[Description(@"300")] [Description(@"300")]
Hit300, Hit300,
[Description(@"10")]
SliderTick
} }
} }

View File

@ -1,11 +1,13 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using OpenTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables.Pieces; using osu.Game.Modes.Osu.Objects.Drawables.Pieces;
using OpenTK; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Modes.Osu.Objects.Drawables namespace osu.Game.Modes.Osu.Objects.Drawables
{ {
@ -17,6 +19,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
private List<ISliderProgress> components = new List<ISliderProgress>(); private List<ISliderProgress> components = new List<ISliderProgress>();
private Container<DrawableSliderTick> ticks;
SliderBody body; SliderBody body;
SliderBall ball; SliderBall ball;
@ -33,6 +37,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
Position = s.StackedPosition, Position = s.StackedPosition,
PathWidth = s.Scale * 64, PathWidth = s.Scale * 64,
}, },
ticks = new Container<DrawableSliderTick>(),
bouncer1 = new SliderBouncer(s, false) bouncer1 = new SliderBouncer(s, false)
{ {
Position = s.Curve.PositionAt(1), Position = s.Curve.PositionAt(1),
@ -63,6 +68,26 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
components.Add(ball); components.Add(ball);
components.Add(bouncer1); components.Add(bouncer1);
components.Add(bouncer2); components.Add(bouncer2);
AddNested(initialCircle);
var repeatDuration = s.Curve.Length / s.Velocity;
foreach (var tick in s.Ticks)
{
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);
}
} }
// Since the DrawableSlider itself is just a container without a size we need to // Since the DrawableSlider itself is just a container without a size we need to
@ -96,7 +121,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
if (initialCircle.Judgement?.Result != HitResult.Hit) if (initialCircle.Judgement?.Result != HitResult.Hit)
initialCircle.Position = slider.Curve.PositionAt(progress); initialCircle.Position = slider.Curve.PositionAt(progress);
components.ForEach(c => c.UpdateProgress(progress, repeat)); foreach (var c in components) c.UpdateProgress(progress, repeat);
foreach (var t in ticks.Children) t.Tracking = ball.Tracking;
} }
protected override void CheckJudgement(bool userTriggered) protected override void CheckJudgement(bool userTriggered)
@ -106,8 +132,22 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
if (!userTriggered && Time.Current >= HitObject.EndTime) if (!userTriggered && Time.Current >= HitObject.EndTime)
{ {
j.Score = sc.Score; var ticksCount = ticks.Children.Count() + 1;
j.Result = sc.Result; var ticksHit = ticks.Children.Count(t => t.Judgement.Result == HitResult.Hit);
if (sc.Result == HitResult.Hit)
ticksHit++;
var hitFraction = (double)ticksHit / ticksCount;
if (hitFraction == 1 && sc.Score == OsuScoreResult.Hit300)
j.Score = OsuScoreResult.Hit300;
else if (hitFraction >= 0.5 && sc.Score >= OsuScoreResult.Hit100)
j.Score = OsuScoreResult.Hit100;
else if (hitFraction > 0)
j.Score = OsuScoreResult.Hit50;
else
j.Score = OsuScoreResult.Miss;
j.Result = j.Score != OsuScoreResult.Miss ? HitResult.Hit : HitResult.Miss;
} }
} }

View File

@ -0,0 +1,120 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Samples;
using osu.Game.Modes.Objects.Drawables;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Modes.Osu.Objects.Drawables
{
public class DrawableSliderTick : DrawableOsuHitObject
{
private SliderTick sliderTick;
public double FadeInTime;
public double FadeOutTime;
public bool Tracking;
public override bool RemoveWhenNotAlive => false;
public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.SliderTick };
public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick)
{
this.sliderTick = sliderTick;
Size = new Vector2(16) * sliderTick.Scale;
Masking = true;
CornerRadius = Size.X / 2;
Origin = Anchor.Centre;
BorderThickness = 2;
BorderColour = Color4.White;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = sliderTick.Colour,
Alpha = 0.3f,
}
};
}
private AudioSample sample;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower();
sample = audio.Sample.Get($@"Gameplay/{sampleSet}-slidertick");
}
protected override void PlaySample()
{
sample?.Play();
}
protected override void CheckJudgement(bool userTriggered)
{
var j = Judgement as OsuJudgementInfo;
if (Judgement.TimeOffset >= 0)
{
j.Result = Tracking ? HitResult.Hit : HitResult.Miss;
j.Score = Tracking ? OsuScoreResult.SliderTick : OsuScoreResult.Miss;
}
}
protected override void UpdatePreemptState()
{
var animIn = Math.Min(150, sliderTick.StartTime - FadeInTime);
ScaleTo(0.5f);
ScaleTo(1.2f, animIn);
FadeIn(animIn);
Delay(animIn);
ScaleTo(1, 150, EasingTypes.Out);
Delay(-animIn);
}
protected override void UpdateState(ArmedState state)
{
if (!IsLoaded) return;
base.UpdateState(state);
switch (state)
{
case ArmedState.Idle:
Delay(FadeOutTime - sliderTick.StartTime);
FadeOut();
break;
case ArmedState.Miss:
FadeOut(160);
FadeColour(Color4.Red, 80);
break;
case ArmedState.Hit:
FadeOut(120, EasingTypes.OutQuint);
ScaleTo(Scale * 1.5f, 120, EasingTypes.OutQuint);
break;
}
}
}
}

View File

@ -1,9 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Beatmaps;
using OpenTK; using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Samples;
using osu.Game.Beatmaps.Timing;
using System;
using System.Collections.Generic;
namespace osu.Game.Modes.Osu.Objects namespace osu.Game.Modes.Osu.Objects
{ {
@ -43,17 +46,70 @@ namespace osu.Game.Modes.Osu.Objects
} }
public double Velocity; public double Velocity;
public double TickDistance;
public override void SetDefaultsFromBeatmap(Beatmap beatmap) public override void SetDefaultsFromBeatmap(Beatmap beatmap)
{ {
base.SetDefaultsFromBeatmap(beatmap); base.SetDefaultsFromBeatmap(beatmap);
Velocity = 100 / beatmap.BeatLengthAt(StartTime, true) * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier; var baseDifficulty = beatmap.BeatmapInfo.BaseDifficulty;
ControlPoint overridePoint;
ControlPoint timingPoint = beatmap.TimingPointAt(StartTime, out overridePoint);
var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1;
var baseVelocity = 100 * baseDifficulty.SliderMultiplier;
Velocity = baseVelocity / (timingPoint.BeatLength * velocityAdjustment);
TickDistance = baseVelocity / (baseDifficulty.SliderTickRate * velocityAdjustment);
} }
public int RepeatCount = 1; public int RepeatCount = 1;
internal readonly SliderCurve Curve = new SliderCurve(); internal readonly SliderCurve Curve = new SliderCurve();
public IEnumerable<SliderTick> Ticks
{
get
{
if (TickDistance == 0) yield break;
var length = Curve.Length;
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
for (var repeat = 0; repeat < RepeatCount; repeat++)
{
var repeatStartTime = StartTime + repeat * repeatDuration;
var reversed = repeat % 2 == 1;
for (var d = tickDistance; d <= length; d += tickDistance)
{
if (d > length - minDistanceFromEnd)
break;
var distanceProgress = d / length;
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;
yield return new SliderTick
{
RepeatIndex = repeat,
StartTime = repeatStartTime + timeProgress * repeatDuration,
Position = Curve.PositionAt(distanceProgress),
StackHeight = StackHeight,
Scale = Scale,
Colour = Colour,
Sample = new HitSampleInfo
{
Type = SampleType.None,
Set = SampleSet.Soft,
},
};
}
}
}
}
} }
public enum CurveTypes public enum CurveTypes

View File

@ -0,0 +1,9 @@
using OpenTK;
namespace osu.Game.Modes.Osu.Objects
{
public class SliderTick : OsuHitObject
{
public int RepeatIndex { get; set; }
}
}

View File

@ -36,24 +36,8 @@ namespace osu.Game.Modes.Osu
foreach (OsuJudgementInfo j in Judgements) foreach (OsuJudgementInfo j in Judgements)
{ {
switch (j.Score) score += j.ScoreValue;
{ maxScore += j.MaxScoreValue;
case OsuScoreResult.Miss:
maxScore += 300;
break;
case OsuScoreResult.Hit50:
score += 50;
maxScore += 300;
break;
case OsuScoreResult.Hit100:
score += 100;
maxScore += 300;
break;
case OsuScoreResult.Hit300:
score += 300;
maxScore += 300;
break;
}
} }
TotalScore.Value = score; TotalScore.Value = score;

View File

@ -59,6 +59,7 @@
<Compile Include="Objects\Drawables\Pieces\GlowPiece.cs" /> <Compile Include="Objects\Drawables\Pieces\GlowPiece.cs" />
<Compile Include="Objects\Drawables\HitExplosion.cs" /> <Compile Include="Objects\Drawables\HitExplosion.cs" />
<Compile Include="Objects\Drawables\Pieces\NumberPiece.cs" /> <Compile Include="Objects\Drawables\Pieces\NumberPiece.cs" />
<Compile Include="Objects\Drawables\DrawableSliderTick.cs" />
<Compile Include="Objects\Drawables\Pieces\RingPiece.cs" /> <Compile Include="Objects\Drawables\Pieces\RingPiece.cs" />
<Compile Include="Objects\Drawables\Pieces\SliderBouncer.cs" /> <Compile Include="Objects\Drawables\Pieces\SliderBouncer.cs" />
<Compile Include="Objects\Drawables\Pieces\SpinnerDisc.cs" /> <Compile Include="Objects\Drawables\Pieces\SpinnerDisc.cs" />
@ -67,6 +68,7 @@
<Compile Include="Objects\Drawables\Pieces\SliderBody.cs" /> <Compile Include="Objects\Drawables\Pieces\SliderBody.cs" />
<Compile Include="Objects\OsuHitObjectParser.cs" /> <Compile Include="Objects\OsuHitObjectParser.cs" />
<Compile Include="Objects\SliderCurve.cs" /> <Compile Include="Objects\SliderCurve.cs" />
<Compile Include="Objects\SliderTick.cs" />
<Compile Include="OsuScore.cs" /> <Compile Include="OsuScore.cs" />
<Compile Include="OsuScoreProcessor.cs" /> <Compile Include="OsuScoreProcessor.cs" />
<Compile Include="UI\OsuComboCounter.cs" /> <Compile Include="UI\OsuComboCounter.cs" />

View File

@ -26,26 +26,31 @@ namespace osu.Game.Beatmaps
return 60000 / BeatLengthAt(time); return 60000 / BeatLengthAt(time);
} }
public double BeatLengthAt(double time, bool applyMultipliers = false) public double BeatLengthAt(double time)
{ {
int point = 0; ControlPoint overridePoint;
int samplePoint = 0; ControlPoint timingPoint = TimingPointAt(time, out overridePoint);
return timingPoint.BeatLength;
}
for (int i = 0; i < ControlPoints.Count; i++) public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint)
if (ControlPoints[i].Time <= time) {
overridePoint = null;
ControlPoint timingPoint = null;
foreach (var controlPoint in ControlPoints)
if (controlPoint.Time <= time)
{ {
if (ControlPoints[i].TimingChange) if (controlPoint.TimingChange)
point = i; {
else timingPoint = controlPoint;
samplePoint = i; overridePoint = null;
}
else overridePoint = controlPoint;
} }
else break;
double mult = 1; return timingPoint;
if (applyMultipliers && samplePoint > point)
mult = ControlPoints[samplePoint].VelocityAdjustment;
return ControlPoints[point].BeatLength * mult;
} }
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using osu.Framework; using osu.Framework;
@ -23,8 +24,6 @@ namespace osu.Game.Modes.Objects.Drawables
public bool Interactive = true; public bool Interactive = true;
public Container<DrawableHitObject> ChildObjects;
public JudgementInfo Judgement; public JudgementInfo Judgement;
public abstract JudgementInfo CreateJudgementInfo(); public abstract JudgementInfo CreateJudgementInfo();
@ -66,7 +65,7 @@ namespace osu.Game.Modes.Objects.Drawables
sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}");
} }
protected void PlaySample() protected virtual void PlaySample()
{ {
sample?.Play(); sample?.Play();
} }
@ -85,6 +84,19 @@ namespace osu.Game.Modes.Objects.Drawables
Expire(true); Expire(true);
} }
private List<DrawableHitObject> nestedHitObjects;
protected IEnumerable<DrawableHitObject> NestedHitObjects => nestedHitObjects;
protected void AddNested(DrawableHitObject h)
{
if (nestedHitObjects == null)
nestedHitObjects = new List<DrawableHitObject>();
h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ;
nestedHitObjects.Add(h);
}
/// <summary> /// <summary>
/// Process a hit of this hitobject. Carries out judgement. /// Process a hit of this hitobject. Carries out judgement.
/// </summary> /// </summary>
@ -119,7 +131,11 @@ namespace osu.Game.Modes.Objects.Drawables
protected virtual void CheckJudgement(bool userTriggered) protected virtual void CheckJudgement(bool userTriggered)
{ {
//todo: consider making abstract. if (NestedHitObjects != null)
{
foreach (var d in NestedHitObjects)
d.CheckJudgement(userTriggered);
}
} }
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()