Voting UI fixes:

- The vote count texts are removed when voting is disabled.
- Server sends vote status to joining clients (-> clients see the number of votes immediately, not after someone votes something).
- Server refreshes vote count texts when a client disconnects.
This commit is contained in:
Joonas Rikkonen
2017-09-21 20:37:30 +03:00
parent 8c3c689596
commit 5a4bc0242d
2 changed files with 31 additions and 19 deletions

View File

@@ -19,11 +19,12 @@ namespace Barotrauma
if (GameMain.Server != null)
{
UpdateVoteTexts(GameMain.Server.ConnectedClients, VoteType.Sub);
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Sub);
GameMain.Server.UpdateVoteStatus();
}
else
{
UpdateVoteTexts(null, VoteType.Sub);
GameMain.NetLobbyScreen.SubList.Deselect();
}
}
@@ -39,11 +40,12 @@ namespace Barotrauma
GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
if (GameMain.Server != null)
{
UpdateVoteTexts(GameMain.Server.ConnectedClients, VoteType.Mode);
UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Mode);
GameMain.Server.UpdateVoteStatus();
}
else
{
UpdateVoteTexts(null, VoteType.Mode);
GameMain.NetLobbyScreen.ModeList.Deselect();
}
}
@@ -60,10 +62,13 @@ namespace Barotrauma
if (voteText != null) comp.RemoveChild(voteText);
}
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
foreach (Pair<object, int> votable in voteList)
if (clients != null)
{
SetVoteText(listBox, votable.First, votable.Second);
List<Pair<object, int>> voteList = GetVoteList(voteType, clients);
foreach (Pair<object, int> votable in voteList)
{
SetVoteText(listBox, votable.First, votable.Second);
}
}
}
@@ -127,10 +132,7 @@ namespace Barotrauma
AllowSubVoting = inc.ReadBoolean();
if (allowSubVoting)
{
foreach (Submarine sub in Submarine.SavedSubmarines)
{
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, 0);
}
UpdateVoteTexts(null, VoteType.Sub);
int votableCount = inc.ReadByte();
for (int i = 0; i < votableCount; i++)
{
@@ -143,6 +145,7 @@ namespace Barotrauma
AllowModeVoting = inc.ReadBoolean();
if (allowModeVoting)
{
UpdateVoteTexts(null, VoteType.Mode);
int votableCount = inc.ReadByte();
for (int i = 0; i < votableCount; i++)
{

View File

@@ -1001,6 +1001,8 @@ namespace Barotrauma.Networking
//and assume the message was received, so we don't have to keep resending
//these large initial messages until the client acknowledges receiving them
c.lastRecvGeneralUpdate++;
SendVoteStatus(new List<Client>() { c });
}
else
{
@@ -1559,11 +1561,13 @@ namespace Barotrauma.Networking
Log(msg, ServerLog.MessageType.ServerMessage);
client.Connection.Disconnect(targetmsg);
connectedClients.Remove(client);
#if CLIENT
GameMain.NetLobbyScreen.RemovePlayer(client.name);
GameMain.NetLobbyScreen.RemovePlayer(client.name);
Voting.UpdateVoteTexts(connectedClients, VoteType.Sub);
Voting.UpdateVoteTexts(connectedClients, VoteType.Mode);
#endif
connectedClients.Remove(client);
UpdateVoteStatus();
@@ -1851,14 +1855,8 @@ namespace Barotrauma.Networking
}
GameMain.NetLobbyScreen.LastUpdateID++;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
msg.Write((byte)ServerNetObject.VOTE);
Voting.ServerWrite(msg);
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
SendVoteStatus(connectedClients);
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
@@ -1868,6 +1866,17 @@ namespace Barotrauma.Networking
}
}
public void SendVoteStatus(List<Client> recipients)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
msg.Write((byte)ServerNetObject.VOTE);
Voting.ServerWrite(msg);
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
server.SendMessage(msg, recipients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
}
public void UpdateClientPermissions(Client client)
{
clientPermissions.RemoveAll(cp => cp.IP == client.Connection.RemoteEndPoint.Address.ToString());