1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 11:23:00 +08:00

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 // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Game.Graphics.UserInterface;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
{ {
public class OsuClickableContainer : ClickableContainer public class OsuClickableContainer : ClickableContainer
{ {
protected SampleChannel SampleClick, SampleHover; private readonly HoverSampleSet sampleSet;
public OsuClickableContainer(HoverSampleSet sampleSet = HoverSampleSet.Normal)
{
this.sampleSet = sampleSet;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load()
{ {
SampleHover = audio.Sample.Get(@"UI/generic-hover"); AddInternal(new HoverClickSounds(sampleSet));
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);
} }
} }
} }

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>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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.Graphics.UserInterface;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -16,38 +10,9 @@ namespace osu.Game.Graphics.UserInterface
/// </summary> /// </summary>
public class OsuButton : Button public class OsuButton : Button
{ {
private SampleChannel sampleClick; public OsuButton()
private SampleChannel sampleHover;
protected HoverSampleSet SampleSet = HoverSampleSet.Normal;
protected override bool OnClick(InputState state)
{ {
sampleClick?.Play(); Add(new HoverClickSounds(HoverSampleSet.Loud));
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
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -222,7 +222,7 @@ namespace osu.Game.Overlays.Chat
} }
private class MessageSender : ClickableContainer, IHasContextMenu private class MessageSender : OsuClickableContainer, IHasContextMenu
{ {
private readonly User sender; private readonly User sender;

View File

@ -17,6 +17,7 @@ using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using System; using System;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Chat namespace osu.Game.Overlays.Chat
{ {
@ -259,7 +260,7 @@ namespace osu.Game.Overlays.Chat
}; };
} }
public class CloseButton : ClickableContainer public class CloseButton : OsuClickableContainer
{ {
private readonly SpriteIcon icon; private readonly SpriteIcon icon;

View File

@ -13,6 +13,7 @@ using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
{ {
@ -74,7 +75,7 @@ namespace osu.Game.Overlays.Toolbar
private readonly SpriteText tooltip2; private readonly SpriteText tooltip2;
protected FillFlowContainer Flow; protected FillFlowContainer Flow;
public ToolbarButton() public ToolbarButton() : base(HoverSampleSet.Loud)
{ {
Width = WIDTH; Width = WIDTH;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
@ -195,4 +196,4 @@ namespace osu.Game.Overlays.Toolbar
}; };
} }
} }
} }

View File

@ -17,10 +17,11 @@ using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
namespace osu.Game.Users namespace osu.Game.Users
{ {
public class UserPanel : ClickableContainer, IHasContextMenu public class UserPanel : OsuClickableContainer, IHasContextMenu
{ {
private readonly User user; private readonly User user;
private const float height = 100; private const float height = 100;

View File

@ -271,6 +271,7 @@
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" /> <Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
<Compile Include="Database\DatabaseContextFactory.cs" /> <Compile Include="Database\DatabaseContextFactory.cs" />
<Compile Include="Database\IHasPrimaryKey.cs" /> <Compile Include="Database\IHasPrimaryKey.cs" />
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
<Compile Include="Graphics\UserInterface\OsuButton.cs" /> <Compile Include="Graphics\UserInterface\OsuButton.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.cs" /> <Compile Include="Migrations\20171019041408_InitialCreate.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs"> <Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">