diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index c38036e926..e42cac1e1a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -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 { { "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(); 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().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().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) diff --git a/mods/cnc/chrome/ingame-menu.yaml b/mods/cnc/chrome/ingame-menu.yaml index ed8118926a..f7992af6f5 100644 --- a/mods/cnc/chrome/ingame-menu.yaml +++ b/mods/cnc/chrome/ingame-menu.yaml @@ -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: diff --git a/mods/common/chrome/ingame-menu.yaml b/mods/common/chrome/ingame-menu.yaml index bc0a97223c..ca83af6efd 100644 --- a/mods/common/chrome/ingame-menu.yaml +++ b/mods/common/chrome/ingame-menu.yaml @@ -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: diff --git a/mods/d2k/chrome/ingame-menu.yaml b/mods/d2k/chrome/ingame-menu.yaml index 8901a2ea4a..c19c87bb38 100644 --- a/mods/d2k/chrome/ingame-menu.yaml +++ b/mods/d2k/chrome/ingame-menu.yaml @@ -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: