Add restart button to main menu for single player (missions, skirmish, replays)

This commit is contained in:
Ivaylo Draganov
2019-06-10 00:15:35 +03:00
committed by Paul Chote
parent baa50c9c53
commit 2204e807b8
4 changed files with 44 additions and 26 deletions

View File

@@ -32,6 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly World world;
readonly WorldRenderer worldRenderer;
readonly MenuPaletteEffect mpe;
readonly bool isSinglePlayer;
bool hasError;
bool leaving;
bool hideMenu;
@@ -48,6 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var buttonHandlers = new Dictionary<string, Action>
{
{ "ABORT_MISSION", CreateAbortMissionButton },
{ "RESTART", CreateRestartButton },
{ "SURRENDER", CreateSurrenderButton },
{ "LOAD_GAME", CreateLoadGameButton },
{ "SAVE_GAME", CreateSaveGameButton },
@@ -58,6 +60,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "EXIT_EDITOR", CreateExitEditorButton }
};
isSinglePlayer = !world.LobbyInfo.GlobalSettings.Dedicated && world.LobbyInfo.NonBotClients.Count() == 1;
menu = widget.Get("INGAME_MENU");
mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
if (mpe != null)
@@ -192,41 +196,55 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Won)
{
Action restartAction = null;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop != null ? iop.ExitDelay : 0;
if (!world.LobbyInfo.GlobalSettings.Dedicated && world.LobbyInfo.NonBotClients.Count() == 1)
{
restartAction = () =>
{
Ui.CloseWindow();
if (mpe != null)
{
if (Game.IsCurrentWorld(world))
mpe.Fade(MenuPaletteEffect.EffectType.Black);
exitDelay += 40 * mpe.Info.FadeLength;
}
Game.RunAfterDelay(exitDelay, Game.RestartGame);
};
}
ConfirmationDialogs.ButtonPrompt(
title: "Leave Mission",
text: "Leave this game and return to the menu?",
onConfirm: OnQuit,
onCancel: ShowMenu,
confirmText: "Leave",
cancelText: "Stay",
otherText: "Restart",
onOther: restartAction);
cancelText: "Stay");
}
else
OnQuit();
};
}
void CreateRestartButton()
{
if (world.Type != WorldType.Regular || !isSinglePlayer)
return;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop != null ? iop.ExitDelay : 0;
Action onRestart = () =>
{
Ui.CloseWindow();
if (mpe != null)
{
if (Game.IsCurrentWorld(world))
mpe.Fade(MenuPaletteEffect.EffectType.Black);
exitDelay += 40 * mpe.Info.FadeLength;
}
Game.RunAfterDelay(exitDelay, Game.RestartGame);
};
var button = AddButton("RESTART", "Restart");
button.IsDisabled = () => hasError || leaving;
button.OnClick = () =>
{
hideMenu = true;
ConfirmationDialogs.ButtonPrompt(
title: "Restart",
text: "Are you sure you want to restart?",
onConfirm: onRestart,
onCancel: ShowMenu,
confirmText: "Restart",
cancelText: "Stay");
};
}
void CreateSurrenderButton()
{
if (world.Type != WorldType.Regular || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) || world.LocalPlayer == null)

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
Logic: IngameMenuLogic
Buttons: EXIT_EDITOR, SAVE_MAP, ABORT_MISSION, SURRENDER, LOAD_GAME, SAVE_GAME, MUSIC, SETTINGS, RESUME
Buttons: EXIT_EDITOR, SAVE_MAP, ABORT_MISSION, SURRENDER, RESTART, LOAD_GAME, SAVE_GAME, MUSIC, SETTINGS, RESUME
ButtonStride: 130, 0
Children:
Image@EVA:

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
Logic: IngameMenuLogic
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, ABORT_MISSION, SAVE_MAP, EXIT_EDITOR
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, ABORT_MISSION, SAVE_MAP, EXIT_EDITOR
ButtonStride: 0, 40
Children:
Background@BORDER:

View File

@@ -2,7 +2,7 @@ Container@INGAME_MENU:
Width: WINDOW_RIGHT
Height: WINDOW_BOTTOM
Logic: IngameMenuLogic
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, ABORT_MISSION, SAVE_MAP, EXIT_EDITOR
Buttons: RESUME, LOAD_GAME, SAVE_GAME, SETTINGS, MUSIC, SURRENDER, RESTART, ABORT_MISSION, SAVE_MAP, EXIT_EDITOR
ButtonStride: 0, 40
Children:
Label@VERSION_LABEL: