Implement loading screens.
This commit is contained in:
@@ -634,6 +634,7 @@
|
||||
<Compile Include="UtilityCommands\PngSheetImportMetadataCommand.cs" />
|
||||
<Compile Include="Widgets\Logic\Editor\ActorEditLogic.cs" />
|
||||
<Compile Include="Widgets\ExponentialSliderWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\GameSaveLoadingLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\MusicHotkeyLogic.cs" />
|
||||
<Compile Include="WorldExtensions.cs" />
|
||||
<Compile Include="UtilityCommands\GetMapHashCommand.cs" />
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); }
|
||||
}
|
||||
|
||||
public class MenuPaletteEffect : IPaletteModifier, IRender, IWorldLoaded
|
||||
public class MenuPaletteEffect : IPaletteModifier, IRender, IWorldLoaded, INotifyGameLoaded
|
||||
{
|
||||
public enum EffectType { None, Black, Desaturated }
|
||||
public readonly MenuPaletteEffectInfo Info;
|
||||
@@ -110,9 +110,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
Fade(Info.Effect);
|
||||
// HACK: Defer fade-in until the GameLoaded notification for game saves
|
||||
if (!w.IsLoadingGameSave)
|
||||
Fade(Info.Effect);
|
||||
}
|
||||
|
||||
void INotifyGameLoaded.GameLoaded(World world)
|
||||
{
|
||||
// HACK: Let the menu opening trigger the fade for game saves
|
||||
// to avoid glitches resulting from trying to trigger both
|
||||
// the standard and menu fades at the same time
|
||||
if (world.IsReplay)
|
||||
Fade(Info.Effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -38,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new MusicPlaylist(init.World, this); }
|
||||
}
|
||||
|
||||
public class MusicPlaylist : INotifyActorDisposing, IGameOver
|
||||
public class MusicPlaylist : INotifyActorDisposing, IGameOver, IWorldLoaded, INotifyGameLoaded
|
||||
{
|
||||
readonly MusicPlaylistInfo info;
|
||||
readonly World world;
|
||||
@@ -89,7 +90,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
currentSong = world.Map.Rules.Music[info.StartingMusic];
|
||||
CurrentSongIsBackground = false;
|
||||
}
|
||||
}
|
||||
|
||||
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
if (!world.IsLoadingGameSave)
|
||||
Play();
|
||||
}
|
||||
|
||||
void INotifyGameLoaded.GameLoaded(World world)
|
||||
{
|
||||
Play();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
||||
if (!world.IsLoadingGameSave)
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class GameSaveLoadingLogic : ChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public GameSaveLoadingLogic(Widget widget, ModData modData, World world)
|
||||
{
|
||||
widget.Get<ProgressBarWidget>("PROGRESS").GetPercentage = () => world.GameSaveLoadingPercentage;
|
||||
|
||||
var versionLabel = widget.GetOrNull<LabelWidget>("VERSION_LABEL");
|
||||
if (versionLabel != null)
|
||||
versionLabel.Text = modData.Manifest.Metadata.Version;
|
||||
|
||||
var keyhandler = widget.Get<LogicKeyListenerWidget>("CANCEL_HANDLER");
|
||||
keyhandler.AddHandler(e =>
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down && e.Key == Keycode.ESCAPE)
|
||||
{
|
||||
Game.Disconnect();
|
||||
Ui.ResetAll();
|
||||
Game.LoadShellMap();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
Game.HideCursor = true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
Game.HideCursor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user