mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 06:32:55 +08:00
Fix new mod select overlay dimming itself
This commit is contained in:
parent
407db7ff9d
commit
1744d7e4f0
@ -127,14 +127,14 @@ namespace osu.Game.Graphics.Containers
|
||||
if (didChange)
|
||||
samplePopIn?.Play();
|
||||
|
||||
if (BlockScreenWideMouse && DimMainContent) game?.AddBlockingOverlay(this);
|
||||
if (BlockScreenWideMouse && DimMainContent) game?.ShowBlockingOverlay(this);
|
||||
break;
|
||||
|
||||
case Visibility.Hidden:
|
||||
if (didChange)
|
||||
samplePopOut?.Play();
|
||||
|
||||
if (BlockScreenWideMouse) game?.RemoveBlockingOverlay(this);
|
||||
if (BlockScreenWideMouse) game?.HideBlockingOverlay(this);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ namespace osu.Game.Graphics.Containers
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
game?.RemoveBlockingOverlay(this);
|
||||
game?.HideBlockingOverlay(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ namespace osu.Game
|
||||
private readonly string[] args;
|
||||
|
||||
private readonly List<OsuFocusedOverlayContainer> focusedOverlays = new List<OsuFocusedOverlayContainer>();
|
||||
private readonly List<OverlayContainer> externalOverlays = new List<OverlayContainer>();
|
||||
|
||||
private readonly List<OverlayContainer> visibleBlockingOverlays = new List<OverlayContainer>();
|
||||
|
||||
@ -186,19 +187,59 @@ namespace osu.Game
|
||||
private void updateBlockingOverlayFade() =>
|
||||
ScreenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
|
||||
|
||||
public void AddBlockingOverlay(OverlayContainer overlay)
|
||||
/// <summary>
|
||||
/// Registers a blocking <see cref="OverlayContainer"/> that was not created by <see cref="OsuGame"/> itself for later use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The goal of this method is to allow child screens, like <see cref="SongSelect"/> to register their own full-screen blocking overlays
|
||||
/// with background dim.
|
||||
/// In those cases, for the dim to work correctly, the overlays need to be added at the `OsuGame` level directly, rather as children of the screens.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// An <see cref="IDisposable"/> that should be disposed of when the <paramref name="overlayContainer"/> should be unregistered.
|
||||
/// Disposing of this <see cref="IDisposable"/> will automatically expire the <paramref name="overlayContainer"/>.
|
||||
/// </returns>
|
||||
internal IDisposable RegisterBlockingOverlay(OverlayContainer overlayContainer)
|
||||
{
|
||||
if (overlayContainer.Parent != null)
|
||||
throw new ArgumentException($@"Overlays registered via {nameof(RegisterBlockingOverlay)} should not be added to the scene graph.");
|
||||
|
||||
if (externalOverlays.Contains(overlayContainer))
|
||||
throw new ArgumentException($@"{overlayContainer} has already been registered via {nameof(RegisterBlockingOverlay)} once.");
|
||||
|
||||
externalOverlays.Add(overlayContainer);
|
||||
overlayContent.Add(overlayContainer);
|
||||
return new InvokeOnDisposal(() => unregisterBlockingOverlay(overlayContainer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should be called when <paramref name="overlay"/> has been shown and should begin blocking background input.
|
||||
/// </summary>
|
||||
internal void ShowBlockingOverlay(OverlayContainer overlay)
|
||||
{
|
||||
if (!visibleBlockingOverlays.Contains(overlay))
|
||||
visibleBlockingOverlays.Add(overlay);
|
||||
updateBlockingOverlayFade();
|
||||
}
|
||||
|
||||
public void RemoveBlockingOverlay(OverlayContainer overlay) => Schedule(() =>
|
||||
/// <summary>
|
||||
/// Should be called when a blocking <paramref name="overlay"/> has been hidden and should stop blocking background input.
|
||||
/// </summary>
|
||||
internal void HideBlockingOverlay(OverlayContainer overlay) => Schedule(() =>
|
||||
{
|
||||
visibleBlockingOverlays.Remove(overlay);
|
||||
updateBlockingOverlayFade();
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters a blocking <see cref="OverlayContainer"/> that was not created by <see cref="OsuGame"/> itself.
|
||||
/// </summary>
|
||||
private void unregisterBlockingOverlay(OverlayContainer overlayContainer)
|
||||
{
|
||||
externalOverlays.Remove(overlayContainer);
|
||||
overlayContainer.Expire();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close all game-wide overlays.
|
||||
/// </summary>
|
||||
|
@ -35,6 +35,7 @@ using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using System.Diagnostics;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Skinning;
|
||||
@ -116,9 +117,15 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private double audioFeedbackLastPlaybackTime;
|
||||
|
||||
[CanBeNull]
|
||||
private IDisposable modSelectOverlayRegistration;
|
||||
|
||||
[Resolved]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(AudioManager audio, IDialogOverlay dialog, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender)
|
||||
{
|
||||
@ -264,10 +271,13 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
},
|
||||
Footer = new Footer(),
|
||||
ModSelect = CreateModSelectOverlay()
|
||||
});
|
||||
}
|
||||
|
||||
// preload the mod select overlay for later use in `LoadComplete()`.
|
||||
// therein it will be registered at the `OsuGame` level to properly function as a blocking overlay.
|
||||
LoadComponent(ModSelect = CreateModSelectOverlay());
|
||||
|
||||
if (Footer != null)
|
||||
{
|
||||
foreach (var (button, overlay) in CreateFooterButtons())
|
||||
@ -301,6 +311,13 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
modSelectOverlayRegistration = game?.RegisterBlockingOverlay(ModSelect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the buttons to be displayed in the footer.
|
||||
/// </summary>
|
||||
@ -700,6 +717,8 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
if (music != null)
|
||||
music.TrackChanged -= ensureTrackLooping;
|
||||
|
||||
modSelectOverlayRegistration?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user