diff --git a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs index 2f1f711511..a45f4d8225 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs @@ -42,6 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "connection", connection }, { "password", password }, { "onAbort", onAbort }, + { "onQuit", null }, { "onRetry", onRetry } }); } @@ -102,16 +103,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool passwordOffsetAdjusted; [ObjectCreator.UseCtor] - public ConnectionFailedLogic(Widget widget, ModData modData, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action onRetry) + public ConnectionFailedLogic(Widget widget, ModData modData, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action onQuit, Action onRetry) { var panel = widget; var abortButton = panel.Get("ABORT_BUTTON"); + var quitButton = panel.Get("QUIT_BUTTON"); var retryButton = panel.Get("RETRY_BUTTON"); + var leaving = false; abortButton.Visible = onAbort != null; + abortButton.IsDisabled = () => leaving; abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); }; + quitButton.Visible = onQuit != null; + quitButton.IsDisabled = () => leaving; + quitButton.OnClick = () => { onQuit(); leaving = true; }; + retryButton.Visible = onRetry != null; + retryButton.IsDisabled = () => leaving; retryButton.OnClick = () => { var pass = passwordField != null && passwordField.IsVisible() ? passwordField.Text : password; diff --git a/OpenRA.Mods.Common/Widgets/Logic/DisconnectWatcherLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/DisconnectWatcherLogic.cs index 129a3ab823..b3318b8db3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/DisconnectWatcherLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/DisconnectWatcherLogic.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public class DisconnectWatcherLogic : ChromeLogic { [ObjectCreator.UseCtor] - public DisconnectWatcherLogic(Widget widget, OrderManager orderManager) + public DisconnectWatcherLogic(Widget widget, World world, OrderManager orderManager) { var disconnected = false; widget.Get("DISCONNECT_WATCHER").OnTick = () => @@ -34,6 +34,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "password", CurrentServerSettings.Password }, { "connection", connection }, { "onAbort", null }, + { "onQuit", () => IngameMenuLogic.OnQuit(world) }, { "onRetry", null } })); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 856abfad0e..7fec0b22dc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - void OnQuit() + public static void OnQuit(World world) { // TODO: Create a mechanism to do things like this cleaner. Also needed for scripted missions if (world.Type == WorldType.Regular) @@ -221,10 +221,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - leaving = true; - var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); var exitDelay = iop?.ExitDelay ?? 0; + var mpe = world.WorldActor.TraitOrDefault(); if (mpe != null) { Game.RunAfterDelay(exitDelay, () => @@ -295,7 +294,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: LeaveMissionTitle, text: LeaveMissionPrompt, - onConfirm: OnQuit, + onConfirm: () => { OnQuit(world); leaving = true; }, onCancel: ShowMenu, confirmText: LeaveMissionAccept, cancelText: LeaveMissionCancel); @@ -499,11 +498,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic title: ExitMapEditorTitle, text: deletedOrUnavailable ? ExitMapEditorPromptDeleted : ExitMapEditorPromptUnsaved, confirmText: deletedOrUnavailable ? ExitMapEditorAnywayConfirm : ExitMapEditorConfirm, - onConfirm: OnQuit, + onConfirm: () => { OnQuit(world); leaving = true; }, onCancel: ShowMenu); } else - OnQuit(); + { + OnQuit(world); + leaving = true; + } }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 1899a28cac..c7b188aa2e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -136,6 +136,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "connection", connection }, { "password", password }, { "onAbort", onExit }, + { "onQuit", null }, { "onRetry", onRetry } }); } diff --git a/mods/cnc/chrome/connection.yaml b/mods/cnc/chrome/connection.yaml index bb1d0b90d2..c90640ab88 100644 --- a/mods/cnc/chrome/connection.yaml +++ b/mods/cnc/chrome/connection.yaml @@ -83,6 +83,12 @@ Container@CONNECTIONFAILED_PANEL: Width: 140 Height: 35 Text: Abort + Button@QUIT_BUTTON: + Key: escape + Y: 84 + Width: 140 + Height: 35 + Text: Quit Button@RETRY_BUTTON: Key: return X: 230 diff --git a/mods/common/chrome/connection.yaml b/mods/common/chrome/connection.yaml index 6b7bf574dd..c67180b299 100644 --- a/mods/common/chrome/connection.yaml +++ b/mods/common/chrome/connection.yaml @@ -57,6 +57,14 @@ Background@CONNECTIONFAILED_PANEL: Text: Abort Font: Bold Key: escape + Button@QUIT_BUTTON: + X: PARENT_RIGHT - 180 + Y: PARENT_BOTTOM - 45 + Width: 160 + Height: 25 + Text: Quit + Font: Bold + Key: escape Background@CONNECTING_PANEL: Logic: ConnectionLogic