From 391767e01d97f3be907255a98dab24a55bfad920 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 8 Dec 2016 19:54:22 +0900 Subject: [PATCH 1/5] Add very basic hitsound support. --- osu-resources | 2 +- .../Objects/Drawables/DrawableSlider.cs | 13 ++++++++++-- .../Objects/Drawables/Pieces/SliderBall.cs | 2 +- .../Objects/OsuHitObjectParser.cs | 5 ++++- .../Objects/Drawables/DrawableHitObject.cs | 20 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/osu-resources b/osu-resources index 73ddad1f01..e24414a277 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 73ddad1f01f223c6c311f1302ed1658a2320813d +Subproject commit e24414a277e407ae2438e4b6d9fa9c7992dd6485 diff --git a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs index e0af180e95..d5167f013b 100644 --- a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs @@ -18,13 +18,12 @@ namespace osu.Game.Modes.Osu.Objects.Drawables private List components = new List(); SliderBody body; + SliderBall ball; SliderBouncer bouncer1, bouncer2; public DrawableSlider(Slider s) : base(s) { - SliderBall ball; - slider = s; Origin = Anchor.TopLeft; @@ -46,6 +45,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables StartTime = s.StartTime, Position = s.Position, Colour = s.Colour, + Sample = s.Sample, }) { Depth = -1 //override time-based depth. @@ -58,6 +58,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables components.Add(bouncer2); } + int currentRepeat; + protected override void Update() { base.Update(); @@ -67,6 +69,13 @@ namespace osu.Game.Modes.Osu.Objects.Drawables int repeat = (int)(progress * slider.RepeatCount); progress = (progress * slider.RepeatCount) % 1; + if (repeat > currentRepeat) + { + if (ball.Tracking) + PlaySample(); + currentRepeat = repeat; + } + if (repeat % 2 == 1) progress = 1 - progress; diff --git a/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs b/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs index ce34ef7c22..c0e2030a80 100644 --- a/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs +++ b/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs @@ -84,7 +84,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces } bool tracking; - protected bool Tracking + public bool Tracking { get { return tracking; } set diff --git a/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs b/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs index 216c40b779..ad0e45ade3 100644 --- a/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs +++ b/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs @@ -101,7 +101,10 @@ namespace osu.Game.Modes.Osu.Objects } result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1])); result.StartTime = double.Parse(split[2]); - result.Sample = new HitSampleInfo { Type = (SampleType)int.Parse(split[4]) }; + result.Sample = new HitSampleInfo { + Type = (SampleType)Math.Max(1, int.Parse(split[4])), + Set = SampleSet.Soft, + }; result.NewCombo = combo; // TODO: "addition" field return result; diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 9b5c268696..c7e29b1cad 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -5,7 +5,11 @@ using System; using System.ComponentModel; using System.Diagnostics; using osu.Framework; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps.Samples; using OpenTK; using Container = osu.Framework.Graphics.Containers.Container; @@ -40,9 +44,25 @@ namespace osu.Game.Modes.Objects.Drawables state = value; UpdateState(state); + + if (State == ArmedState.Hit) + PlaySample(); } } + AudioSample sample; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + sample = audio.Sample.Get($@"Gameplay/{(HitObject.Sample.Set).ToString().ToLower()}-hit{HitObject.Sample.Type.ToString().ToLower()}"); + } + + protected void PlaySample() + { + sample?.Play(); + } + protected override void LoadComplete() { base.LoadComplete(); From c53743ca7deb615b52be53623ab5e5b1903a9bad Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 8 Dec 2016 20:00:24 +0900 Subject: [PATCH 2/5] Fix unit test regression. --- osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs | 2 +- osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs b/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs index ad0e45ade3..143aaecb44 100644 --- a/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs +++ b/osu.Game.Mode.Osu/Objects/OsuHitObjectParser.cs @@ -102,7 +102,7 @@ namespace osu.Game.Modes.Osu.Objects result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1])); result.StartTime = double.Parse(split[2]); result.Sample = new HitSampleInfo { - Type = (SampleType)Math.Max(1, int.Parse(split[4])), + Type = (SampleType)int.Parse(split[4]), Set = SampleSet.Soft, }; result.NewCombo = combo; diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index c7e29b1cad..06d25f8cdd 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -55,7 +55,10 @@ namespace osu.Game.Modes.Objects.Drawables [BackgroundDependencyLoader] private void load(AudioManager audio) { - sample = audio.Sample.Get($@"Gameplay/{(HitObject.Sample.Set).ToString().ToLower()}-hit{HitObject.Sample.Type.ToString().ToLower()}"); + string hitType = (HitObject.Sample.Type == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower(); + string sampleSet = HitObject.Sample.Set.ToString().ToLower(); + + sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); } protected void PlaySample() From 6cfb174f02c9e3db080e585332aabb161b12f3e9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 8 Dec 2016 20:03:18 +0900 Subject: [PATCH 3/5] Fix exiting results screen returning to player. --- osu.Game/Screens/Play/Player.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 8b1e18ac00..7e6f5d2b55 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -132,6 +132,7 @@ namespace osu.Game.Screens.Play Delay(1000); Schedule(delegate { + ValidForResume = false; Push(new Results { Score = scoreProcessor.GetScore() From f8395c4d3f07785e0e9d48524e7e9f368ea054a0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 8 Dec 2016 21:07:20 +0900 Subject: [PATCH 4/5] Fix slider ball not tracking when mouse hasn't been moved since slider appeared. --- .../Objects/Drawables/DrawableSlider.cs | 16 +++++++++++----- .../Objects/Drawables/Pieces/SliderBall.cs | 5 +++-- osu.Game.Mode.Osu/UI/OsuPlayfield.cs | 1 + .../Modes/Objects/Drawables/DrawableHitObject.cs | 1 - 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs index d5167f013b..9e0ad36dd7 100644 --- a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables.Pieces; using OpenTK; +using osu.Framework.Input; namespace osu.Game.Modes.Osu.Objects.Drawables { @@ -39,17 +40,14 @@ namespace osu.Game.Modes.Osu.Objects.Drawables }, bouncer1 = new SliderBouncer(slider, false) { Position = slider.Curve.PositionAt(1) }, bouncer2 = new SliderBouncer(slider, true) { Position = slider.Position }, - ball = new SliderBall(slider), initialCircle = new DrawableHitCircle(new HitCircle { StartTime = s.StartTime, Position = s.Position, Colour = s.Colour, Sample = s.Sample, - }) - { - Depth = -1 //override time-based depth. - }, + }), + ball = new SliderBall(slider), }; components.Add(body); @@ -104,14 +102,22 @@ namespace osu.Game.Modes.Osu.Objects.Drawables { base.UpdateInitialState(); body.Alpha = 1; + + //we need to be visible to handle input events. note that we still don't get enough events (we don't get a position if the mouse hasn't moved since the slider appeared). + ball.Alpha = 0.01f; } protected override void UpdateState(ArmedState state) { base.UpdateState(state); + ball.FadeIn(); + Delay(HitObject.Duration, true); + body.FadeOut(160); + ball.FadeOut(160); + FadeOut(800); } } diff --git a/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs b/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs index c0e2030a80..61ecc09301 100644 --- a/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs +++ b/osu.Game.Mode.Osu/Objects/Drawables/Pieces/SliderBall.cs @@ -98,17 +98,18 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces } } + private bool validTrackingTime => Time.Current >= slider.StartTime && Time.Current <= slider.EndTime; + protected override void Update() { base.Update(); CornerRadius = DrawWidth / 2; - Tracking = lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed; + Tracking = validTrackingTime && lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed; } public void UpdateProgress(double progress, int repeat) { - Alpha = Time.Current >= slider.StartTime && Time.Current <= slider.EndTime ? 1 : 0; Position = slider.Curve.PositionAt(progress); } } diff --git a/osu.Game.Mode.Osu/UI/OsuPlayfield.cs b/osu.Game.Mode.Osu/UI/OsuPlayfield.cs index 3ee3339f2a..9cf873dabf 100644 --- a/osu.Game.Mode.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Mode.Osu/UI/OsuPlayfield.cs @@ -51,6 +51,7 @@ namespace osu.Game.Modes.Osu.UI public override void Add(DrawableHitObject h) { + h.Depth = (float)h.HitObject.StartTime; DrawableHitCircle c = h as DrawableHitCircle; if (c != null) { diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 06d25f8cdd..94694b8d5e 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -30,7 +30,6 @@ namespace osu.Game.Modes.Objects.Drawables public DrawableHitObject(HitObject hitObject) { HitObject = hitObject; - Depth = (float)hitObject.StartTime; } private ArmedState state; From db5c2efa157fe4f7628f48864136cfe94edf814c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Dec 2016 18:12:35 +0900 Subject: [PATCH 5/5] Rename tracking variable and change conditional as per feedback. --- osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBall.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBall.cs b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBall.cs index 89df67757c..0df80984bb 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBall.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBall.cs @@ -98,14 +98,14 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces } } - private bool validTrackingTime => Time.Current >= slider.StartTime && Time.Current <= slider.EndTime; + private bool canCurrentlyTrack => Time.Current >= slider.StartTime && Time.Current < slider.EndTime; protected override void Update() { base.Update(); CornerRadius = DrawWidth / 2; - Tracking = validTrackingTime && lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed; + Tracking = canCurrentlyTrack && lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed; } public void UpdateProgress(double progress, int repeat)