1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +08:00

Merge pull request #1627 from FreezyLemon/taiko-hitsounds-fix

Taiko playing hitsounds on click/keydown, not only on hitobjects being hit.
This commit is contained in:
Dan Balasescu 2017-12-23 20:02:51 +09:00 committed by GitHub
commit 40bb82fe75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 132 additions and 61 deletions

View File

@ -76,10 +76,10 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
Duration = endTime - HitObject.StartTime
};
hold.Head.Samples.Add(new SampleInfo
{
Name = SampleInfo.HIT_NORMAL
});
if (hold.Head.Samples == null)
hold.Head.Samples = new SampleInfoList();
hold.Head.Samples.Add(new SampleInfo { Name = SampleInfo.HIT_NORMAL });
hold.Tail.Samples = HitObject.Samples;

View File

@ -57,7 +57,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Scale = s.Scale,
ComboColour = s.ComboColour,
Samples = s.Samples,
SoundControlPoint = s.SoundControlPoint
SampleControlPoint = s.SampleControlPoint
})
};

View File

@ -67,7 +67,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
validKeyPressed = HitActions.Contains(action);
return UpdateJudgement(true);
// Only count this as handled if the new judgement is a hit
return UpdateJudgement(true) && Judgements.LastOrDefault()?.IsHit == true;
}
protected override void Update()

View File

@ -83,7 +83,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return false;
// Assume the intention was to hit the strong hit with both keys only if the first key is still being held down
return firstKeyHeld && UpdateJudgement(true);
return firstKeyHeld && UpdateJudgement(true) && Judgements.LastOrDefault()?.IsHit == true;
}
}
}

View File

@ -16,10 +16,17 @@ using osu.Framework.Extensions.Color4Extensions;
using System.Linq;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Framework.Input.Bindings;
using osu.Game.Beatmaps.ControlPoints;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using System.Collections.Generic;
using osu.Game.Audio;
using System;
namespace osu.Game.Rulesets.Taiko.UI
{
public class TaikoPlayfield : ScrollingPlayfield
public class TaikoPlayfield : ScrollingPlayfield, IKeyBindingHandler<TaikoAction>
{
/// <summary>
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="TaikoRulesetContainer"/>.
@ -54,9 +61,13 @@ namespace osu.Game.Rulesets.Taiko.UI
private readonly Box overlayBackground;
private readonly Box background;
public TaikoPlayfield()
private readonly ControlPointInfo controlPointInfo;
private Dictionary<SampleControlPoint, DrumSamples> drumSampleMappings;
public TaikoPlayfield(ControlPointInfo controlPointInfo)
: base(Axes.X)
{
this.controlPointInfo = controlPointInfo;
AddRangeInternal(new Drawable[]
{
backgroundContainer = new Container
@ -194,8 +205,19 @@ namespace osu.Game.Rulesets.Taiko.UI
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, AudioManager audio)
{
drumSampleMappings = new Dictionary<SampleControlPoint, DrumSamples>();
foreach (var s in controlPointInfo.SamplePoints)
{
drumSampleMappings.Add(s,
new DrumSamples
{
Centre = s.GetSampleInfo().GetChannel(audio.Sample),
Rim = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample)
});
}
overlayBackgroundContainer.BorderColour = colours.Gray0;
overlayBackground.Colour = colours.Gray1;
@ -249,7 +271,9 @@ namespace osu.Game.Rulesets.Taiko.UI
{
topLevelHitContainer.Add(judgedObject.CreateProxy());
}
catch { }
catch
{
}
}
hitExplosionContainer.Add(new HitExplosion(judgedObject, isRim));
@ -258,5 +282,28 @@ namespace osu.Game.Rulesets.Taiko.UI
kiaiExplosionContainer.Add(new KiaiHitExplosion(judgedObject, isRim));
}
}
public bool OnPressed(TaikoAction action)
{
var samplePoint = controlPointInfo.SamplePointAt(Clock.CurrentTime);
if (!drumSampleMappings.TryGetValue(samplePoint, out var samples))
throw new InvalidOperationException("Current sample set not found.");
if (action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre)
samples.Centre.Play();
else
samples.Rim.Play();
return true;
}
public bool OnReleased(TaikoAction action) => false;
private class DrumSamples
{
public SampleChannel Centre;
public SampleChannel Rim;
}
}
}

