- clients see the submarines that the host has instead of their own subs in server lobby
- possible to vote for subs the client doesn't have - fixed the "votes required" slider moving when re-opening the server settings - WIP method for sending missing subs to clients before the round starts (atm the clients won't have time to request a sub file that was chosen by voting)
This commit is contained in:
@@ -15,6 +15,8 @@ namespace Barotrauma
|
||||
private float barSize;
|
||||
private float barScroll;
|
||||
|
||||
private float step;
|
||||
|
||||
private bool enabled;
|
||||
|
||||
public delegate bool OnMovedHandler(GUIScrollBar scrollBar, float barScroll);
|
||||
@@ -33,29 +35,42 @@ namespace Barotrauma
|
||||
|
||||
public float BarScroll
|
||||
{
|
||||
get { return barScroll; }
|
||||
get { return step == 0.0f ? barScroll : MathUtils.RoundTowardsClosest(barScroll, step); }
|
||||
set
|
||||
{
|
||||
barScroll = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
int newX = bar.Rect.X - frame.Rect.X, newY = bar.Rect.Y - frame.Rect.Y;
|
||||
|
||||
float newScroll = step == 0.0f ? barScroll : MathUtils.RoundTowardsClosest(barScroll, step);
|
||||
|
||||
if (isHorizontal)
|
||||
{
|
||||
newX = (int)(barScroll *(frame.Rect.Width - bar.Rect.Width));
|
||||
newX = Math.Max(newX, 0);
|
||||
newX = Math.Min(newX, frame.Rect.Width - bar.Rect.Width);
|
||||
newX = (int)(newScroll * (frame.Rect.Width - bar.Rect.Width));
|
||||
newX = MathHelper.Clamp(newX, 0, frame.Rect.Width - bar.Rect.Width);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
newY = (int)(barScroll * (frame.Rect.Height- bar.Rect.Height));
|
||||
newY = Math.Max(newY, 0);
|
||||
newY = Math.Min(newY, frame.Rect.Height - bar.Rect.Height);
|
||||
newY = (int)(newScroll * (frame.Rect.Height - bar.Rect.Height));
|
||||
newY = MathHelper.Clamp(newY, 0, frame.Rect.Height - bar.Rect.Height);
|
||||
|
||||
}
|
||||
bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public float Step
|
||||
{
|
||||
get
|
||||
{
|
||||
return step;
|
||||
}
|
||||
set
|
||||
{
|
||||
step = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public float BarSize
|
||||
{
|
||||
get { return barSize; }
|
||||
@@ -158,25 +173,35 @@ namespace Barotrauma
|
||||
//if (barSize == 1.0f) return false;
|
||||
|
||||
int newX = bar.Rect.X - frame.Rect.X, newY = bar.Rect.Y - frame.Rect.Y;
|
||||
int moveAmount;
|
||||
float moveAmount;
|
||||
if (isHorizontal)
|
||||
{
|
||||
moveAmount = (int)PlayerInput.MouseSpeed.X;
|
||||
newX = Math.Min(Math.Max(newX + moveAmount, 0), frame.Rect.Width - bar.Rect.Width);
|
||||
moveAmount = PlayerInput.MouseSpeed.X;
|
||||
barScroll += moveAmount / (frame.Rect.Width - bar.Rect.Width);
|
||||
//newX = Math.Min(Math.Max(newX + moveAmount, 0), frame.Rect.Width - bar.Rect.Width);
|
||||
|
||||
barScroll = (float)newX / ((float)frame.Rect.Width - (float)bar.Rect.Width);
|
||||
//barScroll = (float)newX / ((float)frame.Rect.Width - (float)bar.Rect.Width);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveAmount = (int)PlayerInput.MouseSpeed.Y;
|
||||
newY = Math.Min(Math.Max(newY+moveAmount, 0), frame.Rect.Height - bar.Rect.Height);
|
||||
moveAmount = PlayerInput.MouseSpeed.Y;
|
||||
barScroll += moveAmount / (frame.Rect.Height - bar.Rect.Height);
|
||||
//newY = Math.Min(Math.Max(newY+moveAmount, 0), frame.Rect.Height - bar.Rect.Height);
|
||||
|
||||
barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height);
|
||||
//barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height);
|
||||
}
|
||||
|
||||
if (moveAmount != 0 && OnMoved != null) OnMoved(this, barScroll);
|
||||
if (moveAmount != 0)
|
||||
{
|
||||
int asdf = 1;
|
||||
}
|
||||
|
||||
bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);
|
||||
BarScroll = barScroll;
|
||||
|
||||
if (moveAmount != 0 && OnMoved != null) OnMoved(this, BarScroll);
|
||||
|
||||
|
||||
//bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace Barotrauma
|
||||
public IEnumerable<object> DoLoading(IEnumerable<object> loader)
|
||||
{
|
||||
drawn = false;
|
||||
LoadState = null;
|
||||
LoadState = null;
|
||||
|
||||
while (!drawn)
|
||||
{
|
||||
|
||||
@@ -355,6 +355,7 @@ namespace Barotrauma
|
||||
{
|
||||
waitForKeyHit = waitKeyHit;
|
||||
titleScreenOpen = true;
|
||||
TitleScreen.LoadState = null;
|
||||
CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader));
|
||||
}
|
||||
|
||||
|
||||
@@ -164,10 +164,13 @@ namespace Barotrauma
|
||||
GameMain.LobbyScreen.Select();
|
||||
}
|
||||
|
||||
GUIFrame summaryFrame = shiftSummary.CreateSummaryFrame(endMessage);
|
||||
GUIMessageBox.MessageBoxes.Enqueue(summaryFrame);
|
||||
var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, GUI.Style, summaryFrame.children[0]);
|
||||
okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
|
||||
if (shiftSummary!=null)
|
||||
{
|
||||
GUIFrame summaryFrame = shiftSummary.CreateSummaryFrame(endMessage);
|
||||
GUIMessageBox.MessageBoxes.Enqueue(summaryFrame);
|
||||
var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, GUI.Style, summaryFrame.children[0]);
|
||||
okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
|
||||
}
|
||||
|
||||
TaskManager.EndShift();
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace Barotrauma
|
||||
|
||||
//constructors & generation ----------------------------------------------------
|
||||
|
||||
public Submarine(string filePath, string hash = "") : base(null)
|
||||
public Submarine(string filePath, string hash = "", bool tryLoad = true) : base(null)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
try
|
||||
@@ -196,7 +196,7 @@ namespace Barotrauma
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error loading map " + filePath + "!", e);
|
||||
DebugConsole.ThrowError("Error loading submarine " + filePath + "!", e);
|
||||
}
|
||||
|
||||
if (hash != "")
|
||||
@@ -204,17 +204,22 @@ namespace Barotrauma
|
||||
this.hash = new Md5Hash(hash);
|
||||
}
|
||||
|
||||
XDocument doc = OpenDoc(filePath);
|
||||
|
||||
if (doc != null && doc.Root != null)
|
||||
if (tryLoad)
|
||||
{
|
||||
Description = ToolBox.GetAttributeString(doc.Root, "description", "");
|
||||
XDocument doc = OpenDoc(filePath);
|
||||
|
||||
if (doc != null && doc.Root != null)
|
||||
{
|
||||
Description = ToolBox.GetAttributeString(doc.Root, "description", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ID = ushort.MaxValue;
|
||||
base.Remove();
|
||||
}
|
||||
|
||||
|
||||
//drawing ----------------------------------------------------
|
||||
|
||||
public static void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||
@@ -607,7 +612,7 @@ namespace Barotrauma
|
||||
SavedSubmarines.Add(new Submarine(path));
|
||||
}
|
||||
|
||||
if (GameMain.NetLobbyScreen!=null) GameMain.NetLobbyScreen.UpdateSubList();
|
||||
//if (GameMain.NetLobbyScreen!=null) GameMain.NetLobbyScreen.UpdateSubList(Submarine.SavedSubmarines);
|
||||
}
|
||||
|
||||
private XDocument OpenDoc(string file)
|
||||
|
||||
@@ -29,6 +29,12 @@ namespace Barotrauma.Networking
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string FilePath
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ulong FileSize
|
||||
{
|
||||
@@ -190,7 +196,9 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
writeStream = new FileStream(Path.Combine(downloadFolder, FileName), FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
FilePath = Path.Combine(downloadFolder, FileName);
|
||||
|
||||
writeStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
timeStarted = Environment.TickCount;
|
||||
|
||||
Status = FileTransferStatus.NotStarted;
|
||||
|
||||
@@ -257,8 +257,8 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.ClearPlayers();
|
||||
|
||||
//add the names of other connected clients to the lobby screen
|
||||
int existingClients = inc.ReadInt32();
|
||||
for (int i = 1; i <= existingClients; i++)
|
||||
int clientCount = inc.ReadByte();
|
||||
for (int i = 0; i < clientCount; i++)
|
||||
{
|
||||
Client otherClient = new Client(inc.ReadString(), inc.ReadByte());
|
||||
|
||||
@@ -266,6 +266,17 @@ namespace Barotrauma.Networking
|
||||
otherClients.Add(otherClient);
|
||||
}
|
||||
|
||||
List<Submarine> submarines = new List<Submarine>();
|
||||
int subCount = inc.ReadByte();
|
||||
for (int i = 0; i < subCount; i++ )
|
||||
{
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
|
||||
submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false));
|
||||
}
|
||||
GameMain.NetLobbyScreen.UpdateSubList(submarines);
|
||||
|
||||
//add the name of own client to the lobby screen
|
||||
GameMain.NetLobbyScreen.AddPlayer(name);
|
||||
|
||||
@@ -342,7 +353,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (Screen.Selected != GameMain.GameScreen)
|
||||
{
|
||||
List<Submarine> subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
|
||||
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||
GameMain.NetLobbyScreen.UpdateSubList(subList);
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
}
|
||||
connected = true;
|
||||
@@ -819,7 +833,16 @@ namespace Barotrauma.Networking
|
||||
switch (receiver.FileType)
|
||||
{
|
||||
case FileTransferMessageType.Submarine:
|
||||
Submarine.Preload();
|
||||
var textBlock = GameMain.NetLobbyScreen.SubList.children.Find(c => (c.UserData as Submarine).Name+".sub" == receiver.FileName);
|
||||
if (textBlock != null)
|
||||
{
|
||||
Submarine.SavedSubmarines.RemoveAll(s => s.Name + ".sub" == receiver.FileName);
|
||||
|
||||
(textBlock as GUITextBlock).TextColor = Color.White;
|
||||
var newSub = new Submarine(receiver.FilePath);
|
||||
Submarine.SavedSubmarines.Add(newSub);
|
||||
textBlock.UserData = newSub;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Barotrauma.Networking
|
||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && ConnectedClients.Count>0)
|
||||
{
|
||||
AutoRestartTimer -= deltaTime;
|
||||
if (AutoRestartTimer < 0.0f)
|
||||
if (AutoRestartTimer < 0.0f && GameMain.NetLobbyScreen.StartButton.Enabled)
|
||||
{
|
||||
StartGameClicked(null,null);
|
||||
}
|
||||
@@ -437,11 +437,11 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write((byte)PacketTypes.LoggedIn);
|
||||
outmsg.Write(sender.ID);
|
||||
outmsg.Write(gameStarted);
|
||||
outmsg.Write(gameStarted && sender.Character!=null);
|
||||
outmsg.Write(gameStarted && sender.Character != null);
|
||||
outmsg.Write(allowSpectating);
|
||||
|
||||
//notify the client about other clients already logged in
|
||||
outmsg.Write((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count);
|
||||
outmsg.Write((byte)((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count));
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (c.Connection == inc.SenderConnection) continue;
|
||||
@@ -455,6 +455,14 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(-1);
|
||||
}
|
||||
|
||||
var subs = GameMain.NetLobbyScreen.GetSubList();
|
||||
outmsg.Write((byte)subs.Count);
|
||||
foreach (Submarine sub in subs)
|
||||
{
|
||||
outmsg.Write(sub.Name);
|
||||
outmsg.Write(sub.MD5Hash.Hash);
|
||||
}
|
||||
|
||||
server.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
|
||||
//notify other clients about the new client
|
||||
@@ -854,21 +862,37 @@ namespace Barotrauma.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath))
|
||||
{
|
||||
new GUIMessageBox("Couldn't start a round",
|
||||
"Can't start a round while sending the selected submarine to clients. Cancel the transfers or wait for them to finish before starting.", 400, 400);
|
||||
return false;
|
||||
}
|
||||
|
||||
GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false);
|
||||
CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedMode), "WaitForPlayersReady");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<object> WaitForPlayersReady(Submarine selectedSub, GameModePreset selectedMode)
|
||||
{
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = false;
|
||||
|
||||
if (Voting.AllowSubVoting) yield return new WaitForSeconds(1.0f);
|
||||
|
||||
while (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath))
|
||||
{
|
||||
if (GUIMessageBox.MessageBoxes.Peek() == null)
|
||||
{
|
||||
new GUIMessageBox("File transfer in progress",
|
||||
"The round will be started after the submarine file has been sent to all players.", 400, 400);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
|
||||
GameMain.ShowLoading(StartGame(selectedSub, selectedMode), false);
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private IEnumerable<object> StartGame(Submarine selectedSub, GameModePreset selectedMode)
|
||||
{
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = false;
|
||||
|
||||
GUIMessageBox.CloseAll();
|
||||
|
||||
AssignJobs();
|
||||
@@ -965,6 +989,7 @@ namespace Barotrauma.Networking
|
||||
AddChatMessage("Press TAB to chat. Use ''r;'' to talk through the radio.", ChatMessageType.Server);
|
||||
}
|
||||
|
||||
GameMain.NetLobbyScreen.StartButton.Enabled = true;
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -146,9 +146,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
subSelectionMode = SelectionMode.Manual;
|
||||
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "SubSelection", "Manual"), out subSelectionMode);
|
||||
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
||||
|
||||
modeSelectionMode = SelectionMode.Manual;
|
||||
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "ModeSelection", "Manual"), out modeSelectionMode);
|
||||
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
|
||||
|
||||
FileStreamSender.MaxTransferDuration = new TimeSpan(0,0,ToolBox.GetAttributeInt(doc.Root, "MaxFileTransferDuration", 150));
|
||||
}
|
||||
@@ -184,12 +186,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
var votesRequiredSlider = new GUIScrollBar(new Rectangle(150, y+22, 100, 10), GUI.Style, 0.1f, innerFrame);
|
||||
votesRequiredSlider.UserData = votesRequiredText;
|
||||
votesRequiredSlider.Step = 0.2f;
|
||||
votesRequiredSlider.BarScroll = (EndVoteRequiredRatio - 0.5f) * 2.0f;
|
||||
votesRequiredSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
|
||||
{
|
||||
GUITextBlock voteText = scrollBar.UserData as GUITextBlock;
|
||||
|
||||
scrollBar.BarScroll = MathUtils.Round(barScroll, 0.2f);
|
||||
EndVoteRequiredRatio = barScroll / 2.0f + 0.5f;
|
||||
voteText.Text = "Votes required: " + (int)MathUtils.Round(EndVoteRequiredRatio * 100.0f, 10.0f) + " %";
|
||||
return true;
|
||||
@@ -197,9 +199,7 @@ namespace Barotrauma.Networking
|
||||
votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll);
|
||||
|
||||
y += 40;
|
||||
|
||||
|
||||
|
||||
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Randomize level seed between rounds", Alignment.Left, innerFrame);
|
||||
randomizeLevelBox.Selected = randomizeSeed;
|
||||
randomizeLevelBox.OnSelected = (GUITickBox) =>
|
||||
@@ -207,8 +207,7 @@ namespace Barotrauma.Networking
|
||||
randomizeSeed = GUITickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
y += 40;
|
||||
|
||||
var shareSubsBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Share submarine files with players", Alignment.Left, innerFrame);
|
||||
|
||||
@@ -63,6 +63,12 @@ namespace Barotrauma
|
||||
get { return playerList; }
|
||||
}
|
||||
|
||||
public GUIButton StartButton
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public GUIFrame InfoFrame
|
||||
{
|
||||
get { return infoFrame; }
|
||||
@@ -200,7 +206,7 @@ namespace Barotrauma
|
||||
voteText.UserData = "subvotes";
|
||||
voteText.Visible = false;
|
||||
|
||||
UpdateSubList();
|
||||
//UpdateSubList(Submarine.SavedSubmarines);
|
||||
|
||||
columnX += columnWidth + 20;
|
||||
|
||||
@@ -340,7 +346,7 @@ namespace Barotrauma
|
||||
|
||||
ServerName = (GameMain.Server==null) ? "Server" : GameMain.Server.Name;
|
||||
|
||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton"));
|
||||
infoFrame.RemoveChild(StartButton);
|
||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "settingsButton"));
|
||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton"));
|
||||
|
||||
@@ -348,6 +354,8 @@ namespace Barotrauma
|
||||
|
||||
if (IsServer && GameMain.Server != null)
|
||||
{
|
||||
UpdateSubList(Submarine.SavedSubmarines);
|
||||
|
||||
modeList.OnSelected = VotableClicked;
|
||||
modeList.OnSelected = SelectMode;
|
||||
subList.OnSelected = VotableClicked;
|
||||
@@ -359,9 +367,8 @@ namespace Barotrauma
|
||||
missionTypeButtons[0].OnClicked = ToggleMissionType;
|
||||
missionTypeButtons[1].OnClicked = ToggleMissionType;
|
||||
|
||||
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame);
|
||||
startButton.OnClicked = GameMain.Server.StartGameClicked;
|
||||
startButton.UserData = "startButton";
|
||||
StartButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame);
|
||||
StartButton.OnClicked = GameMain.Server.StartGameClicked;
|
||||
|
||||
GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame);
|
||||
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
|
||||
@@ -562,7 +569,17 @@ namespace Barotrauma
|
||||
|
||||
if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled;
|
||||
(traitorProbabilityText as GUITextBlock).Text = enabled.ToString();
|
||||
}
|
||||
|
||||
public List<Submarine> GetSubList()
|
||||
{
|
||||
List<Submarine> subs = new List<Submarine>();
|
||||
foreach (GUIComponent component in subList.children)
|
||||
{
|
||||
if (component.UserData is Submarine) subs.Add((Submarine)component.UserData);
|
||||
}
|
||||
|
||||
return subs;
|
||||
}
|
||||
|
||||
private bool SelectSub(GUIComponent component, object obj)
|
||||
@@ -583,30 +600,47 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UpdateSubList()
|
||||
public void UpdateSubList(List<Submarine> submarines)
|
||||
{
|
||||
if (subList == null) return;
|
||||
|
||||
subList.ClearChildren();
|
||||
|
||||
if (Submarine.SavedSubmarines.Count == 0)
|
||||
if (submarines.Count == 0)
|
||||
{
|
||||
DebugConsole.ThrowError("No saved submarines found!");
|
||||
DebugConsole.ThrowError("No submarines found!");
|
||||
}
|
||||
|
||||
foreach (Submarine sub in Submarine.SavedSubmarines)
|
||||
foreach (Submarine sub in submarines)
|
||||
{
|
||||
new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25), sub.Name, GUI.Style,
|
||||
Alignment.Left, Alignment.Left, subList)
|
||||
{
|
||||
Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f),
|
||||
ToolTip = sub.Description,
|
||||
UserData = sub
|
||||
};
|
||||
AddSubmarine(sub);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddSubmarine(Submarine sub)
|
||||
{
|
||||
var subTextBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25), sub.Name, GUI.Style,
|
||||
Alignment.Left, Alignment.Left, subList)
|
||||
{
|
||||
Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f),
|
||||
ToolTip = sub.Description,
|
||||
UserData = sub
|
||||
};
|
||||
|
||||
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == sub.Name);
|
||||
if (matchingSub == null)
|
||||
{
|
||||
subTextBlock.TextColor = Color.Gray;
|
||||
subTextBlock.ToolTip = "Submarine not found in your submarine folder";
|
||||
}
|
||||
else if (matchingSub.MD5Hash.Hash != sub.MD5Hash.Hash)
|
||||
{
|
||||
subTextBlock.TextColor = Color.LightGray;
|
||||
subTextBlock.ToolTip = "Your version of the submarine doesn't match the servers version";
|
||||
}
|
||||
}
|
||||
|
||||
public bool VotableClicked(GUIComponent component, object userData)
|
||||
{
|
||||
if (GameMain.Client == null) return false;
|
||||
@@ -993,6 +1027,12 @@ namespace Barotrauma
|
||||
//already downloading the selected sub file
|
||||
if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false;
|
||||
|
||||
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName);
|
||||
if (matchingListSub!=null)
|
||||
{
|
||||
subList.Select(subList.children.IndexOf(matchingListSub), true);
|
||||
}
|
||||
|
||||
Submarine sub = Submarine.SavedSubmarines.Find(m => m.Name == subName);
|
||||
if (sub == null || sub.MD5Hash.Hash != md5Hash)
|
||||
{
|
||||
@@ -1012,7 +1052,7 @@ namespace Barotrauma
|
||||
+ "Server's MD5 hash: " + md5Hash + ". ";
|
||||
}
|
||||
|
||||
string downloadMsg = GameMain.Client.ActiveFileTransferName == "" ?
|
||||
string downloadMsg = string.IsNullOrEmpty(GameMain.Client.ActiveFileTransferName) ?
|
||||
"Do you want to download the file from the server host?" :
|
||||
"Do you want to download the file and cancel downloading ''" + GameMain.Client.ActiveFileTransferName + "''?";
|
||||
|
||||
@@ -1029,23 +1069,22 @@ namespace Barotrauma
|
||||
return false;
|
||||
}
|
||||
|
||||
subList.Select(sub, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteData(NetOutgoingMessage msg)
|
||||
{
|
||||
Submarine selectedMap = subList.SelectedData as Submarine;
|
||||
Submarine selectedSub = subList.SelectedData as Submarine;
|
||||
|
||||
if (selectedMap==null)
|
||||
if (selectedSub==null)
|
||||
{
|
||||
msg.Write(" ");
|
||||
msg.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(Path.GetFileName(selectedMap.Name));
|
||||
msg.Write(selectedMap.MD5Hash.Hash);
|
||||
msg.Write(Path.GetFileName(selectedSub.Name));
|
||||
msg.Write(selectedSub.MD5Hash.Hash);
|
||||
}
|
||||
|
||||
msg.Write(ServerName);
|
||||
@@ -1113,7 +1152,7 @@ namespace Barotrauma
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to read lobby update message");
|
||||
DebugConsole.ThrowError("Failed to read lobby update message ("+e.Message+")");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user