Voting for round to end, level generation improvements

This commit is contained in:
Regalis
2016-02-12 19:39:24 +02:00
parent 3ffc19485b
commit c6f52cc68f
20 changed files with 294 additions and 129 deletions
@@ -292,6 +292,7 @@ namespace Barotrauma
}
Submarine.SaveCurrent(nameBox.Text + ".sub");
Submarine.Loaded.CheckForErrors();
GUI.AddMessage("Submarine saved to " + Submarine.Loaded.FilePath, Color.Green, 3.0f);
@@ -355,6 +355,8 @@ namespace Barotrauma
playYourself.UserData = "playyourself";
}
GameMain.Server.Voting.ResetVotes(GameMain.Server.ConnectedClients);
if (GameMain.Server.RandomizeSeed) LevelSeed = ToolBox.RandomSeed(8);
if (GameMain.Server.SubSelectionMode == SelectionMode.Random) subList.Select(Rand.Range(0,subList.CountChildren));
if (GameMain.Server.ModeSelectionMode == SelectionMode.Random) modeList.Select(Rand.Range(0, modeList.CountChildren));
@@ -368,6 +370,8 @@ namespace Barotrauma
spectateButton.UserData = "spectateButton";
}
GameMain.Client.Voting.ResetVotes(GameMain.Client.OtherClients);
UpdatePlayerFrame(GameMain.Client.CharacterInfo);
}
+39 -6
View File
@@ -12,6 +12,8 @@ namespace Barotrauma
{
private bool allowSubVoting, allowModeVoting;
public bool AllowEndVoting = true;
public bool AllowSubVoting
{
get { return allowSubVoting; }
@@ -83,7 +85,12 @@ namespace Barotrauma
UpdateVoteTexts(connectedClients, voteType);
break;
case VoteType.EndRound:
if (sender.Character == null) return;
sender.SetVote(voteType, inc.ReadBoolean());
GameMain.NetworkMember.EndVoteCount = connectedClients.Count(c => c.Character != null && c.GetVote<bool>(VoteType.EndRound));
GameMain.NetworkMember.EndVoteMax = connectedClients.Count(c => c.Character != null);
break;
}
@@ -107,7 +114,7 @@ namespace Barotrauma
SetVoteText(listBox, votable.First, votable.Second);
}
}
private void SetVoteText(GUIListBox listBox, object userData, int votes)
{
if (userData == null) return;
@@ -124,14 +131,14 @@ namespace Barotrauma
voteText.Text = votes.ToString();
}
}
private List<Pair<object, int>> GetVoteList(VoteType voteType, List<Client> voters)
{
List<Pair<object, int>> voteList = new List<Pair<object, int>>();
foreach (Client voter in voters)
{
object vote = voter.GetVote(voteType);
object vote = voter.GetVote<object>(voteType);
if (vote == null) continue;
var existingVotable = voteList.Find(v => v.First == vote);
@@ -167,6 +174,20 @@ namespace Barotrauma
return selected;
}
public void ResetVotes(List<Client> connectedClients)
{
foreach (Client client in connectedClients)
{
client.ResetVotes();
}
GameMain.NetworkMember.EndVoteCount = 0;
GameMain.NetworkMember.EndVoteMax = 0;
UpdateVoteTexts(connectedClients, VoteType.Mode);
UpdateVoteTexts(connectedClients, VoteType.Sub);
}
public void WriteData(NetOutgoingMessage msg, List<Client> voters)
{
@@ -198,17 +219,22 @@ namespace Barotrauma
}
}
msg.Write(AllowEndVoting);
if (AllowEndVoting)
{
msg.Write((byte)voters.Count);
msg.Write((byte)voters.Count(v => v.GetVote<bool>(VoteType.EndRound)));
}
}
public void ReadData(NetIncomingMessage msg)
{
AllowSubVoting = msg.ReadBoolean();
AllowSubVoting = msg.ReadBoolean();
if (allowSubVoting)
{
int votableCount = msg.ReadByte();
for (int i = 0; i<votableCount; i++)
for (int i = 0; i < votableCount; i++)
{
int votes = msg.ReadByte();
string subName = msg.ReadString();
@@ -229,6 +255,13 @@ namespace Barotrauma
SetVoteText(GameMain.NetLobbyScreen.SubList, mode, votes);
}
}
AllowEndVoting = msg.ReadBoolean();
if (AllowEndVoting)
{
GameMain.NetworkMember.EndVoteCount = msg.ReadByte();
GameMain.NetworkMember.EndVoteMax = msg.ReadByte();
}
}
}
}