1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00

Add fallback behaviour for custom rulesets

This commit is contained in:
Jamie Taylor 2024-06-23 02:20:51 +09:00
parent 0d11b2b91c
commit 2ffeb1b361
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C

View File

@ -30,6 +30,7 @@ namespace osu.Game.Overlays.Toolbar
private readonly Dictionary<RulesetInfo, Sample> rulesetSelectionSample = new Dictionary<RulesetInfo, Sample>();
private readonly Dictionary<RulesetInfo, SampleChannel> rulesetSelectionChannel = new Dictionary<RulesetInfo, SampleChannel>();
private Sample defaultSelectSample;
public ToolbarRulesetSelector()
{
@ -68,6 +69,8 @@ namespace osu.Game.Overlays.Toolbar
foreach (var r in Rulesets.AvailableRulesets)
rulesetSelectionSample[r] = audio.Samples.Get($@"UI/ruleset-select-{r.ShortName}");
defaultSelectSample = audio.Samples.Get(@"UI/default-select");
Current.ValueChanged += playRulesetSelectionSample;
}
@ -101,15 +104,24 @@ namespace osu.Game.Overlays.Toolbar
private void playRulesetSelectionSample(ValueChangedEvent<RulesetInfo> r)
{
// Don't play sample on first setting of value
if (r.OldValue == null)
return;
if (rulesetSelectionChannel.TryGetValue(r.OldValue, out var sampleChannel))
sampleChannel?.Stop();
var channel = rulesetSelectionSample[r.NewValue]?.GetChannel();
rulesetSelectionChannel[r.NewValue] = rulesetSelectionSample[r.NewValue].GetChannel();
rulesetSelectionChannel[r.NewValue]?.Play();
// Skip sample choking and ducking for the default/fallback sample
if (channel == null)
{
defaultSelectSample.Play();
return;
}
foreach (var pair in rulesetSelectionChannel)
pair.Value?.Stop();
rulesetSelectionChannel[r.NewValue] = channel;
channel.Play();
musicController?.TimedDuck(600);
}