From 83c02504ea492d896c1305a6ac1e8fda3d85c23f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 22 Feb 2018 14:18:06 +0200 Subject: [PATCH] Fixed clients failing to select a received submarine/shuttle file, preventing them from starting a round until they rejoin the server. Closes #271 --- .../Source/GUI/GUIDropDown.cs | 4 +- .../Networking/FileTransfer/FileReceiver.cs | 4 +- .../Source/Networking/GameClient.cs | 39 ++++++++++++++++--- .../Source/Screens/NetLobbyScreen.cs | 15 ++++++- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs index 3441113be..5267365b2 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIDropDown.cs @@ -170,14 +170,14 @@ namespace Barotrauma private bool OnClicked(GUIComponent component, object obj) { - if (wasOpened || !Enabled) return false; + if (wasOpened) return false; wasOpened = true; Dropped = !Dropped; if (Dropped) { - OnDropped?.Invoke(this, userData); + if (Enabled) OnDropped?.Invoke(this, userData); if (parent.children[parent.children.Count - 1] != this) { parent.children.Remove(this); diff --git a/Barotrauma/BarotraumaClient/Source/Networking/FileTransfer/FileReceiver.cs b/Barotrauma/BarotraumaClient/Source/Networking/FileTransfer/FileReceiver.cs index 1d0b71451..937e378cf 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/FileTransfer/FileReceiver.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/FileTransfer/FileReceiver.cs @@ -288,8 +288,8 @@ namespace Barotrauma.Networking string errorMessage = ""; if (ValidateReceivedData(activeTransfer, out errorMessage)) { - OnFinished(activeTransfer); StopTransfer(activeTransfer); + OnFinished(activeTransfer); } else { @@ -433,7 +433,7 @@ namespace Barotrauma.Networking } catch (Exception e) { - DebugConsole.ThrowError("Failed to delete file \""+transfer.FilePath+"\" ("+e.Message+")"); + DebugConsole.ThrowError("Failed to delete file \"" + transfer.FilePath + "\" (" + e.Message + ")"); } } } diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index e32b12051..3b9816f0a 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -1187,16 +1187,43 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen.ShuttleList.ListBox.children : GameMain.NetLobbyScreen.SubList.children; - var textBlock = subListChildren.Find(c => + var subElement = subListChildren.Find(c => ((Submarine)c.UserData).Name == newSub.Name && - ((Submarine)c.UserData).MD5Hash.Hash == newSub.MD5Hash.Hash) as GUITextBlock; + ((Submarine)c.UserData).MD5Hash.Hash == newSub.MD5Hash.Hash); - if (textBlock == null) continue; - textBlock.TextColor = new Color(textBlock.TextColor, 1.0f); + if (subElement == null) continue; + subElement.GetChild().TextColor = new Color(subElement.GetChild().TextColor, 1.0f); + subElement.UserData = newSub; + subElement.ToolTip = newSub.Description; - textBlock.UserData = newSub; - textBlock.ToolTip = newSub.Description; + GUIButton infoButton = subElement.GetChild(); + if (infoButton == null) + { + infoButton = new GUIButton(new Rectangle(0, 0, 20, 20), "?", Alignment.CenterLeft, "", subElement); + } + infoButton.UserData = newSub; + infoButton.OnClicked = (component, userdata) => + { + var msgBox = new GUIMessageBox("", "", 550, 400); + ((Submarine)userdata).CreatePreviewWindow(msgBox.InnerFrame); + return true; + }; } + + if (GameMain.NetLobbyScreen.FailedSelectedSub != null && + GameMain.NetLobbyScreen.FailedSelectedSub.First == newSub.Name && + GameMain.NetLobbyScreen.FailedSelectedSub.Second == newSub.MD5Hash.Hash) + { + GameMain.NetLobbyScreen.TrySelectSub(newSub.Name, newSub.MD5Hash.Hash, GameMain.NetLobbyScreen.SubList); + } + + if (GameMain.NetLobbyScreen.FailedSelectedShuttle != null && + GameMain.NetLobbyScreen.FailedSelectedShuttle.First == newSub.Name && + GameMain.NetLobbyScreen.FailedSelectedShuttle.Second == newSub.MD5Hash.Hash) + { + GameMain.NetLobbyScreen.TrySelectSub(newSub.Name, newSub.MD5Hash.Hash, GameMain.NetLobbyScreen.ShuttleList.ListBox); + } + break; case FileTransferType.CampaignSave: var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index 6eeeb15b5..6e85c9be8 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -265,7 +265,7 @@ namespace Barotrauma //respawn shuttle ------------------------------------------------------------------ shuttleTickBox = new GUITickBox(new Rectangle(columnX, 110, 20, 20), TextManager.Get("RespawnShuttle"), Alignment.Left, defaultModeContainer); - shuttleList = new GUIDropDown(new Rectangle(columnX, 140, 200, 20), "", "", defaultModeContainer); + shuttleList = new GUIDropDown(new Rectangle(columnX, 140, columnWidth, 20), "", "", defaultModeContainer); shuttleTickBox.Selected = true; shuttleTickBox.OnSelected = (GUITickBox box) => { @@ -1421,6 +1421,9 @@ namespace Barotrauma GameMain.Config.JobNamePreferences = jobNamePreferences; } + public Pair FailedSelectedSub; + public Pair FailedSelectedShuttle; + public bool TrySelectSub(string subName, string md5Hash, GUIListBox subList) { if (GameMain.Client == null) return false; @@ -1440,10 +1443,20 @@ namespace Barotrauma subList.OnSelected -= VotableClicked; subList.Select(subList.children.IndexOf(matchingListSub), true); subList.OnSelected += VotableClicked; + + if (subList == SubList) + FailedSelectedSub = null; + else + FailedSelectedShuttle = null; } if (sub == null || sub.MD5Hash.Hash != md5Hash) { + if (subList == SubList) + FailedSelectedSub = Pair.Create(subName, md5Hash); + else + FailedSelectedShuttle = Pair.Create(subName, md5Hash); + string errorMsg = ""; if (sub == null) {