1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Add menu button sound effects.

This commit is contained in:
Dean Herbert 2016-12-05 21:09:41 +09:00
parent 3056bbda5d
commit 7bd9a87bda
5 changed files with 50 additions and 5 deletions

@ -1 +1 @@
Subproject commit 1bf3167fa384c124f388a885f01613ed59fe8169
Subproject commit 73ddad1f01f223c6c311f1302ed1658a2320813d

View File

@ -1,6 +1,9 @@
// Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
@ -29,6 +32,7 @@ namespace osu.Game.Graphics.UserInterface
private static readonly Vector2 size_extended = new Vector2(140, 50);
private static readonly Vector2 size_retracted = new Vector2(100, 50);
private AudioSample sampleClick;
public BackButton()
{
@ -141,6 +145,12 @@ namespace osu.Game.Graphics.UserInterface
});
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get(@"Menu/menuback");
}
protected override bool OnClick(InputState state)
{
var flash = new Box
@ -154,6 +164,8 @@ namespace osu.Game.Graphics.UserInterface
flash.FadeOutFromOne(200);
flash.Expire();
sampleClick.Play();
return base.OnClick(state);
}
}

View File

@ -2,6 +2,9 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
@ -58,6 +61,7 @@ namespace osu.Game.Overlays.Toolbar
private SpriteText tooltip1;
private SpriteText tooltip2;
protected FlowContainer Flow;
private AudioSample sampleClick;
public ToolbarButton()
{
@ -120,6 +124,12 @@ namespace osu.Game.Overlays.Toolbar
RelativeSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get(@"Menu/menuclick");
}
protected override void Update()
{
base.Update();
@ -133,6 +143,7 @@ namespace osu.Game.Overlays.Toolbar
protected override bool OnClick(InputState state)
{
Action?.Invoke();
sampleClick.Play();
HoverBackground.FlashColour(new Color4(255, 255, 255, 100), 500, EasingTypes.OutQuint);
return true;
}

View File

@ -1,5 +1,8 @@
using System;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -28,6 +31,7 @@ namespace osu.Game.Screens.Menu
private readonly float extraWidth;
private Key triggerKey;
private string text;
private AudioSample sampleClick;
public override bool Contains(Vector2 screenSpacePos)
{
@ -211,6 +215,14 @@ namespace osu.Game.Screens.Menu
box.ScaleTo(new Vector2(1, 1), 500, EasingTypes.OutElastic);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get($@"Menu/menu-{internalName}-click");
if (sampleClick == null)
sampleClick = audio.Sample.Get(internalName.Contains(@"back") ? @"Menu/menuback" : @"Menu/menuhit");
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
trigger();
@ -232,11 +244,9 @@ namespace osu.Game.Screens.Menu
private void trigger()
{
//Game.Audio.PlaySamplePositional($@"menu-{internalName}-click", internalName.Contains(@"back") ? @"menuback" : @"menuhit");
sampleClick.Play();
clickAction?.Invoke();
//box.FlashColour(ColourHelper.Lighten2(colour, 0.7f), 200);
}
public override bool HandleInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f;
@ -250,6 +260,7 @@ namespace osu.Game.Screens.Menu
public int ContractStyle;
ButtonState state;
public ButtonState State
{
get { return state; }

View File

@ -5,6 +5,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -28,6 +31,8 @@ namespace osu.Game.Screens.Menu
public Action OnChart;
public Action OnTest;
private AudioSample sampleOsuClick;
private FlowContainerWithOrigin buttonFlow;
//todo: make these non-internal somehow.
@ -111,6 +116,12 @@ namespace osu.Game.Screens.Menu
buttonFlow.Add(buttonsTopLevel);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleOsuClick = audio.Sample.Get(@"Menu/menuhit");
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -158,7 +169,7 @@ namespace osu.Game.Screens.Menu
switch (state)
{
case MenuState.Initial:
//Game.Audio.PlaySamplePositional(@"menuhit");
sampleOsuClick.Play();
State = MenuState.TopLevel;
return;
case MenuState.TopLevel: