1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Merge pull request #1972 from smoogipoo/mania-stage-sounds

Make mania play the next note's sounds if no note is hit
This commit is contained in:
Dean Herbert 2018-01-25 01:21:31 +09:00 committed by GitHub
commit a9cf9ec5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -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<ManiaAction>, 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;
}
}

View File

@ -136,7 +136,10 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary>
public event Action<DrawableHitObject, ArmedState> ApplyCustomUpdateState;
protected void PlaySamples() => Samples.ForEach(s => s?.Play());
/// <summary>
/// Plays all the hitsounds for this <see cref="DrawableHitObject"/>.
/// </summary>
public void PlaySamples() => Samples.ForEach(s => s?.Play());
protected override void Update()
{