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:
parent
8f57bf2498
commit
ac7e373f40
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
osu.Game/Graphics/UserInterface/HoverClickSounds.cs
Normal file
62
osu.Game/Graphics/UserInterface/HoverClickSounds.cs
Normal 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
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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]
|
||||
|
@ -88,7 +88,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
Expanded = true,
|
||||
}
|
||||
},
|
||||
new HoverClickSounds()
|
||||
};
|
||||
|
||||
Current.DisabledChanged += disabled =>
|
||||
|
@ -131,7 +131,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Colour = Color4.White,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
}
|
||||
},
|
||||
new HoverClickSounds()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
},
|
||||
new HoverClickSounds()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ namespace osu.Game.Overlays.Chat
|
||||
|
||||
}
|
||||
|
||||
private class MessageSender : ClickableContainer, IHasContextMenu
|
||||
private class MessageSender : OsuClickableContainer, IHasContextMenu
|
||||
{
|
||||
private readonly User sender;
|
||||
|
||||
|
@ -17,6 +17,7 @@ using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Configuration;
|
||||
using System;
|
||||
using osu.Game.Graphics.Containers;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -13,6 +13,7 @@ using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
@ -74,7 +75,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
private readonly SpriteText tooltip2;
|
||||
protected FillFlowContainer Flow;
|
||||
|
||||
public ToolbarButton()
|
||||
public ToolbarButton() : base(HoverSampleSet.Loud)
|
||||
{
|
||||
Width = WIDTH;
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
|
@ -17,10 +17,11 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
public class UserPanel : ClickableContainer, IHasContextMenu
|
||||
public class UserPanel : OsuClickableContainer, IHasContextMenu
|
||||
{
|
||||
private readonly User user;
|
||||
private const float height = 100;
|
||||
|
@ -271,6 +271,7 @@
|
||||
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
|
||||
<Compile Include="Database\DatabaseContextFactory.cs" />
|
||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
||||
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
|
||||
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
|
||||
|
Loading…
Reference in New Issue
Block a user