Ensure all OsuFocusedOverlayContainers contribute to screen fading

This commit is contained in:
Shane Woolcock 2019-03-01 12:20:31 +09:00
parent c237c94a76
commit 5d1eacf1c1
2 changed files with 33 additions and 14 deletions

View File

@ -24,7 +24,11 @@ public class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrack
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 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
}
[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 @@ private void onStateChanged(Visibility visibility)
if (OverlayActivationMode.Value != OverlayActivation.Disabled)
{
if (PlaySamplesOnStateChange) samplePopIn?.Play();
if (BlockScreenWideMouse) osuGame?.AddBlockingOverlay(this);
}
else
State = Visibility.Hidden;
@ -100,6 +103,7 @@ private void onStateChanged(Visibility visibility)
break;
case Visibility.Hidden:
if (PlaySamplesOnStateChange) samplePopOut?.Play();
if (BlockScreenWideMouse) osuGame?.RemoveBlockingOverlay(this);
break;
}
}
@ -109,5 +113,11 @@ protected override void PopOut()
base.PopOut();
previewTrackManager.StopAnyPlaying(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
osuGame?.RemoveBlockingOverlay(this);
}
}
}

View File

@ -110,6 +110,8 @@ public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>
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,23 @@ public OsuGame(string[] args = null)
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)
{
if (visibleBlockingOverlays.Contains(overlay))
visibleBlockingOverlays.Remove(overlay);
updateBlockingOverlayFade();
}
/// <summary>
/// Close all game-wide overlays.
/// </summary>
@ -598,20 +617,10 @@ private void forwardLoggedErrorsToNotifications()
}
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.