mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Add support for 'disabled' sample variation to HoverClickSounds
This commit is contained in:
parent
c48c9ecb6d
commit
f1c17129eb
@ -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)));
|
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()
|
private void createSliderBar()
|
||||||
{
|
{
|
||||||
AddStep("create component", () =>
|
AddStep("create component", () =>
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
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)
|
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Default)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private const int transition_length = 80;
|
private const int transition_length = 80;
|
||||||
|
|
||||||
private TextContainer text;
|
private TextContainer text;
|
||||||
|
private HoverClickSounds hoverClickSounds;
|
||||||
|
|
||||||
public DrawableOsuMenuItem(MenuItem item)
|
public DrawableOsuMenuItem(MenuItem item)
|
||||||
: base(item)
|
: base(item)
|
||||||
@ -36,7 +37,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
BackgroundColour = Color4.Transparent;
|
BackgroundColour = Color4.Transparent;
|
||||||
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
|
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
|
||||||
|
|
||||||
AddInternal(new HoverClickSounds());
|
AddInternal(hoverClickSounds = new HoverClickSounds());
|
||||||
|
|
||||||
updateTextColour();
|
updateTextColour();
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
|
hoverClickSounds.Enabled.Value = !Item.Action.Disabled;
|
||||||
Alpha = Item.Action.Disabled ? 0.2f : 1;
|
Alpha = Item.Action.Disabled ? 0.2f : 1;
|
||||||
|
|
||||||
if (IsHovered && !Item.Action.Disabled)
|
if (IsHovered && !Item.Action.Disabled)
|
||||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
@ -21,6 +22,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
public class HoverClickSounds : HoverSounds
|
public class HoverClickSounds : HoverSounds
|
||||||
{
|
{
|
||||||
private Sample sampleClick;
|
private Sample sampleClick;
|
||||||
|
private Sample sampleClickDisabled;
|
||||||
|
public Bindable<bool> Enabled = new Bindable<bool>(true);
|
||||||
private readonly MouseButton[] buttons;
|
private readonly MouseButton[] buttons;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -41,8 +44,13 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition))
|
if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition))
|
||||||
{
|
{
|
||||||
sampleClick.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
|
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();
|
||||||
sampleClick.Play();
|
|
||||||
|
if (channel != null)
|
||||||
|
{
|
||||||
|
channel.Frequency.Value = 0.99 + RNG.NextDouble(0.02);
|
||||||
|
channel.Play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
@ -53,6 +61,9 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
sampleClick = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select")
|
sampleClick = audio.Samples.Get($@"UI/{SampleSet.GetDescription()}-select")
|
||||||
?? audio.Samples.Get($@"UI/{HoverSampleSet.Default.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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (hoverSounds.HasValue)
|
if (hoverSounds.HasValue)
|
||||||
AddInternal(new HoverClickSounds(hoverSounds.Value));
|
AddInternal(new HoverClickSounds(hoverSounds.Value) { Enabled = { BindTarget = Enabled } });
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -46,6 +46,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
public bool PlaySamplesOnAdjust { get; set; } = true;
|
public bool PlaySamplesOnAdjust { get; set; } = true;
|
||||||
|
|
||||||
|
private readonly HoverClickSounds hoverClickSounds;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to format the tooltip as a percentage or the actual value.
|
/// Whether to format the tooltip as a percentage or the actual value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -127,7 +129,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Current = { Value = true }
|
Current = { Value = true }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new HoverClickSounds()
|
hoverClickSounds = new HoverClickSounds()
|
||||||
};
|
};
|
||||||
|
|
||||||
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
|
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
|
||||||
@ -152,6 +154,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
CurrentNumber.BindValueChanged(current => TooltipText = getTooltipText(current.NewValue), true);
|
CurrentNumber.BindValueChanged(current => TooltipText = getTooltipText(current.NewValue), true);
|
||||||
|
Current.DisabledChanged += disabled => hoverClickSounds.Enabled.Value = !disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
@ -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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@ using osu.Framework.Input.Events;
|
|||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -123,6 +124,8 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { Value = true } };
|
||||||
|
|
||||||
private void cycleDisplayMode()
|
private void cycleDisplayMode()
|
||||||
{
|
{
|
||||||
switch (clockDisplayMode.Value)
|
switch (clockDisplayMode.Value)
|
||||||
|
Loading…
Reference in New Issue
Block a user