From 6ed6288e53bc311c323d876ca5caa59aeedfbf62 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Tue, 22 Apr 2014 22:20:45 +0300 Subject: [PATCH] Hide ingame menu before showing the confirmation dialog As a bonus, don't show the confirmation dialog if the game is over. --- .../Widgets/Logic/IngameMenuLogic.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs index 6a3b4010a1..81817efe04 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs @@ -19,18 +19,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic [ObjectCreator.UseCtor] public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer) { + Action onQuit = () => + { + onExit(); + LeaveGame(world); + }; + Action onSurrender = () => + { + world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); + onExit(); + }; + widget.Get("DISCONNECT").OnClick = () => { - ConfirmationDialogs.PromptConfirmAction( - "Abort Mission", - "Leave this game and return to the menu?", - () => - { - onExit(); - LeaveGame(world); - }, - null, - "Abort"); + bool gameOver = world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined; + + if (gameOver) + { + onQuit(); + } + else + { + widget.Visible = false; + ConfirmationDialogs.PromptConfirmAction( + "Abort Mission", + "Leave this game and return to the menu?", + onQuit, + () => widget.Visible = true, + "Abort"); + } }; widget.Get("SETTINGS").OnClick = () => @@ -52,15 +69,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic widget.Get("SURRENDER").OnClick = () => { + widget.Visible = false; ConfirmationDialogs.PromptConfirmAction( "Surrender", "Are you sure you want to surrender?", - () => - { - world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); - onExit(); - }, - null, + onSurrender, + () => widget.Visible = true, "Surrender"); }; widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;