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

Added hitsound handling to the TaikoRulesetContainer so every KeyDown can play a hitsound (instead of the DrawableHitObjects)

This commit is contained in:
FreezyLemon 2017-11-29 06:28:08 +01:00
parent 3e8db8c5e1
commit c00fb47236

View File

@ -2,8 +2,11 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Input;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
@ -15,21 +18,45 @@ using osu.Game.Rulesets.Taiko.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.Taiko.Replays; using osu.Game.Rulesets.Taiko.Replays;
using OpenTK; using OpenTK;
using OpenTK.Input;
using System.Linq; using System.Linq;
using osu.Framework.Input; using osu.Framework.Input;
using System.Collections.Generic;
namespace osu.Game.Rulesets.Taiko.UI namespace osu.Game.Rulesets.Taiko.UI
{ {
public class TaikoRulesetContainer : ScrollingRulesetContainer<TaikoPlayfield, TaikoHitObject> public class TaikoRulesetContainer : ScrollingRulesetContainer<TaikoPlayfield, TaikoHitObject>
{ {
private readonly HashSet<Key> centreKeys = new HashSet<Key>();
private readonly HashSet<Key> rimKeys = new HashSet<Key>();
private AudioManager audio;
private IEnumerable<KeyBinding> keyBindings;
public TaikoRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) public TaikoRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(ruleset, beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(AudioManager audio, KeyBindingStore store)
{ {
keyBindings = store.Query(Ruleset.RulesetInfo.ID, Ruleset.AvailableVariants?.First() ?? 0).Cast<KeyBinding>();
if (keyBindings.Count() == 0)
keyBindings = Ruleset.GetDefaultKeyBindings();
foreach (var kb in keyBindings)
{
var key = (Key)(kb.KeyCombination.Keys as InputKey[]).First();
var action = kb.GetAction<TaikoAction>();
if (action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre)
centreKeys.Add(key);
if (action == TaikoAction.LeftRim || action == TaikoAction.RightRim)
rimKeys.Add(key);
}
this.audio = audio;
loadBarLines(); loadBarLines();
} }
@ -77,6 +104,21 @@ namespace osu.Game.Rulesets.Taiko.UI
} }
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
var sampleBank = Beatmap.ControlPointInfo.SoundPointAt(WorkingBeatmap.Track.CurrentTime).SampleBank ?? "normal";
string sampleName = "";
if (centreKeys.Contains(args.Key))
sampleName = "hitnormal";
else if (rimKeys.Contains(args.Key))
sampleName = "hitclap";
audio.Sample.Get($"Gameplay/{sampleBank}-{sampleName}")?.Play();
return base.OnKeyDown(state, args);
}
protected override Vector2 GetPlayfieldAspectAdjust() protected override Vector2 GetPlayfieldAspectAdjust()
{ {
const float default_relative_height = TaikoPlayfield.DEFAULT_HEIGHT / 768; const float default_relative_height = TaikoPlayfield.DEFAULT_HEIGHT / 768;