1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 03:13:22 +08:00
This commit is contained in:
Jamie Taylor 2024-12-03 10:53:46 -03:00 committed by GitHub
commit 17e1fcb005
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 103 additions and 69 deletions

View File

@ -101,7 +101,16 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
} }
} }
} },
}
},
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"), new OsuMenuItem(@"Choose me please"),

View File

@ -11,16 +11,8 @@ namespace osu.Game.Graphics.Cursor
[Cached(typeof(OsuContextMenuContainer))] [Cached(typeof(OsuContextMenuContainer))]
public partial class OsuContextMenuContainer : ContextMenuContainer public partial class OsuContextMenuContainer : ContextMenuContainer
{ {
[Cached]
private OsuContextMenuSamples samples = new OsuContextMenuSamples();
private OsuContextMenu menu = null!; private OsuContextMenu menu = null!;
public OsuContextMenuContainer()
{
AddInternal(samples);
}
protected override Menu CreateMenu() => menu = new OsuContextMenu(true); protected override Menu CreateMenu() => menu = new OsuContextMenu(true);
public void CloseMenu() public void CloseMenu()

View File

@ -23,6 +23,9 @@ namespace osu.Game.Graphics.UserInterface
DialogCancel, DialogCancel,
[Description("dialog-ok")] [Description("dialog-ok")]
DialogOk DialogOk,
[Description("menu-open")]
MenuOpen,
} }
} }

View File

@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface
private const int fade_duration = 250; private const int fade_duration = 250;
[Resolved] [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. // todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened; private bool wasOpened;
@ -47,15 +47,14 @@ namespace osu.Game.Graphics.UserInterface
protected override void AnimateOpen() protected override void AnimateOpen()
{ {
wasOpened = true;
this.FadeIn(fade_duration, Easing.OutQuint); this.FadeIn(fade_duration, Easing.OutQuint);
if (playClickSample) if (!playClickSample)
samples.PlayClickSample(); return;
if (!wasOpened) menuSamples?.PlayClickSample();
samples.PlayOpenSample(); menuSamples?.PlayOpenSample();
wasOpened = true;
} }
protected override void AnimateClose() protected override void AnimateClose()
@ -63,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface
this.FadeOut(fade_duration, Easing.OutQuint); this.FadeOut(fade_duration, Easing.OutQuint);
if (wasOpened) if (wasOpened)
samples.PlayCloseSample(); menuSamples?.PlayCloseSample();
wasOpened = false; wasOpened = false;
} }

View File

@ -1,37 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Extensions;
using osu.Framework.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public partial class OsuContextMenuSamples : Component
{
private Sample sampleClick;
private Sample sampleOpen;
private Sample sampleClose;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Samples.Get($@"UI/{HoverSampleSet.Default.GetDescription()}-select");
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
}
public void PlayClickSample() => Scheduler.AddOnce(playClickSample);
private void playClickSample() => sampleClick.Play();
public void PlayOpenSample() => Scheduler.AddOnce(playOpenSample);
private void playOpenSample() => sampleOpen.Play();
public void PlayCloseSample() => Scheduler.AddOnce(playCloseSample);
private void playCloseSample() => sampleClose.Play();
}
}

View File

@ -4,8 +4,6 @@
#nullable disable #nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -20,12 +18,12 @@ namespace osu.Game.Graphics.UserInterface
{ {
public partial class OsuMenu : Menu 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. // todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened; private bool wasOpened;
[Resolved]
private OsuMenuSamples menuSamples { get; set; } = null!;
public OsuMenu(Direction direction, bool topLevelMenu = false) public OsuMenu(Direction direction, bool topLevelMenu = false)
: base(direction, topLevelMenu) : base(direction, topLevelMenu)
{ {
@ -33,13 +31,8 @@ namespace osu.Game.Graphics.UserInterface
MaskingContainer.CornerRadius = 4; MaskingContainer.CornerRadius = 4;
ItemsContainer.Padding = new MarginPadding(5); ItemsContainer.Padding = new MarginPadding(5);
}
[BackgroundDependencyLoader] OnSubmenuOpen += _ => { menuSamples?.PlaySubOpenSample(); };
private void load(AudioManager audio)
{
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
} }
protected override void Update() protected override void Update()
@ -64,7 +57,7 @@ namespace osu.Game.Graphics.UserInterface
protected override void AnimateOpen() protected override void AnimateOpen()
{ {
if (!TopLevelMenu && !wasOpened) if (!TopLevelMenu && !wasOpened)
sampleOpen?.Play(); menuSamples?.PlayOpenSample();
this.FadeIn(300, Easing.OutQuint); this.FadeIn(300, Easing.OutQuint);
wasOpened = true; wasOpened = true;
@ -73,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface
protected override void AnimateClose() protected override void AnimateClose()
{ {
if (!TopLevelMenu && wasOpened) if (!TopLevelMenu && wasOpened)
sampleClose?.Play(); menuSamples?.PlayCloseSample();
this.FadeOut(300, Easing.OutQuint); this.FadeOut(300, Easing.OutQuint);
wasOpened = false; wasOpened = false;

View File

@ -0,0 +1,70 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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;
}
}
}

View File

@ -41,6 +41,7 @@ using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input; using osu.Game.Input;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.IO; using osu.Game.IO;
@ -383,6 +384,10 @@ namespace osu.Game
GlobalActionContainer globalBindings; GlobalActionContainer globalBindings;
OsuMenuSamples menuSamples;
dependencies.Cache(menuSamples = new OsuMenuSamples());
base.Content.Add(menuSamples);
base.Content.Add(SafeAreaContainer = new SafeAreaContainer base.Content.Add(SafeAreaContainer = new SafeAreaContainer
{ {
SafeAreaOverrideEdges = SafeAreaOverrideEdges, SafeAreaOverrideEdges = SafeAreaOverrideEdges,

View File

@ -99,7 +99,7 @@ namespace osu.Game.Screens.Edit.Components.Menus
ForegroundColourHover = colourProvider.Content1; ForegroundColourHover = colourProvider.Content1;
BackgroundColourHover = colourProvider.Background1; BackgroundColourHover = colourProvider.Background1;
AddInternal(hoverClickSounds = new HoverClickSounds()); AddInternal(hoverClickSounds = new HoverClickSounds(HoverSampleSet.MenuOpen));
} }
protected override void LoadComplete() protected override void LoadComplete()