From 7bd9a87bda2178d7e0a1d103a38b9c7c7348f93f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 5 Dec 2016 21:09:41 +0900 Subject: [PATCH] Add menu button sound effects. --- osu-resources | 2 +- osu.Game/Graphics/UserInterface/BackButton.cs | 12 ++++++++++++ osu.Game/Overlays/Toolbar/ToolbarButton.cs | 11 +++++++++++ osu.Game/Screens/Menu/Button.cs | 17 ++++++++++++++--- osu.Game/Screens/Menu/ButtonSystem.cs | 13 ++++++++++++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/osu-resources b/osu-resources index 1bf3167fa3..73ddad1f01 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 1bf3167fa384c124f388a885f01613ed59fe8169 +Subproject commit 73ddad1f01f223c6c311f1302ed1658a2320813d diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs index 7ccc5c061b..2f0f78b7a6 100644 --- a/osu.Game/Graphics/UserInterface/BackButton.cs +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -1,6 +1,9 @@ // Copyright (c) 2007-2016 ppy Pty Ltd . // 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); } } diff --git a/osu.Game/Overlays/Toolbar/ToolbarButton.cs b/osu.Game/Overlays/Toolbar/ToolbarButton.cs index 70462fa5fe..5976f64c41 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarButton.cs @@ -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; } diff --git a/osu.Game/Screens/Menu/Button.cs b/osu.Game/Screens/Menu/Button.cs index f0de6e7f74..92bbf0da68 100644 --- a/osu.Game/Screens/Menu/Button.cs +++ b/osu.Game/Screens/Menu/Button.cs @@ -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; } diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index f5cf111269..86db7f5e5f 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -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: