mirror of
https://github.com/osukey/osukey.git
synced 2025-05-22 14:07:38 +09:00
Extract interface for overlay management
This commit is contained in:
parent
66473972da
commit
a56eab2c47
@ -34,7 +34,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
protected virtual bool DimMainContent => true;
|
protected virtual bool DimMainContent => true;
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private OsuGame game { get; set; }
|
private IOverlayManager overlayManager { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private PreviewTrackManager previewTrackManager { get; set; }
|
private PreviewTrackManager previewTrackManager { get; set; }
|
||||||
@ -50,8 +50,8 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
if (game != null)
|
if (overlayManager != null)
|
||||||
OverlayActivationMode.BindTo(game.OverlayActivationMode);
|
OverlayActivationMode.BindTo(overlayManager.OverlayActivationMode);
|
||||||
|
|
||||||
OverlayActivationMode.BindValueChanged(mode =>
|
OverlayActivationMode.BindValueChanged(mode =>
|
||||||
{
|
{
|
||||||
@ -127,14 +127,14 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (didChange)
|
if (didChange)
|
||||||
samplePopIn?.Play();
|
samplePopIn?.Play();
|
||||||
|
|
||||||
if (BlockScreenWideMouse && DimMainContent) game?.ShowBlockingOverlay(this);
|
if (BlockScreenWideMouse && DimMainContent) overlayManager?.ShowBlockingOverlay(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Visibility.Hidden:
|
case Visibility.Hidden:
|
||||||
if (didChange)
|
if (didChange)
|
||||||
samplePopOut?.Play();
|
samplePopOut?.Play();
|
||||||
|
|
||||||
if (BlockScreenWideMouse) game?.HideBlockingOverlay(this);
|
if (BlockScreenWideMouse) overlayManager?.HideBlockingOverlay(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
game?.HideBlockingOverlay(this);
|
overlayManager?.HideBlockingOverlay(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ namespace osu.Game
|
|||||||
/// The full osu! experience. Builds on top of <see cref="OsuGameBase"/> to add menus and binding logic
|
/// The full osu! experience. Builds on top of <see cref="OsuGameBase"/> to add menus and binding logic
|
||||||
/// for initial components that are generally retrieved via DI.
|
/// for initial components that are generally retrieved via DI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo, IPerformFromScreenRunner
|
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo, IPerformFromScreenRunner, IOverlayManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of global offset to apply when a left/right anchored overlay is displayed (ie. settings or notifications).
|
/// The amount of global offset to apply when a left/right anchored overlay is displayed (ie. settings or notifications).
|
||||||
@ -184,48 +184,34 @@ namespace osu.Game
|
|||||||
SentryLogger = new SentryLogger(this);
|
SentryLogger = new SentryLogger(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IOverlayManager
|
||||||
|
|
||||||
|
IBindable<OverlayActivation> IOverlayManager.OverlayActivationMode => OverlayActivationMode;
|
||||||
|
|
||||||
private void updateBlockingOverlayFade() =>
|
private void updateBlockingOverlayFade() =>
|
||||||
ScreenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
|
ScreenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
|
||||||
|
|
||||||
/// <summary>
|
IDisposable IOverlayManager.RegisterBlockingOverlay(OverlayContainer overlayContainer)
|
||||||
/// 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)
|
if (overlayContainer.Parent != null)
|
||||||
throw new ArgumentException($@"Overlays registered via {nameof(RegisterBlockingOverlay)} should not be added to the scene graph.");
|
throw new ArgumentException($@"Overlays registered via {nameof(IOverlayManager.RegisterBlockingOverlay)} should not be added to the scene graph.");
|
||||||
|
|
||||||
if (externalOverlays.Contains(overlayContainer))
|
if (externalOverlays.Contains(overlayContainer))
|
||||||
throw new ArgumentException($@"{overlayContainer} has already been registered via {nameof(RegisterBlockingOverlay)} once.");
|
throw new ArgumentException($@"{overlayContainer} has already been registered via {nameof(IOverlayManager.RegisterBlockingOverlay)} once.");
|
||||||
|
|
||||||
externalOverlays.Add(overlayContainer);
|
externalOverlays.Add(overlayContainer);
|
||||||
overlayContent.Add(overlayContainer);
|
overlayContent.Add(overlayContainer);
|
||||||
return new InvokeOnDisposal(() => unregisterBlockingOverlay(overlayContainer));
|
return new InvokeOnDisposal(() => unregisterBlockingOverlay(overlayContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
void IOverlayManager.ShowBlockingOverlay(OverlayContainer overlay)
|
||||||
/// 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))
|
if (!visibleBlockingOverlays.Contains(overlay))
|
||||||
visibleBlockingOverlays.Add(overlay);
|
visibleBlockingOverlays.Add(overlay);
|
||||||
updateBlockingOverlayFade();
|
updateBlockingOverlayFade();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
void IOverlayManager.HideBlockingOverlay(OverlayContainer overlay) => Schedule(() =>
|
||||||
/// 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);
|
visibleBlockingOverlays.Remove(overlay);
|
||||||
updateBlockingOverlayFade();
|
updateBlockingOverlayFade();
|
||||||
@ -240,6 +226,8 @@ namespace osu.Game
|
|||||||
overlayContainer.Expire();
|
overlayContainer.Expire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close all game-wide overlays.
|
/// Close all game-wide overlays.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
44
osu.Game/Overlays/IOverlayManager.cs
Normal file
44
osu.Game/Overlays/IOverlayManager.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Screens.Select;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays
|
||||||
|
{
|
||||||
|
[Cached]
|
||||||
|
internal interface IOverlayManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether overlays should be able to be opened game-wide. Value is sourced from the current active screen.
|
||||||
|
/// </summary>
|
||||||
|
IBindable<OverlayActivation> OverlayActivationMode { get; }
|
||||||
|
|
||||||
|
/// <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 a game 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>
|
||||||
|
IDisposable RegisterBlockingOverlay(OverlayContainer overlayContainer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Should be called when <paramref name="overlay"/> has been shown and should begin blocking background input.
|
||||||
|
/// </summary>
|
||||||
|
void ShowBlockingOverlay(OverlayContainer overlay);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Should be called when a blocking <paramref name="overlay"/> has been hidden and should stop blocking background input.
|
||||||
|
/// </summary>
|
||||||
|
void HideBlockingOverlay(OverlayContainer overlay);
|
||||||
|
}
|
||||||
|
}
|
@ -58,8 +58,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
|||||||
|
|
||||||
protected readonly IBindable<long?> RoomId = new Bindable<long?>();
|
protected readonly IBindable<long?> RoomId = new Bindable<long?>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved(CanBeNull = true)]
|
||||||
private OsuGame game { get; set; }
|
private IOverlayManager overlayManager { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
@ -264,7 +264,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
|||||||
beatmapAvailabilityTracker.SelectedItem.BindTo(SelectedItem);
|
beatmapAvailabilityTracker.SelectedItem.BindTo(SelectedItem);
|
||||||
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => updateWorkingBeatmap());
|
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => updateWorkingBeatmap());
|
||||||
|
|
||||||
userModsSelectOverlayRegistration = game?.RegisterBlockingOverlay(userModsSelectOverlay);
|
userModsSelectOverlayRegistration = overlayManager?.RegisterBlockingOverlay(userModsSelectOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
private IReadOnlyList<Mod> initialMods;
|
private IReadOnlyList<Mod> initialMods;
|
||||||
private bool itemSelected;
|
private bool itemSelected;
|
||||||
|
|
||||||
private FreeModSelectScreen freeModSelectOverlay;
|
private readonly FreeModSelectScreen freeModSelectOverlay;
|
||||||
private IDisposable freeModSelectOverlayRegistration;
|
private IDisposable freeModSelectOverlayRegistration;
|
||||||
|
|
||||||
protected OnlinePlaySongSelect(Room room)
|
protected OnlinePlaySongSelect(Room room)
|
||||||
@ -98,7 +98,7 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
Mods.BindValueChanged(onModsChanged);
|
Mods.BindValueChanged(onModsChanged);
|
||||||
Ruleset.BindValueChanged(onRulesetChanged);
|
Ruleset.BindValueChanged(onRulesetChanged);
|
||||||
|
|
||||||
freeModSelectOverlayRegistration = Game?.RegisterBlockingOverlay(freeModSelectOverlay);
|
freeModSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(freeModSelectOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
private void onModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||||
|
@ -124,7 +124,7 @@ namespace osu.Game.Screens.Select
|
|||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
protected new OsuGame Game { get; private set; }
|
internal IOverlayManager OverlayManager { get; private set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(AudioManager audio, IDialogOverlay dialog, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender)
|
private void load(AudioManager audio, IDialogOverlay dialog, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender)
|
||||||
@ -315,7 +315,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
modSelectOverlayRegistration = Game?.RegisterBlockingOverlay(ModSelect);
|
modSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(ModSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user