From e2e0728e20d8cfa5921d9d50dd71a42efa566a54 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 13 Mar 2014 17:52:09 +1300 Subject: [PATCH] Add a force start warning dialog. --- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 40 +++++++++---- mods/cnc/chrome/lobby-dialogs.yaml | 67 +++++++++++++++++++++- mods/ra/chrome/lobby-dialogs.yaml | 65 +++++++++++++++++++++ 3 files changed, 159 insertions(+), 13 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index b4287d68c7..ad183ba8b7 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic readonly OrderManager orderManager; readonly bool skirmishMode; - enum PanelType { Players, Options, Kick } + enum PanelType { Players, Options, Kick, ForceStart } PanelType panel = PanelType.Players; Widget lobby; @@ -138,7 +138,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic countryNames.Add("random", "Any"); var gameStarting = false; - Func configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick || + Func configurationDisabled = () => !Game.IsHost || gameStarting || + panel == PanelType.Kick || panel == PanelType.ForceStart || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; var mapButton = lobby.GetOrNull("CHANGEMAP_BUTTON"); @@ -261,10 +262,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic optionsBin.IsVisible = () => panel == PanelType.Options; var optionsButton = lobby.Get("OPTIONS_BUTTON"); - optionsButton.IsDisabled = () => panel == PanelType.Kick; + optionsButton.IsDisabled = () => panel == PanelType.Kick || panel == PanelType.ForceStart; optionsButton.GetText = () => panel == PanelType.Options ? "Players" : "Options"; optionsButton.OnClick = () => panel = (panel == PanelType.Options) ? PanelType.Players : PanelType.Options; + // Force start panel + Action startGame = () => + { + gameStarting = true; + orderManager.IssueOrder(Order.Command("startgame")); + }; + var startGameButton = lobby.GetOrNull("START_GAME_BUTTON"); if (startGameButton != null) { @@ -272,18 +280,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null); startGameButton.OnClick = () => { - gameStarting = true; - orderManager.IssueOrder(Order.Command("startgame")); + Func, bool> notReady = sl => + { + var cl = orderManager.LobbyInfo.ClientInSlot(sl.Key); + + // Bots and admins don't count + return cl != null && !cl.IsAdmin && cl.Bot == null && !cl.IsReady; + }; + + if (orderManager.LobbyInfo.Slots.Any(notReady)) + panel = PanelType.ForceStart; + else + startGame(); }; } - var statusCheckbox = lobby.GetOrNull("STATUS_CHECKBOX"); - if (statusCheckbox != null) - { - statusCheckbox.IsHighlighted = () => !statusCheckbox.IsChecked() && - orderManager.LobbyInfo.FirstEmptySlot() == null && - orderManager.LocalFrameNumber / 25 % 2 == 0; - } + var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby, new WidgetArgs()); + forceStartBin.IsVisible = () => panel == PanelType.ForceStart; + forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); + forceStartBin.Get("OK_BUTTON").OnClick = startGame; + forceStartBin.Get("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; // Options panel var allowCheats = optionsBin.GetOrNull("ALLOWCHEATS_CHECKBOX"); diff --git a/mods/cnc/chrome/lobby-dialogs.yaml b/mods/cnc/chrome/lobby-dialogs.yaml index e1d0effc43..28d849e52e 100644 --- a/mods/cnc/chrome/lobby-dialogs.yaml +++ b/mods/cnc/chrome/lobby-dialogs.yaml @@ -180,4 +180,69 @@ Background@LOBBY_OPTIONS_BIN: Y:107 Width:140 Height:25 - Font:Regular \ No newline at end of file + Font:Regular + +Background@FORCE_START_DIALOG: + X:15 + Y:30 + Width:501 + Height:219 + Background:scrollpanel-bg + Children: + Label@TITLE: + X:0 + Y:40 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text: Start Game? + Label@TEXTA: + X:0 + Y:67 + Width:PARENT_RIGHT + Height:25 + Font:Regular + Align:Center + Text:One or more players are not yet ready. + Label@TEXTB: + X:0 + Y:85 + Width:PARENT_RIGHT + Height:25 + Font:Regular + Align:Center + Text:Are you sure that you want to force start the game? + Container@KICK_WARNING: + Width:PARENT_RIGHT + Children: + Label@KICK_WARNING_A: + X:0 + Y:106 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text:One or more clients are missing the selected + Label@KICK_WARNING_B: + X:0 + Y:123 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text:map, and will be kicked from the server. + Button@OK_BUTTON: + X:(PARENT_RIGHT - WIDTH)/2 + 75 + Y:155 + Width:120 + Height:25 + Text:Start + Font:Bold + Button@CANCEL_BUTTON: + X:(PARENT_RIGHT - WIDTH)/2 - 75 + Y:155 + Width:120 + Height:25 + Text:Cancel + Font:Bold \ No newline at end of file diff --git a/mods/ra/chrome/lobby-dialogs.yaml b/mods/ra/chrome/lobby-dialogs.yaml index cb266f2f7d..51d0a2c643 100644 --- a/mods/ra/chrome/lobby-dialogs.yaml +++ b/mods/ra/chrome/lobby-dialogs.yaml @@ -179,3 +179,68 @@ Background@LOBBY_OPTIONS_BIN: Width:140 Height:25 Font:Regular + +Background@FORCE_START_DIALOG: + X:20 + Y:67 + Width:535 + Height:235 + Background:dialog3 + Children: + Label@TITLE: + X:0 + Y:40 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text: Start Game? + Label@TEXTA: + X:0 + Y:67 + Width:PARENT_RIGHT + Height:25 + Font:Regular + Align:Center + Text:One or more players are not yet ready. + Label@TEXTB: + X:0 + Y:85 + Width:PARENT_RIGHT + Height:25 + Font:Regular + Align:Center + Text:Are you sure that you want to force start the game? + Container@KICK_WARNING: + Width:PARENT_RIGHT + Children: + Label@KICK_WARNING_A: + X:0 + Y:106 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text:One or more clients are missing the selected + Label@KICK_WARNING_B: + X:0 + Y:123 + Width:PARENT_RIGHT + Height:25 + Font:Bold + Align:Center + Text:map, and will be kicked from the server. + Button@OK_BUTTON: + X:(PARENT_RIGHT - WIDTH)/2 + 75 + Y:155 + Width:120 + Height:25 + Text:Start + Font:Bold + Button@CANCEL_BUTTON: + X:(PARENT_RIGHT - WIDTH)/2 - 75 + Y:155 + Width:120 + Height:25 + Text:Cancel + Font:Bold \ No newline at end of file