Add a force start warning dialog.

This commit is contained in:
Paul Chote
2014-03-13 17:52:09 +13:00
parent fcb3d7347a
commit e2e0728e20
3 changed files with 159 additions and 13 deletions

View File

@@ -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<bool> configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick ||
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||
panel == PanelType.Kick || panel == PanelType.ForceStart ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON");
@@ -261,10 +262,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
optionsBin.IsVisible = () => panel == PanelType.Options;
var optionsButton = lobby.Get<ButtonWidget>("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<ButtonWidget>("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<KeyValuePair<string, Session.Slot>, 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<CheckboxWidget>("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<ButtonWidget>("OK_BUTTON").OnClick = startGame;
forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players;
// Options panel
var allowCheats = optionsBin.GetOrNull<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");

View File

@@ -180,4 +180,69 @@ Background@LOBBY_OPTIONS_BIN:
Y:107
Width:140
Height:25
Font:Regular
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

View File

@@ -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