Add audio feedback for OSD value changes

This commit is contained in:
Jamie Taylor 2021-01-15 20:06:55 +09:00
parent 70924319e4
commit 63e6ec1c9f
1 changed files with 43 additions and 3 deletions

View File

@ -3,6 +3,8 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration.Tracking;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
@ -19,6 +21,15 @@ public class TrackedSettingToast : Toast
{
private const int lights_bottom_margin = 40;
private readonly int optionCount;
private readonly int selectedOption = -1;
private SampleChannel sampleOn;
private SampleChannel sampleOff;
private SampleChannel sampleChange;
private bool playedSample;
public TrackedSettingToast(SettingDescription description)
: base(description.Name, description.Value, description.Shortcut)
{
@ -46,9 +57,6 @@ public TrackedSettingToast(SettingDescription description)
}
};
int optionCount = 0;
int selectedOption = -1;
switch (description.RawValue)
{
case bool val:
@ -69,6 +77,38 @@ public TrackedSettingToast(SettingDescription description)
optionLights.Add(new OptionLight { Glowing = i == selectedOption });
}
protected override void Update()
{
base.Update();
if (playedSample) return;
if (optionCount == 1)
{
if (selectedOption == 0)
sampleOn?.Play();
else
sampleOff?.Play();
}
else
{
if (sampleChange == null) return;
sampleChange.Frequency.Value = 1 + (double)selectedOption / (optionCount - 1) * 0.25f;
sampleChange.Play();
}
playedSample = true;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleOn = audio.Samples.Get("UI/osd-on");
sampleOff = audio.Samples.Get("UI/osd-off");
sampleChange = audio.Samples.Get("UI/osd-change");
}
private class OptionLight : Container
{
private Color4 glowingColour, idleColour;