diff --git a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs index 0e1d0f374d..65cc348d09 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs @@ -80,13 +80,15 @@ namespace OpenRA.Mods.Cnc.Widgets public class CncIngameMenuLogic : IWidgetDelegate { + Widget menu; + [ObjectCreator.UseCtor] public CncIngameMenuLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] World world, [ObjectCreator.Param] Action onExit) { - var menu = widget.GetWidget("INGAME_MENU"); - menu.GetWidget("QUIT_BUTTON").OnClick = () => + menu = widget.GetWidget("INGAME_MENU"); + var onQuit = (Action)(() => { Game.DisconnectOnly(); @@ -94,13 +96,45 @@ namespace OpenRA.Mods.Cnc.Widgets Game.LoadShellMap(); Widget.RootWidget.RemoveChildren(); Widget.LoadWidget("MENU_BACKGROUND", new Dictionary()); - }; + }); + + var doNothing = (Action)(() => {}); + + menu.GetWidget("QUIT_BUTTON").OnClick = () => + PromptConfirmAction("Exit Game", "Are you sure you want to leave the game?", onQuit, doNothing); + + var onSurrender = (Action)(() => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false))); + var surrenderButton = menu.GetWidget("SURRENDER_BUTTON"); + surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined); + surrenderButton.OnClick = () => + PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing); menu.GetWidget("RESUME_BUTTON").OnClick = () => { Widget.RootWidget.RemoveChild(menu); - onExit(); + onExit(); }; } + + public void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel) + { + var prompt = menu.GetWidget("CONFIRM_PROMPT"); + + prompt.GetWidget("PROMPT_TITLE").GetText = () => title; + prompt.GetWidget("PROMPT_TEXT").GetText = () => text; + + prompt.GetWidget("CONFIRM_BUTTON").OnClick = () => + { + prompt.IsVisible = () => false; + onConfirm(); + }; + + prompt.GetWidget("CANCEL_BUTTON").OnClick = () => + { + prompt.IsVisible = () => false; + onCancel(); + }; + prompt.IsVisible = () => true; + } } } diff --git a/mods/cnc/chrome/ingamemenu.yaml b/mods/cnc/chrome/ingamemenu.yaml index 66d6e00733..5128c2f4a1 100644 --- a/mods/cnc/chrome/ingamemenu.yaml +++ b/mods/cnc/chrome/ingamemenu.yaml @@ -51,4 +51,45 @@ Container@INGAME_MENU: Y:0 Width:140 Height:35 - Text:Resume \ No newline at end of file + Text:Resume + Container@CONFIRM_PROMPT: + Id:CONFIRM_PROMPT + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - 90)/2 + Width:370 + Height:125 + Visible:false + Children: + Label@PROMPT_TITLE: + Id:PROMPT_TITLE + Width:PARENT_RIGHT + Y:0-25 + Font:BigBold + Contrast:true + Align:Center + Background@bg: + Width:370 + Height:90 + Background:panel-black + Children: + Label@PROMPT_TEXT: + Id:PROMPT_TEXT + Y:(PARENT_BOTTOM-HEIGHT)/2 + Width:PARENT_RIGHT + Height:25 + Font:Bold + WordWrap:true + Align:Center + CncMenuButton@CANCEL_BUTTON: + Id:CANCEL_BUTTON + Y:89 + Width:140 + Height:35 + Text:Cancel + CncMenuButton@CONFIRM_BUTTON: + Id:CONFIRM_BUTTON + X:230 + Y:89 + Width:140 + Height:35 + Text:Confirm \ No newline at end of file