1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:28:00 +08:00

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

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 @@ namespace osu.Game.Overlays.OSD
{
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 @@ namespace osu.Game.Overlays.OSD
}
};
int optionCount = 0;
int selectedOption = -1;
switch (description.RawValue)
{
case bool val:
@ -69,6 +77,38 @@ namespace osu.Game.Overlays.OSD
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;