Add restart button to main menu for single player (missions, skirmish, replays)
This commit is contained in:
committed by
Paul Chote
parent
baa50c9c53
commit
2204e807b8
@@ -32,6 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly World world;
|
readonly World world;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly MenuPaletteEffect mpe;
|
readonly MenuPaletteEffect mpe;
|
||||||
|
readonly bool isSinglePlayer;
|
||||||
bool hasError;
|
bool hasError;
|
||||||
bool leaving;
|
bool leaving;
|
||||||
bool hideMenu;
|
bool hideMenu;
|
||||||
@@ -48,6 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var buttonHandlers = new Dictionary<string, Action>
|
var buttonHandlers = new Dictionary<string, Action>
|
||||||
{
|
{
|
||||||
{ "ABORT_MISSION", CreateAbortMissionButton },
|
{ "ABORT_MISSION", CreateAbortMissionButton },
|
||||||
|
{ "RESTART", CreateRestartButton },
|
||||||
{ "SURRENDER", CreateSurrenderButton },
|
{ "SURRENDER", CreateSurrenderButton },
|
||||||
{ "LOAD_GAME", CreateLoadGameButton },
|
{ "LOAD_GAME", CreateLoadGameButton },
|
||||||
{ "SAVE_GAME", CreateSaveGameButton },
|
{ "SAVE_GAME", CreateSaveGameButton },
|
||||||
@@ -58,6 +60,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{ "EXIT_EDITOR", CreateExitEditorButton }
|
{ "EXIT_EDITOR", CreateExitEditorButton }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
isSinglePlayer = !world.LobbyInfo.GlobalSettings.Dedicated && world.LobbyInfo.NonBotClients.Count() == 1;
|
||||||
|
|
||||||
menu = widget.Get("INGAME_MENU");
|
menu = widget.Get("INGAME_MENU");
|
||||||
mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
||||||
if (mpe != null)
|
if (mpe != null)
|
||||||
@@ -192,41 +196,55 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
if (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Won)
|
if (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Won)
|
||||||
{
|
{
|
||||||
Action restartAction = null;
|
|
||||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().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(
|
ConfirmationDialogs.ButtonPrompt(
|
||||||
title: "Leave Mission",
|
title: "Leave Mission",
|
||||||
text: "Leave this game and return to the menu?",
|
text: "Leave this game and return to the menu?",
|
||||||
onConfirm: OnQuit,
|
onConfirm: OnQuit,
|
||||||
onCancel: ShowMenu,
|
onCancel: ShowMenu,
|
||||||
confirmText: "Leave",
|
confirmText: "Leave",
|
||||||
cancelText: "Stay",
|
cancelText: "Stay");
|
||||||
otherText: "Restart",
|
|
||||||
onOther: restartAction);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
OnQuit();
|
OnQuit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateRestartButton()
|
||||||
|
{
|
||||||
|
if (world.Type != WorldType.Regular || !isSinglePlayer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().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()
|
void CreateSurrenderButton()
|
||||||
{
|
{
|
||||||
if (world.Type != WorldType.Regular || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) || world.LocalPlayer == null)
|
if (world.Type != WorldType.Regular || world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) || world.LocalPlayer == null)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Container@INGAME_MENU:
|
|||||||
Width: WINDOW_RIGHT
|
Width: WINDOW_RIGHT
|
||||||
Height: WINDOW_BOTTOM
|
Height: WINDOW_BOTTOM
|
||||||
Logic: IngameMenuLogic
|
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
|
ButtonStride: 130, 0
|
||||||
Children:
|
Children:
|
||||||
Image@EVA:
|
Image@EVA:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Container@INGAME_MENU:
|
|||||||
Width: WINDOW_RIGHT
|
Width: WINDOW_RIGHT
|
||||||
Height: WINDOW_BOTTOM
|
Height: WINDOW_BOTTOM
|
||||||
Logic: IngameMenuLogic
|
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
|
ButtonStride: 0, 40
|
||||||
Children:
|
Children:
|
||||||
Background@BORDER:
|
Background@BORDER:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Container@INGAME_MENU:
|
|||||||
Width: WINDOW_RIGHT
|
Width: WINDOW_RIGHT
|
||||||
Height: WINDOW_BOTTOM
|
Height: WINDOW_BOTTOM
|
||||||
Logic: IngameMenuLogic
|
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
|
ButtonStride: 0, 40
|
||||||
Children:
|
Children:
|
||||||
Label@VERSION_LABEL:
|
Label@VERSION_LABEL:
|
||||||
|
|||||||
Reference in New Issue
Block a user