1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Add support for 'disabled' sample variation to HoverClickSounds

This commit is contained in:
Jamie Taylor 2022-11-03 17:44:54 +09:00
parent c48c9ecb6d
commit f1c17129eb
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
8 changed files with 34 additions and 7 deletions

View File

@ -38,6 +38,14 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("revert back", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.ResizeWidthTo(1, 200, Easing.OutQuint)));
}
[Test]
public void TestDisable()
{
createSliderBar();
AddStep("set disabled", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.Current.Disabled = true));
AddStep("unset disabled", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.Current.Disabled = false));
}
private void createSliderBar()
{
AddStep("create component", () =>

View File

@ -20,7 +20,7 @@ namespace osu.Game.Graphics.Containers
protected override Container<Drawable> Content => content;
protected virtual HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet);
protected virtual HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { BindTarget = Enabled } };
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Default)
{

View File

@ -24,6 +24,7 @@ namespace osu.Game.Graphics.UserInterface
private const int transition_length = 80;
private TextContainer text;
private HoverClickSounds hoverClickSounds;
public DrawableOsuMenuItem(MenuItem item)
: base(item)
@ -36,7 +37,7 @@ namespace osu.Game.Graphics.UserInterface
BackgroundColour = Color4.Transparent;
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
AddInternal(new HoverClickSounds());
AddInternal(hoverClickSounds = new HoverClickSounds());
updateTextColour();
@ -76,6 +77,7 @@ namespace osu.Game.Graphics.UserInterface
private void updateState()
{
hoverClickSounds.Enabled.Value = !Item.Action.Disabled;
Alpha = Item.Action.Disabled ? 0.2f : 1;
if (IsHovered && !Item.Action.Disabled)

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
@ -21,6 +22,8 @@ namespace osu.Game.Graphics.UserInterface
public class HoverClickSounds : HoverSounds
{
private Sample sampleClick;
private Sample sampleClickDisabled;
public Bindable<bool> Enabled = new Bindable<bool>(true);
private readonly MouseButton[] buttons;
/// <summary>
@ -41,8 +44,13 @@ namespace osu.Game.Graphics.UserInterface
{
if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition))
{
sampleClick.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
sampleClick.Play();
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();
if (channel != null)
{
channel.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
channel.Play();
}
}
return base.OnClick(e);
@ -53,6 +61,9 @@ namespace osu.Game.Graphics.UserInterface
{
sampleClick = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select");
sampleClickDisabled = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select-disabled")
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select-disabled");
}
}
}

View File

@ -104,7 +104,7 @@ namespace osu.Game.Graphics.UserInterface
});
if (hoverSounds.HasValue)
AddInternal(new HoverClickSounds(hoverSounds.Value));
AddInternal(new HoverClickSounds(hoverSounds.Value) { Enabled = { BindTarget = Enabled } });
}
[BackgroundDependencyLoader]

View File

@ -46,6 +46,8 @@ namespace osu.Game.Graphics.UserInterface
public bool PlaySamplesOnAdjust { get; set; } = true;
private readonly HoverClickSounds hoverClickSounds;
/// <summary>
/// Whether to format the tooltip as a percentage or the actual value.
/// </summary>
@ -127,7 +129,7 @@ namespace osu.Game.Graphics.UserInterface
Current = { Value = true }
},
},
new HoverClickSounds()
hoverClickSounds = new HoverClickSounds()
};
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
@ -152,6 +154,7 @@ namespace osu.Game.Graphics.UserInterface
{
base.LoadComplete();
CurrentNumber.BindValueChanged(current => TooltipText = getTooltipText(current.NewValue), true);
Current.DisabledChanged += disabled => hoverClickSounds.Enabled.Value = !disabled;
}
protected override bool OnHover(HoverEvent e)

View File

@ -138,7 +138,7 @@ namespace osu.Game.Graphics.UserInterface
}
}
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet);
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { BindTarget = Enabled } };
protected override void LoadComplete()
{

View File

@ -13,6 +13,7 @@ using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -123,6 +124,8 @@ namespace osu.Game.Overlays.Toolbar
base.OnHoverLost(e);
}
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { Value = true } };
private void cycleDisplayMode()
{
switch (clockDisplayMode.Value)