Merge pull request #5180 from pavlos256/abort-mission-confirmation

Closes #4650
This commit is contained in:
Matthias Mailänder
2014-04-22 22:09:48 +02:00
8 changed files with 115 additions and 4 deletions

View File

@@ -497,6 +497,7 @@
<Compile Include="ModChooserLoadScreen.cs" />
<Compile Include="Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="StartGameNotification.cs" />
<Compile Include="Widgets\ConfirmationDialogs.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -0,0 +1,42 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
{
public static class ConfirmationDialogs
{
public static void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel = null, string confirmText = null, string cancelText = null)
{
var prompt = Ui.OpenWindow("CONFIRM_PROMPT");
prompt.Get<LabelWidget>("PROMPT_TITLE").GetText = () => title;
prompt.Get<LabelWidget>("PROMPT_TEXT").GetText = () => text;
if (!string.IsNullOrEmpty(confirmText))
prompt.Get<ButtonWidget>("CONFIRM_BUTTON").GetText = () => confirmText;
if (!string.IsNullOrEmpty(cancelText))
prompt.Get<ButtonWidget>("CANCEL_BUTTON").GetText = () => cancelText;
prompt.Get<ButtonWidget>("CONFIRM_BUTTON").OnClick = () =>
{
Ui.CloseWindow();
onConfirm();
};
prompt.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Ui.CloseWindow();
if (onCancel != null)
onCancel();
};
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -19,11 +19,36 @@ namespace OpenRA.Mods.RA.Widgets.Logic
[ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer)
{
widget.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
Action onQuit = () =>
{
onExit();
LeaveGame(world);
};
Action onSurrender = () =>
{
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
onExit();
};
widget.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
{
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<ButtonWidget>("SETTINGS").OnClick = () =>
{
@@ -44,8 +69,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
widget.Get<ButtonWidget>("SURRENDER").OnClick = () =>
{
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
onExit();
widget.Visible = false;
ConfirmationDialogs.PromptConfirmAction(
"Surrender",
"Are you sure you want to surrender?",
onSurrender,
() => widget.Visible = true,
"Surrender");
};
widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;
}