mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Merge pull request #13726 from nekodex/notch-tick-sfx
Add audio feedback for changing volume
This commit is contained in:
commit
5a7706edee
@ -51,7 +51,7 @@
|
||||
<Reference Include="Java.Interop" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.702.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Transitive Dependencies">
|
||||
|
@ -15,6 +15,7 @@ using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -99,7 +100,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, OsuColour colours)
|
||||
{
|
||||
sample = audio.Samples.Get(@"UI/sliderbar-notch");
|
||||
sample = audio.Samples.Get(@"UI/notch-tick");
|
||||
AccentColour = colours.Pink;
|
||||
}
|
||||
|
||||
@ -149,7 +150,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
private void playSample(T value)
|
||||
{
|
||||
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
||||
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 30)
|
||||
return;
|
||||
|
||||
if (value.Equals(lastSampleValue))
|
||||
@ -158,13 +159,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
lastSampleValue = value;
|
||||
lastSampleTime = Clock.CurrentTime;
|
||||
|
||||
var channel = sample.Play();
|
||||
var channel = sample.GetChannel();
|
||||
|
||||
channel.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
||||
if (NormalizedValue == 0)
|
||||
channel.Frequency.Value -= 0.4f;
|
||||
else if (NormalizedValue == 1)
|
||||
channel.Frequency.Value += 0.4f;
|
||||
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + NormalizedValue * 0.2f;
|
||||
|
||||
// intentionally pitched down, even when hitting max.
|
||||
if (NormalizedValue == 0 || NormalizedValue == 1)
|
||||
channel.Frequency.Value -= 0.5f;
|
||||
|
||||
channel.Play();
|
||||
}
|
||||
|
||||
private void updateTooltipText(T value)
|
||||
|
@ -4,6 +4,8 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -36,6 +38,9 @@ namespace osu.Game.Overlays.Volume
|
||||
private OsuSpriteText text;
|
||||
private BufferedContainer maxGlow;
|
||||
|
||||
private Sample sample;
|
||||
private double sampleLastPlaybackTime;
|
||||
|
||||
public VolumeMeter(string name, float circleSize, Color4 meterColour)
|
||||
{
|
||||
this.circleSize = circleSize;
|
||||
@ -46,8 +51,11 @@ namespace osu.Game.Overlays.Volume
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load(OsuColour colours, AudioManager audio)
|
||||
{
|
||||
sample = audio.Samples.Get(@"UI/notch-tick");
|
||||
sampleLastPlaybackTime = Time.Current;
|
||||
|
||||
Color4 backgroundColour = colours.Gray1;
|
||||
|
||||
CircularProgress bgProgress;
|
||||
@ -178,22 +186,12 @@ namespace osu.Game.Overlays.Volume
|
||||
}
|
||||
};
|
||||
|
||||
Bindable.ValueChanged += volume =>
|
||||
{
|
||||
this.TransformTo("DisplayVolume",
|
||||
volume.NewValue,
|
||||
400,
|
||||
Easing.OutQuint);
|
||||
};
|
||||
Bindable.BindValueChanged(volume => { this.TransformTo(nameof(DisplayVolume), volume.NewValue, 400, Easing.OutQuint); }, true);
|
||||
|
||||
bgProgress.Current.Value = 0.75f;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Bindable.TriggerChange();
|
||||
}
|
||||
private int displayVolumeInt;
|
||||
|
||||
private double displayVolume;
|
||||
|
||||
@ -202,8 +200,16 @@ namespace osu.Game.Overlays.Volume
|
||||
get => displayVolume;
|
||||
set
|
||||
{
|
||||
if (value == displayVolume)
|
||||
return;
|
||||
|
||||
displayVolume = value;
|
||||
|
||||
int intValue = (int)Math.Round(displayVolume * 100);
|
||||
bool intVolumeChanged = intValue != displayVolumeInt;
|
||||
|
||||
displayVolumeInt = intValue;
|
||||
|
||||
if (displayVolume >= 0.995f)
|
||||
{
|
||||
text.Text = "MAX";
|
||||
@ -212,14 +218,36 @@ namespace osu.Game.Overlays.Volume
|
||||
else
|
||||
{
|
||||
maxGlow.EffectColour = Color4.Transparent;
|
||||
text.Text = Math.Round(displayVolume * 100).ToString(CultureInfo.CurrentCulture);
|
||||
text.Text = displayVolumeInt.ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
volumeCircle.Current.Value = displayVolume * 0.75f;
|
||||
volumeCircleGlow.Current.Value = displayVolume * 0.75f;
|
||||
|
||||
if (intVolumeChanged && IsLoaded)
|
||||
Scheduler.AddOnce(playTickSound);
|
||||
}
|
||||
}
|
||||
|
||||
private void playTickSound()
|
||||
{
|
||||
const int tick_debounce_time = 30;
|
||||
|
||||
if (Time.Current - sampleLastPlaybackTime <= tick_debounce_time)
|
||||
return;
|
||||
|
||||
var channel = sample.GetChannel();
|
||||
|
||||
channel.Frequency.Value = 0.99f + RNG.NextDouble(0.02f) + displayVolume * 0.1f;
|
||||
|
||||
// intentionally pitched down, even when hitting max.
|
||||
if (displayVolumeInt == 0 || displayVolumeInt == 100)
|
||||
channel.Frequency.Value -= 0.5f;
|
||||
|
||||
channel.Play();
|
||||
sampleLastPlaybackTime = Time.Current;
|
||||
}
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get => Bindable.Value;
|
||||
|
@ -37,7 +37,7 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Realm" Version="10.2.1" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.702.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||
<PackageReference Include="Sentry" Version="3.6.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
|
@ -71,7 +71,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.702.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.618.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.701.0" />
|
||||
</ItemGroup>
|
||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
||||
<PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user