Simplify overlay adding logic

This commit is contained in:
Dean Herbert 2019-11-12 15:03:58 +09:00
parent e28ddec8d6
commit 25eb964290

View File

@ -593,14 +593,14 @@ namespace osu.Game
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true); loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true);
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true); loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true);
var login = loadComponentSingleFile(new LoginOverlay loadComponentSingleFile(new LoginOverlay
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add, true); }, rightFloatingOverlayContent.Add, true);
var nowPlaying = loadComponentSingleFile(new NowPlayingOverlay loadComponentSingleFile(new NowPlayingOverlay
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -615,10 +615,10 @@ namespace osu.Game
Add(externalLinkOpener = new ExternalLinkOpener()); Add(externalLinkOpener = new ExternalLinkOpener());
// side overlays which cancel each other.
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications }; var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications };
overlays.AddRange(singleDisplaySideOverlays);
foreach (var overlay in singleDisplaySideOverlays) foreach (var overlay in new OverlayContainer[] { Settings, notifications })
{ {
overlay.State.ValueChanged += state => overlay.State.ValueChanged += state =>
{ {
@ -630,7 +630,6 @@ namespace osu.Game
// eventually informational overlays should be displayed in a stack, but for now let's only allow one to stay open at a time. // eventually informational overlays should be displayed in a stack, but for now let's only allow one to stay open at a time.
var informationalOverlays = new OverlayContainer[] { beatmapSetOverlay, userProfile }; var informationalOverlays = new OverlayContainer[] { beatmapSetOverlay, userProfile };
overlays.AddRange(informationalOverlays);
foreach (var overlay in informationalOverlays) foreach (var overlay in informationalOverlays)
{ {
@ -644,7 +643,6 @@ namespace osu.Game
// ensure only one of these overlays are open at once. // ensure only one of these overlays are open at once.
var singleDisplayOverlays = new OverlayContainer[] { chatOverlay, social, direct, changelogOverlay }; var singleDisplayOverlays = new OverlayContainer[] { chatOverlay, social, direct, changelogOverlay };
overlays.AddRange(singleDisplayOverlays);
foreach (var overlay in singleDisplayOverlays) foreach (var overlay in singleDisplayOverlays)
{ {
@ -659,8 +657,6 @@ namespace osu.Game
}; };
} }
overlays.AddRange(new OverlayContainer[] { login, nowPlaying });
OverlayActivationMode.ValueChanged += mode => OverlayActivationMode.ValueChanged += mode =>
{ {
if (mode.NewValue != OverlayActivation.All) CloseAllOverlays(); if (mode.NewValue != OverlayActivation.All) CloseAllOverlays();
@ -747,6 +743,9 @@ namespace osu.Game
if (cache) if (cache)
dependencies.Cache(d); dependencies.Cache(d);
if (d is OverlayContainer overlay)
overlays.Add(overlay);
// schedule is here to ensure that all component loads are done after LoadComplete is run (and thus all dependencies are cached). // 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, // 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. // we could avoid the need for scheduling altogether.