Implement loading screens.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Widgets;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -26,31 +27,65 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("The widget tree to open when the map editor is loaded.")]
|
||||
public readonly string EditorRoot = "EDITOR_ROOT";
|
||||
|
||||
[Desc("The widget tree to open (in addition to INGAME_ROOT) while loading a saved game.")]
|
||||
public readonly string GameSaveLoadingRoot = "GAMESAVE_LOADING_SCREEN";
|
||||
|
||||
[Desc("Remove any existing UI when a map is loaded.")]
|
||||
public readonly bool ClearRoot = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new LoadWidgetAtGameStart(this); }
|
||||
}
|
||||
|
||||
public class LoadWidgetAtGameStart : IWorldLoaded
|
||||
public class LoadWidgetAtGameStart : IWorldLoaded, INotifyGameLoading, INotifyGameLoaded
|
||||
{
|
||||
readonly LoadWidgetAtGameStartInfo info;
|
||||
Widget root;
|
||||
|
||||
public LoadWidgetAtGameStart(LoadWidgetAtGameStartInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
void INotifyGameLoading.GameLoading(World world)
|
||||
{
|
||||
// Clear any existing widget state
|
||||
if (info.ClearRoot)
|
||||
Ui.ResetAll();
|
||||
|
||||
Ui.OpenWindow(info.GameSaveLoadingRoot, new WidgetArgs()
|
||||
{
|
||||
{ "world", world }
|
||||
});
|
||||
}
|
||||
|
||||
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
if (!world.IsLoadingGameSave && info.ClearRoot)
|
||||
Ui.ResetAll();
|
||||
|
||||
var widget = world.Type == WorldType.Shellmap ? info.ShellmapRoot :
|
||||
world.Type == WorldType.Editor ? info.EditorRoot : info.IngameRoot;
|
||||
|
||||
Game.LoadWidget(world, widget, Ui.Root, new WidgetArgs());
|
||||
root = Game.LoadWidget(world, widget, Ui.Root, new WidgetArgs());
|
||||
|
||||
// The Lua API requires the UI to available, so hide it instead
|
||||
if (world.IsLoadingGameSave)
|
||||
root.IsVisible = () => false;
|
||||
}
|
||||
|
||||
void INotifyGameLoaded.GameLoaded(World world)
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
root.IsVisible = () => true;
|
||||
|
||||
// Open the options menu
|
||||
if (!world.IsReplay)
|
||||
{
|
||||
var optionsButton = root.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
|
||||
world.SetPauseState(false);
|
||||
if (optionsButton != null)
|
||||
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, optionsButton.OnClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user