1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:13:21 +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
{
Centre = s.GetSampleInfo().GetChannel(audio.Sample, "Taiko"),
Rim = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample, "Taiko")
Centre = s.GetSampleInfo().GetChannel(audio.Sample.Get, "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_CLAP = @"hitclap";
public SampleChannel GetChannel(SampleManager manager, string resourceNamespace = null)
public SampleChannel GetChannel(Func<string, SampleChannel> getChannel, string resourceNamespace = null)
{
SampleChannel channel = null;
if (resourceNamespace != null)
channel = manager.Get($"Gameplay/{resourceNamespace}/{Bank}-{Name}");
channel = getChannel($"Gameplay/{resourceNamespace}/{Bank}-{Name}");
// try without namespace as a fallback.
if (channel == null)
channel = manager.Get($"Gameplay/{Bank}-{Name}");
channel = getChannel($"Gameplay/{Bank}-{Name}");
if (channel != null)
channel.Volume.Value = Volume / 100.0;

View File

@ -17,6 +17,7 @@ using osu.Framework.Configuration;
using OpenTK;
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Objects.Drawables
{
@ -82,8 +83,10 @@ namespace osu.Game.Rulesets.Objects.Drawables
HitObject = hitObject;
}
private readonly Bindable<Skin> skin = new Bindable<Skin>();
[BackgroundDependencyLoader]
private void load(AudioManager audio)
private void load(AudioManager audio, SkinManager skins)
{
var samples = GetSamples();
if (samples.Any())
@ -91,23 +94,30 @@ namespace osu.Game.Rulesets.Objects.Drawables
if (HitObject.SampleControlPoint == null)
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}.");
foreach (SampleInfo s in samples)
void loadSamples(Skin skin)
{
SampleInfo localSampleInfo = new SampleInfo
Samples.Clear();
foreach (SampleInfo s in samples)
{
Bank = s.Bank ?? HitObject.SampleControlPoint.SampleBank,
Name = s.Name,
Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume
};
SampleInfo localSampleInfo = new SampleInfo
{
Bank = s.Bank ?? HitObject.SampleControlPoint.SampleBank,
Name = s.Name,
Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume
};
SampleChannel channel = localSampleInfo.GetChannel(audio.Sample, SampleNamespace);
if (channel == null)
continue;
SampleChannel channel = localSampleInfo.GetChannel(skin.GetSample, SampleNamespace) ?? localSampleInfo.GetChannel(audio.Sample.Get, SampleNamespace);
Samples.Add(channel);
if (channel == null) return;
Samples.Add(channel);
}
}
skin.ValueChanged += loadSamples;
skin.BindTo(skins.CurrentSkin);
}
}