2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class SkinnableSound : SkinReloadableDrawable
|
|
|
|
|
{
|
|
|
|
|
private readonly SampleInfo[] samples;
|
|
|
|
|
private SampleChannel[] channels;
|
|
|
|
|
|
|
|
|
|
private AudioManager audio;
|
|
|
|
|
|
|
|
|
|
public SkinnableSound(params SampleInfo[] samples)
|
|
|
|
|
{
|
|
|
|
|
this.samples = samples;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
this.audio = audio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Play() => channels?.ForEach(c => c.Play());
|
|
|
|
|
|
2018-11-15 11:26:12 +00:00
|
|
|
|
public override bool IsPresent => false; // We don't need to receive updates.
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
|
|
|
|
{
|
|
|
|
|
channels = samples.Select(s =>
|
|
|
|
|
{
|
|
|
|
|
var ch = loadChannel(s, skin.GetSample);
|
|
|
|
|
if (ch == null && allowFallback)
|
|
|
|
|
ch = loadChannel(s, audio.Sample.Get);
|
|
|
|
|
return ch;
|
|
|
|
|
}).Where(c => c != null).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SampleChannel loadChannel(SampleInfo info, Func<string, SampleChannel> getSampleFunction)
|
|
|
|
|
{
|
2018-07-02 05:18:41 +00:00
|
|
|
|
foreach (var lookup in info.LookupNames)
|
|
|
|
|
{
|
|
|
|
|
var ch = getSampleFunction($"Gameplay/{lookup}");
|
|
|
|
|
if (ch == null)
|
|
|
|
|
continue;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
ch.Volume.Value = info.Volume / 100.0;
|
2018-07-02 05:18:41 +00:00
|
|
|
|
return ch;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-02 05:18:41 +00:00
|
|
|
|
return null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|