Skip to content

Commit

Permalink
Merge pull request #359 from Damnae/slider_ticks
Browse files Browse the repository at this point in the history
Add slider ticks.
  • Loading branch information
Tom94 committed Feb 16, 2017
2 parents d3335f7 + b55d85a commit e10c564
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 53 deletions.
3 changes: 2 additions & 1 deletion osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs
Expand Up @@ -37,7 +37,7 @@ public TestCaseHitObjects()
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 };
private Container playfieldContainer;
Expand Down Expand Up @@ -75,6 +75,7 @@ private void load(HitObjectType mode)
Length = 400,
Position = new Vector2(-200, 0),
Velocity = 1,
TickDistance = 100,
}));
break;
case HitObjectType.Spinner:
Expand Down
10 changes: 5 additions & 5 deletions osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs
Expand Up @@ -84,18 +84,18 @@ protected override void CheckJudgement(bool userTriggered)

double hitOffset = Math.Abs(Judgement.TimeOffset);

OsuJudgementInfo osuJudgement = Judgement as OsuJudgementInfo;

if (hitOffset < hit50)
{
Judgement.Result = HitResult.Hit;

OsuJudgementInfo osuInfo = Judgement as OsuJudgementInfo;

if (hitOffset < hit300)
osuInfo.Score = OsuScoreResult.Hit300;
osuJudgement.Score = OsuScoreResult.Hit300;
else if (hitOffset < hit100)
osuInfo.Score = OsuScoreResult.Hit100;
osuJudgement.Score = OsuScoreResult.Hit100;
else if (hitOffset < hit50)
osuInfo.Score = OsuScoreResult.Hit50;
osuJudgement.Score = OsuScoreResult.Hit50;
}
else
Judgement.Result = HitResult.Miss;
Expand Down
35 changes: 33 additions & 2 deletions osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs
Expand Up @@ -4,7 +4,6 @@
using System.ComponentModel;
using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables;
using osu.Framework.Graphics;

namespace osu.Game.Modes.Osu.Objects.Drawables
{
Expand All @@ -19,7 +18,7 @@ public DrawableOsuHitObject(OsuHitObject hitObject)
{
}

public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo();
public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 };

protected override void UpdateState(ArmedState state)
{
Expand Down Expand Up @@ -49,7 +48,37 @@ protected virtual void UpdateInitialState()

public class OsuJudgementInfo : PositionalJudgementInfo
{
/// <summary>
/// The score the user achieved.
/// </summary>
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;
}

Expand All @@ -73,5 +102,7 @@ public enum OsuScoreResult
Hit100,
[Description(@"300")]
Hit300,
[Description(@"10")]
SliderTick
}
}
50 changes: 45 additions & 5 deletions osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs
@@ -1,11 +1,13 @@
// 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.Collections.Generic;
using OpenTK;
using osu.Framework.Graphics;
using osu.Game.Modes.Objects.Drawables;
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
{
Expand All @@ -17,6 +19,8 @@ public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxie

private List<ISliderProgress> components = new List<ISliderProgress>();

private Container<DrawableSliderTick> ticks;

SliderBody body;
SliderBall ball;

Expand All @@ -33,6 +37,7 @@ public DrawableSlider(Slider s) : base(s)
Position = s.StackedPosition,
PathWidth = s.Scale * 64,
},
ticks = new Container<DrawableSliderTick>(),
bouncer1 = new SliderBouncer(s, false)
{
Position = s.Curve.PositionAt(1),
Expand Down Expand Up @@ -63,6 +68,26 @@ public DrawableSlider(Slider s) : base(s)
components.Add(ball);
components.Add(bouncer1);
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
Expand Down Expand Up @@ -96,7 +121,8 @@ protected override void Update()
if (initialCircle.Judgement?.Result != HitResult.Hit)
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)
Expand All @@ -106,8 +132,22 @@ protected override void CheckJudgement(bool userTriggered)

if (!userTriggered && Time.Current >= HitObject.EndTime)
{
j.Score = sc.Score;
j.Result = sc.Result;
var ticksCount = ticks.Children.Count() + 1;
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;
}
}

Expand Down
120 changes: 120 additions & 0 deletions osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs
@@ -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;
}
}
}
}

0 comments on commit e10c564

Please sign in to comment.