Add hover/click sound effects to more stuff everywhere

This commit is contained in:
Dean Herbert
2017-11-26 02:41:18 +09:00
parent 8f57bf2498
commit ac7e373f40
13 changed files with 95 additions and 67 deletions

View File

@ -2,34 +2,24 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Graphics.Containers
{
public class OsuClickableContainer : ClickableContainer
{
protected SampleChannel SampleClick, SampleHover;
private readonly HoverSampleSet sampleSet;
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Normal)
{
this.sampleSet = sampleSet;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
private void load()
{
SampleHover = audio.Sample.Get(@"UI/generic-hover");
SampleClick = audio.Sample.Get(@"UI/generic-select");
}
protected override bool OnHover(InputState state)
{
SampleHover?.Play();
return base.OnHover(state);
}
protected override bool OnClick(InputState state)
{
SampleClick?.Play();
return base.OnClick(state);
AddInternal(new HoverClickSounds(sampleSet));
}
}
}

View File

@ -0,0 +1,62 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Adds hover and click sounds to a drawable.
/// Does not draw anything.
/// </summary>
public class HoverClickSounds : CompositeDrawable
{
private SampleChannel sampleClick;
private SampleChannel sampleHover;
protected readonly HoverSampleSet SampleSet;
public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal)
{
SampleSet = sampleSet;
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true;
}
protected override bool OnClick(InputState state)
{
sampleClick?.Play();
return base.OnClick(state);
}
protected override bool OnHover(InputState state)
{
sampleHover?.Play();
return base.OnHover(state);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get($@"UI/generic-select{SampleSet.GetDescription()}");
sampleHover = audio.Sample.Get($@"UI/generic-hover{SampleSet.GetDescription()}");
}
}
public enum HoverSampleSet
{
[Description("")]
Loud,
[Description("-soft")]
Normal,
[Description("-softer")]
Soft
}
}

View File

@ -1,13 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
@ -16,38 +10,9 @@ namespace osu.Game.Graphics.UserInterface
/// </summary>
public class OsuButton : Button
{
private SampleChannel sampleClick;
private SampleChannel sampleHover;
protected HoverSampleSet SampleSet = HoverSampleSet.Normal;
protected override bool OnClick(InputState state)
public OsuButton()
{
sampleClick?.Play();
return base.OnClick(state);
}
protected override bool OnHover(InputState state)
{
sampleHover?.Play();
return base.OnHover(state);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get($@"UI/generic-select{SampleSet.GetDescription()}");
sampleHover = audio.Sample.Get($@"UI/generic-hover{SampleSet.GetDescription()}");
}
public enum HoverSampleSet
{
[Description("")]
Normal,
[Description("-soft")]
Soft,
[Description("-softer")]
Softer
Add(new HoverClickSounds(HoverSampleSet.Loud));
}
}
}

View File

@ -70,7 +70,8 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 5 },
}
},
new HoverClickSounds()
};
Nub.Current.BindTo(Current);

View File

@ -33,7 +33,6 @@ namespace osu.Game.Graphics.UserInterface
if (accentColour == default(Color4))
accentColour = colours.PinkDarker;
updateAccentColour();
}
private void updateAccentColour()
@ -137,6 +136,8 @@ namespace osu.Game.Graphics.UserInterface
nonAccentHoverColour = colours.PinkDarker;
nonAccentSelectedColour = Color4.Black.Opacity(0.5f);
updateColours();
AddInternal(new HoverClickSounds(HoverSampleSet.Soft));
}
protected override void UpdateForegroundColour()
@ -183,7 +184,7 @@ namespace osu.Game.Graphics.UserInterface
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
}
},
};
}
}
@ -237,8 +238,10 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 4 },
Size = new Vector2(20),
}
},
};
AddInternal(new HoverClickSounds());
}
[BackgroundDependencyLoader]

View File

@ -88,7 +88,8 @@ namespace osu.Game.Graphics.UserInterface
{
Origin = Anchor.TopCentre,
Expanded = true,
}
},
new HoverClickSounds()
};
Current.DisabledChanged += disabled =>

View File

@ -131,7 +131,8 @@ namespace osu.Game.Graphics.UserInterface
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
},
new HoverClickSounds()
};
}

View File

@ -57,6 +57,7 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
},
new HoverClickSounds()
};
}