View File

@ -93,7 +93,7 @@ namespace osu.Game.Rulesets.Taiko.UI
public override PassThroughInputManager CreateInputManager() => new TaikoInputManager(Ruleset.RulesetInfo);
protected override Playfield CreatePlayfield() => new TaikoPlayfield
protected override Playfield CreatePlayfield() => new TaikoPlayfield(Beatmap.ControlPointInfo)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft

View File

@ -146,8 +146,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(116999, difficultyPoint.Time);
Assert.AreEqual(0.75000000000000189d, difficultyPoint.SpeedMultiplier);
Assert.AreEqual(34, controlPoints.SoundPoints.Count);
var soundPoint = controlPoints.SoundPoints[0];
Assert.AreEqual(34, controlPoints.SamplePoints.Count);
var soundPoint = controlPoints.SamplePoints[0];
Assert.AreEqual(956, soundPoint.Time);
Assert.AreEqual("soft", soundPoint.SampleBank);
Assert.AreEqual(60, soundPoint.SampleVolume);

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual
b.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = random.Next(0, length) });
for (int i = 0; i < random.Next(1, 5); i++)
b.ControlPointInfo.SoundPoints.Add(new SoundControlPoint { Time = random.Next(0, length) });
b.ControlPointInfo.SamplePoints.Add(new SampleControlPoint { Time = random.Next(0, length) });
b.BeatmapInfo.Bookmarks = new int[random.Next(10, 30)];
for (int i = 0; i < b.BeatmapInfo.Bookmarks.Length; i++)

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Audio.Sample;
namespace osu.Game.Audio
{
@ -13,6 +14,13 @@ namespace osu.Game.Audio
public const string HIT_NORMAL = @"hitnormal";
public const string HIT_CLAP = @"hitclap";
public SampleChannel GetChannel(SampleManager manager)
{
var channel = manager.Get($"Gameplay/{Bank}-{Name}");
channel.Volume.Value = Volume / 100.0;
return channel;
}
/// <summary>
/// The bank to load the sample from.
/// </summary>

View File

@ -28,7 +28,7 @@ namespace osu.Game.Beatmaps.ControlPoints
/// All sound points.
/// </summary>
[JsonProperty]
public SortedList<SoundControlPoint> SoundPoints { get; private set; } = new SortedList<SoundControlPoint>(Comparer<SoundControlPoint>.Default);
public SortedList<SampleControlPoint> SamplePoints { get; private set; } = new SortedList<SampleControlPoint>(Comparer<SampleControlPoint>.Default);
/// <summary>
/// All effect points.
@ -55,7 +55,7 @@ namespace osu.Game.Beatmaps.ControlPoints
/// </summary>
/// <param name="time">The time to find the sound control point at.</param>
/// <returns>The sound control point.</returns>
public SoundControlPoint SoundPointAt(double time) => binarySearch(SoundPoints, time);
public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault());
/// <summary>
/// Finds the timing control point that is active at <paramref name="time"/>.

View File

@ -0,0 +1,34 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Audio;
namespace osu.Game.Beatmaps.ControlPoints
{
public class SampleControlPoint : ControlPoint
{
public const string DEFAULT_BANK = "normal";
/// <summary>
/// The default sample bank at this control point.
/// </summary>
public string SampleBank = DEFAULT_BANK;
/// <summary>
/// The default sample volume at this control point.
/// </summary>
public int SampleVolume;
/// <summary>
/// Create a SampleInfo based on the sample settings in this control point.
/// </summary>
/// <param name="sampleName">The name of the same.</param>
/// <returns>A populated <see cref="SampleInfo"/>.</returns>
public SampleInfo GetSampleInfo(string sampleName = SampleInfo.HIT_NORMAL) => new SampleInfo
{
Bank = SampleBank,
Name = sampleName,
Volume = SampleVolume,
};
}
}

View File

@ -1,20 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.ControlPoints
{
public class SoundControlPoint : ControlPoint
{
public const string DEFAULT_BANK = "normal";
/// <summary>
/// The default sample bank at this control point.
/// </summary>
public string SampleBank = DEFAULT_BANK;
/// <summary>
/// The default sample volume at this control point.
/// </summary>
public int SampleVolume;
}
}

