From 59045c8bca134f132316d69253ad8d7ba9a07ba0 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Fri, 30 May 2025 08:23:09 +0300 Subject: [PATCH 1/2] Duck music and dim background when "no results" placeholder is visible --- osu.Game/Screens/SelectV2/SongSelect.cs | 106 ++++++++++++++++++++---- 1 file changed, 88 insertions(+), 18 deletions(-) diff --git a/osu.Game/Screens/SelectV2/SongSelect.cs b/osu.Game/Screens/SelectV2/SongSelect.cs index f4ba68cbd5..e2d5092b81 100644 --- a/osu.Game/Screens/SelectV2/SongSelect.cs +++ b/osu.Game/Screens/SelectV2/SongSelect.cs @@ -22,6 +22,7 @@ using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Collections; using osu.Game.Database; +using osu.Game.Graphics; using osu.Game.Graphics.Carousel; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; @@ -368,6 +369,65 @@ namespace osu.Game.Screens.SelectV2 private void ensureTrackLooping(IWorkingBeatmap beatmap, TrackChangeDirection changeDirection) => beatmap.PrepareTrackForPreview(true); + private IDisposable? trackDuck; + + private void attachTrackDuckingIfShould() + { + bool shouldDuck = noResultsPlaceholder.State.Value == Visibility.Visible; + + if (shouldDuck && trackDuck == null) + trackDuck = music.Duck(new DuckParameters { DuckVolumeTo = 1, DuckCutoffTo = 500 }); + } + + private void detachTrackDucking() + { + trackDuck?.Dispose(); + trackDuck = null; + } + + #endregion + + #region Background + + private bool gradientDimApplied; + + private void updateScreenBackground() + { + var beatmap = Beatmap.Value; + + ApplyToBackground(backgroundModeBeatmap => + { + backgroundModeBeatmap.BlurAmount.Value = 0; + backgroundModeBeatmap.Beatmap = beatmap; + backgroundModeBeatmap.IgnoreUserSettings.Value = true; + backgroundModeBeatmap.DimWhenUserSettingsIgnored.Value = 0.1f; + + ColourInfo targetColour = gradientDimApplied + ? ColourInfo.GradientHorizontal(OsuColour.Gray(0.8f), OsuColour.Gray(0.4f)) + : Color4.White; + + backgroundModeBeatmap.FadeColour(targetColour, 300, Easing.OutQuint); + }); + } + + private void applyGradientDimToBackground() + { + gradientDimApplied = true; + + // If not current, background will be updated later by OnEntering/OnResuming events. + if (this.IsCurrentScreen()) + updateScreenBackground(); + } + + private void removeGradientDimFromBackground() + { + gradientDimApplied = false; + + // If not current, background will be updated later by OnEntering/OnResuming events. + if (this.IsCurrentScreen()) + updateScreenBackground(); + } + #endregion #region Selection handling @@ -405,20 +465,11 @@ namespace osu.Game.Screens.SelectV2 carousel.CurrentSelection = beatmap.BeatmapInfo; - if (this.IsCurrentScreen()) - ensurePlayingSelected(); - // If not the current screen, this will be applied in OnResuming. if (this.IsCurrentScreen()) { - ApplyToBackground(backgroundModeBeatmap => - { - backgroundModeBeatmap.BlurAmount.Value = 0; - backgroundModeBeatmap.Beatmap = beatmap; - backgroundModeBeatmap.IgnoreUserSettings.Value = true; - backgroundModeBeatmap.DimWhenUserSettingsIgnored.Value = 0.1f; - backgroundModeBeatmap.FadeColour(Color4.White, 250); - }); + ensurePlayingSelected(); + updateScreenBackground(); } }); @@ -440,6 +491,7 @@ namespace osu.Game.Screens.SelectV2 modSelectOverlay.SelectedMods.BindTo(Mods); beginLooping(); + attachTrackDuckingIfShould(); // force reselection if entering song select with a protected beatmap if (Beatmap.Value.BeatmapInfo.BeatmapSet!.Protected) @@ -470,6 +522,7 @@ namespace osu.Game.Screens.SelectV2 modSelectOverlay.SelectedMods.BindTo(Mods); beginLooping(); + attachTrackDuckingIfShould(); if (Beatmap.Value.BeatmapInfo.BeatmapSet!.Protected) Beatmap.SetDefault(); @@ -491,6 +544,7 @@ namespace osu.Game.Screens.SelectV2 carousel.VisuallyFocusSelected = true; endLooping(); + detachTrackDucking(); base.OnSuspending(e); } @@ -504,6 +558,7 @@ namespace osu.Game.Screens.SelectV2 filterControl.Hide(); endLooping(); + detachTrackDucking(); return base.OnExiting(e); } @@ -577,13 +632,7 @@ namespace osu.Game.Screens.SelectV2 int count = carousel.MatchedBeatmapsCount; - if (count == 0) - { - noResultsPlaceholder.Show(); - noResultsPlaceholder.Filter = carousel.Criteria; - } - else - noResultsPlaceholder.Hide(); + updateNoResultsPlaceholder(); // Intentionally not localised until we have proper support for this (see https://github.com/ppy/osu-framework/pull/4918 // but also in this case we want support for formatting a number within a string). @@ -606,6 +655,27 @@ namespace osu.Game.Screens.SelectV2 carousel.NextRandom(); } + private void updateNoResultsPlaceholder() + { + int count = carousel.MatchedBeatmapsCount; + + if (count == 0) + { + noResultsPlaceholder.Show(); + noResultsPlaceholder.Filter = carousel.Criteria!; + + attachTrackDuckingIfShould(); + applyGradientDimToBackground(); + } + else + { + noResultsPlaceholder.Hide(); + + detachTrackDucking(); + removeGradientDimFromBackground(); + } + } + #endregion #region Hotkeys From b56fd5b4b420210c1d7e3ee08398a43324ce4db7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 2 Jun 2025 15:52:49 +0900 Subject: [PATCH 2/2] Don't touch beatmap background --- osu.Game/Screens/SelectV2/SongSelect.cs | 68 +++++++------------------ 1 file changed, 17 insertions(+), 51 deletions(-) diff --git a/osu.Game/Screens/SelectV2/SongSelect.cs b/osu.Game/Screens/SelectV2/SongSelect.cs index e2d5092b81..e2a9edc198 100644 --- a/osu.Game/Screens/SelectV2/SongSelect.cs +++ b/osu.Game/Screens/SelectV2/SongSelect.cs @@ -22,7 +22,6 @@ using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Collections; using osu.Game.Database; -using osu.Game.Graphics; using osu.Game.Graphics.Carousel; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; @@ -93,6 +92,7 @@ namespace osu.Game.Screens.SelectV2 private BeatmapTitleWedge titleWedge = null!; private BeatmapDetailsArea detailsArea = null!; private FillFlowContainer wedgesContainer = null!; + private Box rightGradientBackground = null!; private NoResultsPlaceholder noResultsPlaceholder = null!; @@ -133,8 +133,8 @@ namespace osu.Game.Screens.SelectV2 new Box { RelativeSizeAxes = Axes.Both, - Width = 0.5f, - Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.5f), Color4.Black.Opacity(0f)), + Width = 0.6f, + Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.3f), Color4.Black.Opacity(0f)), }, new Container { @@ -205,8 +205,10 @@ namespace osu.Game.Screens.SelectV2 RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - new Box + rightGradientBackground = new Box { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.0f), Color4.Black.Opacity(0.5f)), RelativeSizeAxes = Axes.Both, }, @@ -387,49 +389,6 @@ namespace osu.Game.Screens.SelectV2 #endregion - #region Background - - private bool gradientDimApplied; - - private void updateScreenBackground() - { - var beatmap = Beatmap.Value; - - ApplyToBackground(backgroundModeBeatmap => - { - backgroundModeBeatmap.BlurAmount.Value = 0; - backgroundModeBeatmap.Beatmap = beatmap; - backgroundModeBeatmap.IgnoreUserSettings.Value = true; - backgroundModeBeatmap.DimWhenUserSettingsIgnored.Value = 0.1f; - - ColourInfo targetColour = gradientDimApplied - ? ColourInfo.GradientHorizontal(OsuColour.Gray(0.8f), OsuColour.Gray(0.4f)) - : Color4.White; - - backgroundModeBeatmap.FadeColour(targetColour, 300, Easing.OutQuint); - }); - } - - private void applyGradientDimToBackground() - { - gradientDimApplied = true; - - // If not current, background will be updated later by OnEntering/OnResuming events. - if (this.IsCurrentScreen()) - updateScreenBackground(); - } - - private void removeGradientDimFromBackground() - { - gradientDimApplied = false; - - // If not current, background will be updated later by OnEntering/OnResuming events. - if (this.IsCurrentScreen()) - updateScreenBackground(); - } - - #endregion - #region Selection handling /// @@ -465,11 +424,18 @@ namespace osu.Game.Screens.SelectV2 carousel.CurrentSelection = beatmap.BeatmapInfo; - // If not the current screen, this will be applied in OnResuming. if (this.IsCurrentScreen()) { + // If not the current screen, this will be applied in OnResuming. ensurePlayingSelected(); - updateScreenBackground(); + + ApplyToBackground(backgroundModeBeatmap => + { + backgroundModeBeatmap.BlurAmount.Value = 0; + backgroundModeBeatmap.Beatmap = beatmap; + backgroundModeBeatmap.IgnoreUserSettings.Value = true; + backgroundModeBeatmap.DimWhenUserSettingsIgnored.Value = 0.1f; + }); } }); @@ -665,14 +631,14 @@ namespace osu.Game.Screens.SelectV2 noResultsPlaceholder.Filter = carousel.Criteria!; attachTrackDuckingIfShould(); - applyGradientDimToBackground(); + rightGradientBackground.ResizeWidthTo(3, 1000, Easing.OutQuint); } else { noResultsPlaceholder.Hide(); detachTrackDucking(); - removeGradientDimFromBackground(); + rightGradientBackground.ResizeWidthTo(1, 500, Easing.OutQuint); } }