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

Add basic hitsound skinning

This commit is contained in:
Dean Herbert 2018-02-22 17:34:35 +09:00
parent 84b707f4f8
commit 6ceabfe19e
3 changed files with 27 additions and 17 deletions

View File

@ -29,8 +29,8 @@ namespace osu.Game.Rulesets.Taiko.Audio
{ {
mappings[s.Time] = new DrumSample mappings[s.Time] = new DrumSample
{ {
Centre = s.GetSampleInfo().GetChannel(audio.Sample, "Taiko"), Centre = s.GetSampleInfo().GetChannel(audio.Sample.Get, "Taiko"),
Rim = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample, "Taiko") Rim = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample.Get, "Taiko")
}; };
} }
} }

View File

@ -14,16 +14,16 @@ namespace osu.Game.Audio
public const string HIT_NORMAL = @"hitnormal"; public const string HIT_NORMAL = @"hitnormal";
public const string HIT_CLAP = @"hitclap"; public const string HIT_CLAP = @"hitclap";
public SampleChannel GetChannel(SampleManager manager, string resourceNamespace = null) public SampleChannel GetChannel(Func<string, SampleChannel> getChannel, string resourceNamespace = null)
{ {
SampleChannel channel = null; SampleChannel channel = null;
if (resourceNamespace != null) if (resourceNamespace != null)
channel = manager.Get($"Gameplay/{resourceNamespace}/{Bank}-{Name}"); channel = getChannel($"Gameplay/{resourceNamespace}/{Bank}-{Name}");
// try without namespace as a fallback. // try without namespace as a fallback.
if (channel == null) if (channel == null)
channel = manager.Get($"Gameplay/{Bank}-{Name}"); channel = getChannel($"Gameplay/{Bank}-{Name}");
if (channel != null) if (channel != null)
channel.Volume.Value = Volume / 100.0; channel.Volume.Value = Volume / 100.0;

View File

@ -17,6 +17,7 @@ using osu.Framework.Configuration;
using OpenTK; using OpenTK;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Objects.Drawables namespace osu.Game.Rulesets.Objects.Drawables
{ {
@ -82,8 +83,10 @@ namespace osu.Game.Rulesets.Objects.Drawables
HitObject = hitObject; HitObject = hitObject;
} }
private readonly Bindable<Skin> skin = new Bindable<Skin>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio, SkinManager skins)
{ {
var samples = GetSamples(); var samples = GetSamples();
if (samples.Any()) if (samples.Any())
@ -91,6 +94,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
if (HitObject.SampleControlPoint == null) if (HitObject.SampleControlPoint == null)
throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}." throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}."
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}."); + $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
void loadSamples(Skin skin)
{
Samples.Clear();
foreach (SampleInfo s in samples) foreach (SampleInfo s in samples)
{ {
@ -101,14 +107,18 @@ namespace osu.Game.Rulesets.Objects.Drawables
Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume
}; };
SampleChannel channel = localSampleInfo.GetChannel(audio.Sample, SampleNamespace);
if (channel == null) SampleChannel channel = localSampleInfo.GetChannel(skin.GetSample, SampleNamespace) ?? localSampleInfo.GetChannel(audio.Sample.Get, SampleNamespace);
continue;
if (channel == null) return;
Samples.Add(channel); Samples.Add(channel);
} }
} }
skin.ValueChanged += loadSamples;
skin.BindTo(skins.CurrentSkin);
}
} }
protected override void LoadComplete() protected override void LoadComplete()