(3cb6209cf) Show the "starting a round" popup to all clients when the server initiates a new round. Closes #1396

This commit is contained in:
Joonas Rikkonen
2019-04-08 13:37:27 +03:00
parent 24794932dc
commit 33b8c37933
2 changed files with 32 additions and 16 deletions
@@ -768,13 +768,19 @@ namespace Barotrauma.Networking
readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME);
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
readyToStartMsg.Write(
bool readyToStart =
GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) &&
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox));
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
readyToStartMsg.Write(readyToStart);
WriteCharacterInfo(readyToStartMsg);
client.SendMessage(readyToStartMsg, NetDeliveryMethod.ReliableUnordered);
if (readyToStart && !CoroutineManager.IsCoroutineRunning("WaitForStartRound"))
{
CoroutineManager.StartCoroutine(GameMain.NetLobbyScreen.WaitForStartRound(startButton: null, allowCancel: false), "WaitForStartRound");
}
break;
case ServerPacketHeader.STARTGAME:
startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(inc), false);
@@ -646,7 +646,7 @@ namespace Barotrauma
OnClicked = (btn, obj) =>
{
GameMain.Client.RequestStartRound();
CoroutineManager.StartCoroutine(WaitForStartRound(StartButton), "WaitForStartRound");
CoroutineManager.StartCoroutine(WaitForStartRound(StartButton, allowCancel: true), "WaitForStartRound");
return true;
}
};
@@ -656,31 +656,41 @@ namespace Barotrauma
TextManager.Get("SpectateButton"), style: "GUIButtonLarge");
}
private IEnumerable<object> WaitForStartRound(GUIButton startButton)
public IEnumerable<object> WaitForStartRound(GUIButton startButton, bool allowCancel)
{
string headerText = TextManager.Get("RoundStartingPleaseWait");
var msgBox = new GUIMessageBox(headerText, TextManager.Get("RoundStarting"), new string[] { TextManager.Get("Cancel") });
var msgBox = new GUIMessageBox(headerText, TextManager.Get("RoundStarting"),
allowCancel ? new string[] { TextManager.Get("Cancel") } : new string[0]);
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
if (allowCancel)
{
startButton.Enabled = true;
GameMain.Client.RequestRoundEnd();
CoroutineManager.StopCoroutines("WaitForStartRound");
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
{
startButton.Enabled = true;
GameMain.Client.RequestRoundEnd();
CoroutineManager.StopCoroutines("WaitForStartRound");
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
}
startButton.Enabled = false;
if (startButton != null)
{
startButton.Enabled = false;
}
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
while (Selected != GameMain.GameScreen && DateTime.Now < timeOut)
while (Selected == GameMain.NetLobbyScreen && DateTime.Now < timeOut)
{
msgBox.Header.Text = headerText + new string('.', ((int)Timing.TotalTime % 3 + 1));
yield return CoroutineStatus.Running;
}
msgBox.Close();
startButton.Enabled = true;
if (startButton != null)
{
startButton.Enabled = true;
}
yield return CoroutineStatus.Success;
}
@@ -1845,7 +1855,7 @@ namespace Barotrauma
StartRound = () =>
{
GameMain.Client.RequestStartRound();
CoroutineManager.StartCoroutine(WaitForStartRound(campaignUI.StartButton), "WaitForStartRound");
CoroutineManager.StartCoroutine(WaitForStartRound(campaignUI.StartButton, allowCancel: true), "WaitForStartRound");
}
};
campaignUI.MapContainer.RectTransform.NonScaledSize = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);