Merge pull request #4373 from swoolcock/ensure-focused-overlay-dim

Ensure all OsuFocusedOverlayContainers contribute to screen fading
This commit is contained in:
Dan Balasescu 2019-03-01 13:39:52 +09:00 committed by GitHub
commit cf83be1cd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 14 deletions

View File

@ -24,7 +24,11 @@ namespace osu.Game.Graphics.Containers
protected override bool BlockNonPositionalInput => true;
private PreviewTrackManager previewTrackManager;
[Resolved(CanBeNull = true)]
private OsuGame osuGame { get; set; }
[Resolved]
private PreviewTrackManager previewTrackManager { get; set; }
protected readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
@ -36,10 +40,8 @@ namespace osu.Game.Graphics.Containers
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame, AudioManager audio, PreviewTrackManager previewTrackManager)
private void load(AudioManager audio)
{
this.previewTrackManager = previewTrackManager;
if (osuGame != null)
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
@ -93,6 +95,7 @@ namespace osu.Game.Graphics.Containers
if (OverlayActivationMode.Value != OverlayActivation.Disabled)
{
if (PlaySamplesOnStateChange) samplePopIn?.Play();
if (BlockScreenWideMouse) osuGame?.AddBlockingOverlay(this);
}
else
State = Visibility.Hidden;
@ -100,6 +103,7 @@ namespace osu.Game.Graphics.Containers
break;
case Visibility.Hidden:
if (PlaySamplesOnStateChange) samplePopOut?.Play();
if (BlockScreenWideMouse) osuGame?.RemoveBlockingOverlay(this);
break;
}
}
@ -109,5 +113,11 @@ namespace osu.Game.Graphics.Containers
base.PopOut();
previewTrackManager.StopAnyPlaying(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
osuGame?.RemoveBlockingOverlay(this);
}
}
}

View File

@ -110,6 +110,8 @@ namespace osu.Game
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
private readonly List<OverlayContainer> visibleBlockingOverlays = new List<OverlayContainer>();
// todo: move this to SongSelect once Screen has the ability to unsuspend.
[Cached]
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
@ -128,6 +130,22 @@ namespace osu.Game
public void ToggleDirect() => direct.ToggleVisibility();
private void updateBlockingOverlayFade() =>
screenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
public void AddBlockingOverlay(OverlayContainer overlay)
{
if (!visibleBlockingOverlays.Contains(overlay))
visibleBlockingOverlays.Add(overlay);
updateBlockingOverlayFade();
}
public void RemoveBlockingOverlay(OverlayContainer overlay)
{
visibleBlockingOverlays.Remove(overlay);
updateBlockingOverlayFade();
}
/// <summary>
/// Close all game-wide overlays.
/// </summary>
@ -598,20 +616,10 @@ namespace osu.Game
}
private Task asyncLoadStream;
private int visibleOverlayCount;
private void loadComponentSingleFile<T>(T d, Action<T> add)
where T : Drawable
{
if (d is FocusedOverlayContainer focused)
{
focused.StateChanged += s =>
{
visibleOverlayCount += s == Visibility.Visible ? 1 : -1;
screenContainer.FadeColour(visibleOverlayCount > 0 ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
};
}
// schedule is here to ensure that all component loads are done after LoadComplete is run (and thus all dependencies are cached).
// with some better organisation of LoadComplete to do construction and dependency caching in one step, followed by calls to loadComponentSingleFile,
// we could avoid the need for scheduling altogether.