View File

@ -313,7 +313,7 @@ namespace osu.Game.Beatmaps.Formats
stringSampleSet = @"normal";
DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time);
SoundControlPoint soundPoint = beatmap.ControlPointInfo.SoundPointAt(time);
SampleControlPoint samplePoint = beatmap.ControlPointInfo.SamplePointAt(time);
EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time);
if (timingChange)
@ -336,9 +336,9 @@ namespace osu.Game.Beatmaps.Formats
});
}
if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume)
if (stringSampleSet != samplePoint.SampleBank || sampleVolume != samplePoint.SampleVolume)
{
beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint
beatmap.ControlPointInfo.SamplePoints.Add(new SampleControlPoint
{
Time = time,
SampleBank = stringSampleSet,

View File

@ -84,28 +84,29 @@ namespace osu.Game.Rulesets.Objects.Drawables
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
foreach (SampleInfo sample in HitObject.Samples)
if (HitObject.Samples != null)
{
if (HitObject.SoundControlPoint == null)
throw new ArgumentNullException(nameof(HitObject.SoundControlPoint), $"{nameof(HitObject)} must always have an attached {nameof(HitObject.SoundControlPoint)}.");
if (HitObject.SampleControlPoint == null)
throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)} must always have an attached {nameof(HitObject.SampleControlPoint)}.");
var bank = sample.Bank;
if (string.IsNullOrEmpty(bank))
bank = HitObject.SoundControlPoint.SampleBank;
foreach (SampleInfo s in HitObject.Samples)
{
SampleInfo localSampleInfo = new SampleInfo
{
Bank = s.Bank ?? HitObject.SampleControlPoint.SampleBank,
Name = s.Name,
Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume
};
int volume = sample.Volume;
if (volume == 0)
volume = HitObject.SoundControlPoint.SampleVolume;
SampleChannel channel = audio.Sample.Get($@"Gameplay/{bank}-{sample.Name}");
SampleChannel channel = localSampleInfo.GetChannel(audio.Sample);
if (channel == null)
continue;
channel.Volume.Value = volume;
Samples.Add(channel);
}
}
}
protected override void LoadComplete()
{

View File

@ -32,10 +32,10 @@ namespace osu.Game.Rulesets.Objects
/// and can be treated as the default samples for the hit object.
/// </para>
/// </summary>
public SampleInfoList Samples = new SampleInfoList();
public SampleInfoList Samples;
[JsonIgnore]
public SoundControlPoint SoundControlPoint;
public SampleControlPoint SampleControlPoint;
/// <summary>
/// Whether this <see cref="HitObject"/> is in Kiai time.
@ -64,11 +64,11 @@ namespace osu.Game.Rulesets.Objects
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
SoundControlPoint soundPoint = controlPointInfo.SoundPointAt(StartTime);
SampleControlPoint samplePoint = controlPointInfo.SamplePointAt(StartTime);
EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime);
Kiai = effectPoint.KiaiMode;
SoundControlPoint = soundPoint;
SampleControlPoint = samplePoint;
}
protected virtual void CreateNestedHitObjects()

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
cpi.TimingPoints.ForEach(addTimingPoint);
// Consider all non-timing points as the same type
cpi.SoundPoints.Select(c => (ControlPoint)c)
cpi.SamplePoints.Select(c => (ControlPoint)c)
.Concat(cpi.EffectPoints)
.Concat(cpi.DifficultyPoints)
.Distinct()

View File

@ -258,7 +258,7 @@
<Compile Include="Beatmaps\ControlPoints\ControlPointInfo.cs" />
<Compile Include="Beatmaps\ControlPoints\DifficultyControlPoint.cs" />
<Compile Include="Beatmaps\ControlPoints\EffectControlPoint.cs" />
<Compile Include="Beatmaps\ControlPoints\SoundControlPoint.cs" />
<Compile Include="Beatmaps\ControlPoints\SampleControlPoint.cs" />
<Compile Include="Beatmaps\ControlPoints\TimingControlPoint.cs" />
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />