From e0c033fe99e51d51b57ae7c267442e5cc7277d95 Mon Sep 17 00:00:00 2001 From: Alexander Heinz Date: Sat, 31 Jan 2015 13:58:19 +0100 Subject: [PATCH] restart button added for singleplayer in cnc, ra, d2k --- OpenRA.Game/Game.cs | 6 +++ .../Widgets/ConfirmationDialogs.cs | 33 ++++++++++++++ .../Widgets/Logic/Ingame/IngameMenuLogic.cs | 2 +- mods/cnc/chrome/dialogs.yaml | 44 +++++++++++++++++++ mods/ra/chrome/confirmation-dialogs.yaml | 42 ++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 6d42f0ef8a..9377e34647 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -175,6 +175,12 @@ namespace OpenRA GC.Collect(); } + public static void RestartGame() + { + OrderManager.World.EndGame(); + StartGame(OrderManager.World.Map.Uid, WorldType.Regular); + } + public static bool IsHost { get diff --git a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs index 0ec0ffae83..2ce75fd7f3 100644 --- a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs +++ b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs @@ -55,6 +55,39 @@ namespace OpenRA.Mods.Common.Widgets onCancel(); }; } + /** + * open confirmation dialog for mission / game restart + */ + public static void PromptAbortMission(World world, string title, string text, Action onAbort, Action onCancel = null, Action closeMenu = null) + { + var isMultiplayer = !world.LobbyInfo.IsSinglePlayer && !world.IsReplay; + var prompt = Ui.OpenWindow("ABORT_MISSION_PROMPT"); + prompt.Get("PROMPT_TITLE").GetText = () => title; + prompt.Get("PROMPT_TEXT").GetText = () => text; + prompt.Get("ABORT_BUTTON").OnClick = () => + { + Ui.CloseWindow(); + onAbort(); + }; + + var restartButton = prompt.Get("RESTART_BUTTON"); + restartButton.IsVisible = () => !isMultiplayer; + restartButton.OnClick = () => + { + if (closeMenu != null) + closeMenu(); + + Ui.CloseWindow(); + Game.RestartGame(); + }; + + prompt.Get("CANCEL_BUTTON").OnClick = () => + { + Ui.CloseWindow(); + if (onCancel != null) + onCancel(); + }; + } public static void TextInputPrompt( string title, string prompt, string initialText, diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 81ff05725b..864248feda 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } hideMenu = true; - ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, showMenu); + ConfirmationDialogs.PromptAbortMission(world, "Abort Mission", "Leave this game and return to the menu?", onQuit, showMenu, closeMenu); }; var exitEditorButton = menu.Get("EXIT_EDITOR"); diff --git a/mods/cnc/chrome/dialogs.yaml b/mods/cnc/chrome/dialogs.yaml index e292799449..346aa70923 100644 --- a/mods/cnc/chrome/dialogs.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -200,6 +200,50 @@ Container@CANCEL_PROMPT: Height: 35 Text: Cancel +Container@ABORT_MISSION_PROMPT: + X: (WINDOW_RIGHT - WIDTH)/2 + Y: (WINDOW_BOTTOM - 90)/2 + Width: 500 + Height: 125 + Children: + Label@PROMPT_TITLE: + Width: PARENT_RIGHT + Y: 0-25 + Font: BigBold + Contrast: true + Align: Center + Background@bg: + Width: 500 + Height: 90 + Background: panel-black + Children: + Label@PROMPT_TEXT: + Y: (PARENT_BOTTOM-HEIGHT)/2 + Width: PARENT_RIGHT + Height: 25 + Font: Bold + Align: Center + Button@ABORT_BUTTON: + Key: return + X: 360 + Y: 89 + Width: 140 + Height: 35 + Text: Abort + Button@RESTART_BUTTON: + Key: r + X: 180 + Y: 89 + Width: 140 + Height: 35 + Text: Restart + Button@CANCEL_BUTTON: + Key: escape + Y: 89 + Width: 140 + Height: 35 + Text: Cancel + Container@TEXT_INPUT_PROMPT: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2 diff --git a/mods/ra/chrome/confirmation-dialogs.yaml b/mods/ra/chrome/confirmation-dialogs.yaml index 89274a021b..81ebff6341 100644 --- a/mods/ra/chrome/confirmation-dialogs.yaml +++ b/mods/ra/chrome/confirmation-dialogs.yaml @@ -33,6 +33,48 @@ Background@CONFIRM_PROMPT: Font: Bold Key: escape +Background@ABORT_MISSION_PROMPT: + X: (WINDOW_RIGHT - WIDTH)/2 + Y: (WINDOW_BOTTOM - 90)/2 + Width: 600 + Height: 175 + Children: + Label@PROMPT_TITLE: + Width: PARENT_RIGHT + Y: 20 + Height: 25 + Font: Bold + Align: Center + Label@PROMPT_TEXT: + X: 15 + Y: 50 + Width: PARENT_RIGHT - 30 + Height: 65 + Align: Center + Button@ABORT_BUTTON: + X: 20 + Y: PARENT_BOTTOM - 45 + Width: 160 + Height: 25 + Text: Abort + Font: Bold + Key: return + Button@RESTART_BUTTON: + X: PARENT_RIGHT - 380 + Y: PARENT_BOTTOM - 45 + Width: 160 + Height: 25 + Text: Restart + Font: Bold + Button@CANCEL_BUTTON: + X: PARENT_RIGHT - 180 + Y: PARENT_BOTTOM - 45 + Width: 160 + Height: 25 + Text: Cancel + Font: Bold + Key: escape + Background@CANCEL_PROMPT: X: (WINDOW_RIGHT - WIDTH)/2 Y: (WINDOW_BOTTOM - 90)/2