Loading Screens
What is a loading screen?
Loading screens are shown when entering a game server. During loading the client connects to the server, downloads the game, map and any addons, and then actually joins the game.
The loading screen usually shows progress indicating which of these things it's doing. It's also nice to have a cancel button.
Defining Your Loading Screen
When your game is opened in the menu, we look in your game for a Panel
or RootPanel
that implements the Sandbox.Menu.ILoadingScreenPanel
interface. If we find it, then we create it and that's your loading screen.
So to create a loading screen panel in plain c#, you'd do something like this.
or to define one in Razor you'd do
From there you can add stylesheets and panels as you would normally define any UI.
Resources
Much like the Game Menu, you can add specific resources to download before the rest that are required for your loading screen.
You just add them into your project settings Menu files.
Your Game Menu and Loading Screen resources will both be in this list and both be downloaded before loading up your menu!
LoadingProgress
The OnLoadingProgress
method receives a LoadingProgress
struct from the engine. This holds information on the current load progress.
Cancelling
To cancel, just call Game.Menu.CancelLoading()
. You can easily wire a button up to do this in Razor like this.