mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 07:43:00 +08:00
Centralise caching of components at OsuGame level
This commit is contained in:
parent
6e0fbaa96d
commit
4b508915f6
@ -58,16 +58,8 @@ namespace osu.Game
|
||||
|
||||
private ChannelManager channelManager;
|
||||
|
||||
private MusicController musicController;
|
||||
|
||||
private NotificationOverlay notifications;
|
||||
|
||||
private LoginOverlay loginOverlay;
|
||||
|
||||
private DialogOverlay dialogOverlay;
|
||||
|
||||
private AccountCreationOverlay accountCreation;
|
||||
|
||||
private DirectOverlay direct;
|
||||
|
||||
private SocialOverlay social;
|
||||
@ -91,7 +83,6 @@ namespace osu.Game
|
||||
|
||||
private OsuScreenStack screenStack;
|
||||
private VolumeOverlay volume;
|
||||
private OnScreenDisplay onscreenDisplay;
|
||||
private OsuLogo osuLogo;
|
||||
|
||||
private MainMenu menuScreen;
|
||||
@ -124,10 +115,6 @@ namespace osu.Game
|
||||
RavenLogger = new RavenLogger(this);
|
||||
}
|
||||
|
||||
public void ToggleSettings() => settings.ToggleVisibility();
|
||||
|
||||
public void ToggleDirect() => direct.ToggleVisibility();
|
||||
|
||||
private void updateBlockingOverlayFade() =>
|
||||
screenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
|
||||
|
||||
@ -381,6 +368,8 @@ namespace osu.Game
|
||||
|
||||
Container logoContainer;
|
||||
|
||||
dependencies.CacheAs(idleTracker = new GameIdleTracker(6000));
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new VolumeControlReceptor
|
||||
@ -402,7 +391,7 @@ namespace osu.Game
|
||||
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
idleTracker = new GameIdleTracker(6000)
|
||||
idleTracker
|
||||
});
|
||||
|
||||
screenStack.ScreenPushed += screenPushed;
|
||||
@ -429,59 +418,44 @@ namespace osu.Game
|
||||
}, topMostOverlayContent.Add);
|
||||
|
||||
loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add);
|
||||
loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add);
|
||||
loadComponentSingleFile(new OnScreenDisplay(), Add, true);
|
||||
|
||||
loadComponentSingleFile(notifications = new NotificationOverlay
|
||||
{
|
||||
GetToolbarHeight = () => ToolbarOffset,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
}, rightFloatingOverlayContent.Add);
|
||||
}, rightFloatingOverlayContent.Add, true);
|
||||
|
||||
loadComponentSingleFile(screenshotManager, Add);
|
||||
|
||||
//overlay elements
|
||||
loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add);
|
||||
loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add);
|
||||
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal);
|
||||
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add);
|
||||
loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add);
|
||||
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add);
|
||||
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add);
|
||||
loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true);
|
||||
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add, true);
|
||||
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true);
|
||||
|
||||
loadComponentSingleFile(loginOverlay = new LoginOverlay
|
||||
loadComponentSingleFile(new LoginOverlay
|
||||
{
|
||||
GetToolbarHeight = () => ToolbarOffset,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
}, rightFloatingOverlayContent.Add);
|
||||
}, rightFloatingOverlayContent.Add, true);
|
||||
|
||||
loadComponentSingleFile(musicController = new MusicController
|
||||
loadComponentSingleFile(new MusicController
|
||||
{
|
||||
GetToolbarHeight = () => ToolbarOffset,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
}, rightFloatingOverlayContent.Add);
|
||||
}, rightFloatingOverlayContent.Add, true);
|
||||
|
||||
loadComponentSingleFile(accountCreation = new AccountCreationOverlay(), topMostOverlayContent.Add);
|
||||
loadComponentSingleFile(dialogOverlay = new DialogOverlay(), topMostOverlayContent.Add);
|
||||
loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true);
|
||||
loadComponentSingleFile(new DialogOverlay(), topMostOverlayContent.Add, true);
|
||||
loadComponentSingleFile(externalLinkOpener = new ExternalLinkOpener(), topMostOverlayContent.Add);
|
||||
|
||||
dependencies.CacheAs(idleTracker);
|
||||
dependencies.Cache(settings);
|
||||
dependencies.Cache(onscreenDisplay);
|
||||
dependencies.Cache(social);
|
||||
dependencies.Cache(direct);
|
||||
dependencies.Cache(chatOverlay);
|
||||
dependencies.Cache(channelManager);
|
||||
dependencies.Cache(userProfile);
|
||||
dependencies.Cache(musicController);
|
||||
dependencies.Cache(beatmapSetOverlay);
|
||||
dependencies.Cache(notifications);
|
||||
dependencies.Cache(loginOverlay);
|
||||
dependencies.Cache(dialogOverlay);
|
||||
dependencies.Cache(accountCreation);
|
||||
|
||||
chatOverlay.StateChanged += state => channelManager.HighPollRate.Value = state == Visibility.Visible;
|
||||
|
||||
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||
@ -610,9 +584,12 @@ namespace osu.Game
|
||||
|
||||
private Task asyncLoadStream;
|
||||
|
||||
private void loadComponentSingleFile<T>(T d, Action<T> add)
|
||||
private void loadComponentSingleFile<T>(T d, Action<T> add, bool cache = false)
|
||||
where T : Drawable
|
||||
{
|
||||
if (cache)
|
||||
dependencies.Cache(d);
|
||||
|
||||
// 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.
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Screens.Multi;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Screens.Tournament;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
@ -45,7 +46,7 @@ namespace osu.Game.Screens.Menu
|
||||
protected override BackgroundScreen CreateBackground() => background;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuGame game = null)
|
||||
private void load(DirectOverlay direct, SettingsOverlay settings)
|
||||
{
|
||||
if (host.CanExit)
|
||||
AddInternal(new ExitConfirmOverlay { Action = this.Exit });
|
||||
@ -86,11 +87,8 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
};
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
buttons.OnSettings = game.ToggleSettings;
|
||||
buttons.OnDirect = game.ToggleDirect;
|
||||
}
|
||||
buttons.OnSettings = () => settings?.ToggleVisibility();
|
||||
buttons.OnDirect = () => direct?.ToggleVisibility();
|
||||
|
||||
LoadComponentAsync(background = new BackgroundScreenDefault());
|
||||
preloadSongSelect();
|
||||
|
Loading…
Reference in New Issue
Block a user