Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve menu/context-menu sample playback #30910

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.1128.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.1205.0" />
</ItemGroup>
<PropertyGroup>
<!-- Fody does not handle Android build well, and warns when unchanged.
Expand Down
11 changes: 10 additions & 1 deletion osu.Game.Tests/Visual/UserInterface/TestSceneContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ private static MenuItem[] makeMenu()
}
}
}
}
},
}
},
new OsuMenuItem(@"Another nested option")
{
Items = new MenuItem[]
{
new OsuMenuItem(@"Sub-One"),
new OsuMenuItem(@"Sub-Two"),
new OsuMenuItem(@"Sub-Three"),
}
},
new OsuMenuItem(@"Choose me please"),
Expand Down
8 changes: 0 additions & 8 deletions osu.Game/Graphics/Cursor/OsuContextMenuContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ namespace osu.Game.Graphics.Cursor
[Cached(typeof(OsuContextMenuContainer))]
public partial class OsuContextMenuContainer : ContextMenuContainer
{
[Cached]
private OsuContextMenuSamples samples = new OsuContextMenuSamples();

private OsuContextMenu menu = null!;

public OsuContextMenuContainer()
{
AddInternal(samples);
}

protected override Menu CreateMenu() => menu = new OsuContextMenu(true);

public void CloseMenu()
Expand Down
5 changes: 4 additions & 1 deletion osu.Game/Graphics/UserInterface/HoverSampleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public enum HoverSampleSet
DialogCancel,

[Description("dialog-ok")]
DialogOk
DialogOk,

[Description("menu-open")]
MenuOpen,
}
}
15 changes: 7 additions & 8 deletions osu.Game/Graphics/UserInterface/OsuContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class OsuContextMenu : OsuMenu
private const int fade_duration = 250;

[Resolved]
private OsuContextMenuSamples samples { get; set; } = null!;
private OsuMenuSamples menuSamples { get; set; } = null!;

// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened;
Expand Down Expand Up @@ -47,23 +47,22 @@ private void load(OsuColour colours)

protected override void AnimateOpen()
{
wasOpened = true;
this.FadeIn(fade_duration, Easing.OutQuint);

if (playClickSample)
samples.PlayClickSample();

if (!wasOpened)
samples.PlayOpenSample();
if (!playClickSample)
return;

wasOpened = true;
menuSamples.PlayClickSample();
menuSamples.PlayOpenSample();
}

protected override void AnimateClose()
{
this.FadeOut(fade_duration, Easing.OutQuint);

if (wasOpened)
samples.PlayCloseSample();
menuSamples.PlayCloseSample();

wasOpened = false;
}
Expand Down
37 changes: 0 additions & 37 deletions osu.Game/Graphics/UserInterface/OsuContextMenuSamples.cs

This file was deleted.

19 changes: 6 additions & 13 deletions osu.Game/Graphics/UserInterface/OsuMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -20,26 +18,21 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class OsuMenu : Menu
{
private Sample sampleOpen;
private Sample sampleClose;

// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened;

[Resolved]
private OsuMenuSamples menuSamples { get; set; } = null!;

public OsuMenu(Direction direction, bool topLevelMenu = false)
: base(direction, topLevelMenu)
{
BackgroundColour = Color4.Black.Opacity(0.5f);

MaskingContainer.CornerRadius = 4;
ItemsContainer.Padding = new MarginPadding(5);
}

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
OnSubmenuOpen += _ => { menuSamples?.PlaySubOpenSample(); };
}

protected override void Update()
Expand All @@ -64,7 +57,7 @@ protected override void Update()
protected override void AnimateOpen()
{
if (!TopLevelMenu && !wasOpened)
sampleOpen?.Play();
menuSamples?.PlayOpenSample();

this.FadeIn(300, Easing.OutQuint);
wasOpened = true;
Expand All @@ -73,7 +66,7 @@ protected override void AnimateOpen()
protected override void AnimateClose()
{
if (!TopLevelMenu && wasOpened)
sampleClose?.Play();
menuSamples?.PlayCloseSample();

this.FadeOut(300, Easing.OutQuint);
wasOpened = false;
Expand Down
70 changes: 70 additions & 0 deletions osu.Game/Graphics/UserInterface/OsuMenuSamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;

namespace osu.Game.Graphics.UserInterface
{
public partial class OsuMenuSamples : Component
{
private Sample sampleClick;
private Sample sampleOpen;
private Sample sampleSubOpen;
private Sample sampleClose;

private bool triggerOpen;
private bool triggerSubOpen;
private bool triggerClose;

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Samples.Get(@"UI/menu-open-select");
sampleOpen = audio.Samples.Get(@"UI/menu-open");
sampleSubOpen = audio.Samples.Get(@"UI/menu-sub-open");
sampleClose = audio.Samples.Get(@"UI/menu-close");
}

public void PlayClickSample()
{
Scheduler.AddOnce(playClickSample);
}

public void PlayOpenSample()
{
triggerOpen = true;
Scheduler.AddOnce(resolvePlayback);
}

public void PlaySubOpenSample()
{
triggerSubOpen = true;
Scheduler.AddOnce(resolvePlayback);
}

public void PlayCloseSample()
{
triggerClose = true;
Scheduler.AddOnce(resolvePlayback);
}

private void playClickSample() => sampleClick.Play();

private void resolvePlayback()
{
if (triggerSubOpen)
sampleSubOpen?.Play();
else if (triggerOpen)
sampleOpen?.Play();
else if (triggerClose)
sampleClose?.Play();

triggerOpen = triggerSubOpen = triggerClose = false;
}
}
}
5 changes: 5 additions & 0 deletions osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osu.Game.IO;
Expand Down Expand Up @@ -383,6 +384,10 @@ private void load(ReadableKeyCombinationProvider keyCombinationProvider, Framewo

GlobalActionContainer globalBindings;

OsuMenuSamples menuSamples;
dependencies.Cache(menuSamples = new OsuMenuSamples());
base.Content.Add(menuSamples);

base.Content.Add(SafeAreaContainer = new SafeAreaContainer
{
SafeAreaOverrideEdges = SafeAreaOverrideEdges,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Components/Menus/EditorMenuBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void load(OverlayColourProvider colourProvider)
ForegroundColourHover = colourProvider.Content1;
BackgroundColourHover = colourProvider.Background1;

AddInternal(hoverClickSounds = new HoverClickSounds());
AddInternal(hoverClickSounds = new HoverClickSounds(HoverSampleSet.MenuOpen));
}

protected override void LoadComplete()
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/osu.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Realm" Version="11.5.0" />
<PackageReference Include="ppy.osu.Framework" Version="2024.1128.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2024.1106.0" />
<PackageReference Include="ppy.osu.Framework" Version="2024.1205.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2024.1202.0" />
<PackageReference Include="Sentry" Version="4.13.0" />
<!-- Held back due to 0.34.0 failing AOT compilation on ZstdSharp.dll dependency. -->
<PackageReference Include="SharpCompress" Version="0.38.0" />
Expand Down
2 changes: 1 addition & 1 deletion osu.iOS.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<MtouchInterpreter>-all</MtouchInterpreter>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.iOS" Version="2024.1128.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2024.1205.0" />
</ItemGroup>
</Project>
Loading