diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 882628642b..21f00c003b 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -11,13 +11,14 @@ using osu.Framework.Graphics.Colour; using osu.Game.Graphics; using osu.Game.Rulesets.Objects.Drawables; using System; +using System.Linq; using osu.Framework.Input.Bindings; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.UI.Scrolling; namespace osu.Game.Rulesets.Mania.UI { - public class Column : ScrollingPlayfield, IHasAccentColour + public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasAccentColour { private const float key_icon_size = 10; private const float key_icon_corner_radius = 3; @@ -259,5 +260,26 @@ namespace osu.Game.Rulesets.Mania.UI public bool OnPressed(ManiaAction action) => Pressed?.Invoke(action) ?? false; public bool OnReleased(ManiaAction action) => Released?.Invoke(action) ?? false; } + + public bool OnPressed(ManiaAction action) + { + // Play the sounds of the next hitobject + if (HitObjects.AliveObjects.Any()) + { + // If there are alive hitobjects, we can abuse the fact that AliveObjects are sorted by time (see: Add()) + HitObjects.AliveObjects.First().PlaySamples(); + } + else + { + // If not, we do a slow search - we might want to do a BinarySearch here if this becomes problematic + // We fallback to LastOrDefault() if we're beyond the last note in the map + var hitObject = HitObjects.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ?? HitObjects.Objects.LastOrDefault(); + hitObject?.PlaySamples(); + } + + return false; + } + + public bool OnReleased(ManiaAction action) => false; } } diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 8680ff4e83..2db02724ed 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -136,7 +136,10 @@ namespace osu.Game.Rulesets.Objects.Drawables /// public event Action ApplyCustomUpdateState; - protected void PlaySamples() => Samples.ForEach(s => s?.Play()); + /// + /// Plays all the hitsounds for this . + /// + public void PlaySamples() => Samples.ForEach(s => s?.Play()); protected override void Update() {