From 819eb6401167ca815e60a5c256e56620c0da1576 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 31 Jul 2014 21:24:08 +0200 Subject: [PATCH] Add end game dialog --- OpenRA.Game/Widgets/Widget.cs | 5 + .../Widgets/Logic/IngameChromeLogic.cs | 8 ++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + .../Widgets/Logic/Ingame/LeaveMapLogic.cs | 70 +++++++++++++ .../LoadIngamePlayerOrObserverUILogic.cs | 8 ++ mods/cnc/chrome/ingame-leavemap.yaml | 98 ++++++++++++++++++ mods/cnc/mod.yaml | 1 + mods/d2k/chrome/ingame-leavemap.yaml | 92 +++++++++++++++++ mods/d2k/mod.yaml | 1 + mods/ra/chrome/ingame-leavemap.yaml | 99 +++++++++++++++++++ mods/ra/mod.yaml | 1 + mods/ts/mod.yaml | 1 + 12 files changed, 385 insertions(+) create mode 100644 OpenRA.Mods.RA/Widgets/Logic/Ingame/LeaveMapLogic.cs create mode 100644 mods/cnc/chrome/ingame-leavemap.yaml create mode 100644 mods/d2k/chrome/ingame-leavemap.yaml create mode 100644 mods/ra/chrome/ingame-leavemap.yaml diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 030fba1e7e..4ef77ecd88 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -51,6 +51,11 @@ namespace OpenRA.Widgets return window; } + public static Widget CurrentWindow() + { + return WindowList.Count > 0 ? WindowList.Peek() : null; + } + public static T LoadWidget(string id, Widget parent, WidgetArgs args) where T : Widget { var widget = LoadWidget(id, parent, args) as T; diff --git a/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs b/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs index a7f254bc0a..4c7ddeb0d2 100644 --- a/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs +++ b/OpenRA.Mods.D2k/Widgets/Logic/IngameChromeLogic.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Drawing; using System.Linq; using OpenRA.Mods.RA; @@ -43,6 +44,13 @@ namespace OpenRA.Mods.D2k.Widgets.Logic void InitRootWidgets() { Game.LoadWidget(world, "CHAT_PANEL", gameRoot, new WidgetArgs()); + + Action ShowLeaveRestartDialog = () => + { + gameRoot.IsVisible = () => false; + Game.LoadWidget(world, "LEAVE_RESTART_WIDGET", Ui.Root, new WidgetArgs()); + }; + world.GameOver += ShowLeaveRestartDialog; } void InitObserverWidgets() diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index d62d7d5450..85dab4f5b9 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -377,6 +377,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/Ingame/LeaveMapLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/Ingame/LeaveMapLogic.cs new file mode 100644 index 0000000000..f8f1405e54 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/Ingame/LeaveMapLogic.cs @@ -0,0 +1,70 @@ +#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.Linq; +using OpenRA.Network; +using OpenRA.Traits; +using OpenRA.Widgets; +using OpenRA.Mods.RA; + +namespace OpenRA.Mods.RA.Widgets +{ + class LeaveMapLogic + { + [ObjectCreator.UseCtor] + public LeaveMapLogic(Widget widget, OrderManager orderManager, World world) + { + widget.Get("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version; + + var panelName = "LEAVE_RESTART_SIMPLE"; + + var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); + var showObjectives = iop != null && iop.PanelName != null && world.LocalPlayer != null; + + if (showObjectives) + panelName = "LEAVE_RESTART_FULL"; + + var dialog = widget.Get(panelName); + var fmvPlayer = Ui.Root.GetOrNull("FMVPLAYER"); + dialog.IsVisible = () => true; + widget.IsVisible = () => fmvPlayer == null || fmvPlayer != Ui.CurrentWindow(); + + var leaveButton = dialog.Get("LEAVE_BUTTON"); + leaveButton.OnClick = () => + { + leaveButton.Disabled = true; + var mpe = world.WorldActor.TraitOrDefault(); + + Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", + world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race); + + var exitDelay = 1200; + if (mpe != null) + { + Game.RunAfterDelay(exitDelay, () => mpe.Fade(MenuPaletteEffect.EffectType.Black)); + exitDelay += 40 * mpe.Info.FadeLength; + } + + Game.RunAfterDelay(exitDelay, () => + { + Game.Disconnect(); + Ui.ResetAll(); + Game.LoadShellMap(); + }); + }; + + if (showObjectives) + { + var objectivesContainer = dialog.Get("OBJECTIVES"); + Game.LoadWidget(world, iop.PanelName, objectivesContainer, new WidgetArgs()); + } + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs b/OpenRA.Mods.RA/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs index 201007bd86..91e1f7c60a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic @@ -26,6 +27,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs()); Game.LoadWidget(world, "CHAT_PANEL", ingameRoot, new WidgetArgs()); + + Action ShowLeaveRestartDialog = () => + { + ingameRoot.IsVisible = () => false; + Game.LoadWidget(world, "LEAVE_RESTART_WIDGET", Ui.Root, new WidgetArgs()); + }; + world.GameOver += ShowLeaveRestartDialog; } } } diff --git a/mods/cnc/chrome/ingame-leavemap.yaml b/mods/cnc/chrome/ingame-leavemap.yaml new file mode 100644 index 0000000000..1b150db223 --- /dev/null +++ b/mods/cnc/chrome/ingame-leavemap.yaml @@ -0,0 +1,98 @@ +Container@LEAVE_RESTART_WIDGET: + Logic: LeaveMapLogic + Children: + Image@EVA: + X: WINDOW_RIGHT-128-43 + Y: 43 + Width: 128 + Height: 64 + ImageCollection: logos + ImageName: eva + Label@VERSION_LABEL: + X: WINDOW_RIGHT-128-43 + Y: 115 + Width: 128 + Align: Center + Contrast: true + Background@BORDER: + Width: WINDOW_RIGHT + Height: WINDOW_BOTTOM + Background: shellmapborder + Container@LEAVE_RESTART_SIMPLE + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 370 + Height: 125 + Visible: False + Children: + Background@LEAVE_RESTART_SIMPLE_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 35 + Background: panel-black + Children: + Label@GAME_ENDED_LABEL: + X: 0 + Y: 0 - 25 + Width: PARENT_RIGHT + Font: BigBold + Align: Center + Text: The game has ended + Contrast: True + Label@BLURB: + X: 15 + Y: (PARENT_BOTTOM - HEIGHT) / 2 + Width: PARENT_RIGHT - 30 + Text: Press 'Leave' to return to the main menu. + Align: Center + Button@LEAVE_BUTTON: + X: 0 + Y: PARENT_BOTTOM - 1 + Width: 140 + Height: 35 + Font: Bold + Text: Leave + Button@RESTART_BUTTON: + X: 150 + Y: PARENT_BOTTOM - 1 + Width: 140 + Height: 35 + Font: Bold + Text: Restart + Visible: false + Container@LEAVE_RESTART_FULL: + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 512 + Height: 410 + Visible: False + Children: + Background@LEAVE_RESTART_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 35 + Background: panel-black + Children: + Label@GAME_ENDED_LABEL: + X: 0 + Y: 0 - 25 + Width: PARENT_RIGHT + Font: BigBold + Align: Center + Text: The game has ended + Contrast: True + Button@LEAVE_BUTTON: + X: 0 + Y: PARENT_BOTTOM - 1 + Width: 140 + Height: 35 + Font: Bold + Text: Leave + Button@RESTART_BUTTON: + X: 150 + Y: PARENT_BOTTOM - 1 + Width: 140 + Height: 35 + Font: Bold + Text: Restart + Visible: false + Container@OBJECTIVES: + diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index dafb8b1977..38afa45035 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -94,6 +94,7 @@ ChromeLayout: mods/cnc/chrome/ingame-infobriefing.yaml mods/cnc/chrome/ingame-infoobjectives.yaml mods/cnc/chrome/ingame-infostats.yaml + mods/cnc/chrome/ingame-leavemap.yaml mods/cnc/chrome/music.yaml mods/cnc/chrome/settings.yaml mods/cnc/chrome/credits.yaml diff --git a/mods/d2k/chrome/ingame-leavemap.yaml b/mods/d2k/chrome/ingame-leavemap.yaml new file mode 100644 index 0000000000..cd78d046f0 --- /dev/null +++ b/mods/d2k/chrome/ingame-leavemap.yaml @@ -0,0 +1,92 @@ +Container@LEAVE_RESTART_WIDGET: + Logic: LeaveMapLogic + Children: + Background@BORDER: + X: 0 - 15 + Y: 0 - 15 + Width: WINDOW_RIGHT + 30 + Height: WINDOW_BOTTOM + 30 + Background: mainmenu-border + Label@VERSION_LABEL: + X: WINDOW_RIGHT - 10 + Y: WINDOW_BOTTOM - 20 + Align: Right + Font: Regular + Contrast: True + Container@LEAVE_RESTART_SIMPLE + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 370 + Height: 175 + Visible: False + Children: + Background@LEAVE_RESTART_SIMPLE_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Children: + Label@GAME_ENDED_LABEL: + Y: 20 + Width: PARENT_RIGHT + Height: 25 + Font: Bold + Align: Center + Text: The game has ended + Label@BLURB: + X: 15 + Y: 50 + Width: PARENT_RIGHT - 30 + Height: 65 + Text: Press 'Leave' to return to the main menu. + Align: Center + Button@RESTART_BUTTON: + X: 20 + Y: PARENT_BOTTOM - 45 + Width: 140 + Height: 25 + Font: Bold + Text: Restart + Visible: false + Button@LEAVE_BUTTON: + X: (PARENT_RIGHT - WIDTH) / 2 + Y: PARENT_BOTTOM - 45 + Width: 140 + Height: 25 + Font: Bold + Text: Leave + Container@LEAVE_RESTART_FULL: + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 522 + Height: 470 + Visible: False + Children: + Background@LEAVE_RESTART_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Children: + Label@GAME_ENDED_LABEL: + X: 20 + Y: 20 + Width: PARENT_RIGHT - 40 + Height: 25 + Font: Bold + Align: Center + Text: The game has ended + Button@RESTART_BUTTON: + X: PARENT_RIGHT - 2 * (WIDTH + 20) + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Font: Bold + Text: Restart + Visible: false + Button@LEAVE_BUTTON: + X: PARENT_RIGHT - WIDTH - 20 + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Font: Bold + Text: Leave + Container@OBJECTIVES: + Y: 40 + diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index cc9d32dd33..e4703fe110 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -70,6 +70,7 @@ ChromeLayout: mods/ra/chrome/ingame-observerstats.yaml mods/d2k/chrome/ingame-player.yaml mods/ra/chrome/ingame-debug.yaml + mods/d2k/chrome/ingame-leavemap.yaml mods/d2k/chrome/mainmenu.yaml mods/ra/chrome/settings.yaml mods/ra/chrome/credits.yaml diff --git a/mods/ra/chrome/ingame-leavemap.yaml b/mods/ra/chrome/ingame-leavemap.yaml new file mode 100644 index 0000000000..1bebfd9716 --- /dev/null +++ b/mods/ra/chrome/ingame-leavemap.yaml @@ -0,0 +1,99 @@ +Container@LEAVE_RESTART_WIDGET: + Logic: LeaveMapLogic + Children: + Background@BORDER: + X: 0 - 15 + Y: 0 - 15 + Width: WINDOW_RIGHT + 30 + Height: WINDOW_BOTTOM + 30 + Background: mainmenu-border + Image@LOGO: + X: WINDOW_RIGHT - 296 + Y: 30 + ImageCollection: logos + ImageName: logo + Label@VERSION_LABEL: + X: WINDOW_RIGHT - 296 + Y: 296 - 20 + Width: 296 - 20 + Height: 25 + Align: Center + Font: Regular + Contrast: True + Container@LEAVE_RESTART_SIMPLE + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 370 + Height: 175 + Visible: False + Children: + Background@LEAVE_RESTART_SIMPLE_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Children: + Label@GAME_ENDED_LABEL: + Y: 20 + Width: PARENT_RIGHT + Height: 25 + Font: Bold + Align: Center + Text: The game has ended + Label@BLURB: + X: 15 + Y: 50 + Width: PARENT_RIGHT - 30 + Height: 65 + Text: Press 'Leave' to return to the main menu. + Align: Center + Button@RESTART_BUTTON: + X: 20 + Y: PARENT_BOTTOM - 45 + Width: 140 + Height: 25 + Font: Bold + Text: Restart + Visible: false + Button@LEAVE_BUTTON: + X: (PARENT_RIGHT - WIDTH) / 2 + Y: PARENT_BOTTOM - 45 + Width: 140 + Height: 25 + Font: Bold + Text: Leave + Container@LEAVE_RESTART_FULL: + X: (WINDOW_RIGHT - WIDTH) / 2 + Y: (WINDOW_BOTTOM - HEIGHT) / 2 + Width: 522 + Height: 470 + Visible: False + Children: + Background@LEAVE_RESTART_BG: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Children: + Label@GAME_ENDED_LABEL: + X: 20 + Y: 20 + Width: PARENT_RIGHT - 40 + Height: 25 + Font: Bold + Align: Center + Text: The game has ended + Button@RESTART_BUTTON: + X: PARENT_RIGHT - 2 * (WIDTH + 20) + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Font: Bold + Text: Restart + Visible: false + Button@LEAVE_BUTTON: + X: PARENT_RIGHT - WIDTH - 20 + Y: PARENT_BOTTOM - 45 + Width: 120 + Height: 25 + Font: Bold + Text: Leave + Container@OBJECTIVES: + Y: 40 + diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index cbcbc3e30f..1bb66eab72 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -78,6 +78,7 @@ ChromeLayout: mods/ra/chrome/ingame-infobriefing.yaml mods/ra/chrome/ingame-infoobjectives.yaml mods/ra/chrome/ingame-infostats.yaml + mods/ra/chrome/ingame-leavemap.yaml mods/ra/chrome/ingame-menu.yaml mods/ra/chrome/ingame-observer.yaml mods/ra/chrome/ingame-observerstats.yaml diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 0c1e5c35eb..e889a0e0ae 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -112,6 +112,7 @@ ChromeLayout: mods/ra/chrome/ingame-observerstats.yaml mods/ts/chrome/ingame-player.yaml mods/ra/chrome/ingame-debug.yaml + mods/ra/chrome/ingame-leavemap.yaml mods/ra/chrome/mainmenu.yaml mods/ra/chrome/settings.yaml mods/ra/chrome/credits.yaml