Voting for round to end, level generation improvements
This commit is contained in:
@@ -15,6 +15,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private ReliableChannel reliableChannel;
|
||||
|
||||
private GUIButton endRoundButton;
|
||||
|
||||
private bool connected;
|
||||
|
||||
private int myID;
|
||||
@@ -28,8 +30,17 @@ namespace Barotrauma.Networking
|
||||
get { return myID; }
|
||||
}
|
||||
|
||||
public List<Client> OtherClients
|
||||
{
|
||||
get { return otherClients; }
|
||||
}
|
||||
|
||||
public GameClient(string newName)
|
||||
{
|
||||
endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD);
|
||||
endRoundButton.OnClicked = EndRoundClicked;
|
||||
endRoundButton.Visible = false;
|
||||
|
||||
GameMain.DebugDraw = false;
|
||||
Hull.EditFire = false;
|
||||
Hull.EditWater = false;
|
||||
@@ -230,7 +241,6 @@ namespace Barotrauma.Networking
|
||||
new GUIMessageBox("Connection timed out", "You were disconnected for too long and your Character was deleted. Please wait for another round to start.");
|
||||
}
|
||||
|
||||
|
||||
GameMain.NetLobbyScreen.ClearPlayers();
|
||||
|
||||
//add the names of other connected clients to the lobby screen
|
||||
@@ -590,6 +600,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
gameStarted = true;
|
||||
|
||||
endRoundButton.Visible = Voting.AllowEndVoting;
|
||||
|
||||
GameMain.GameScreen.Select();
|
||||
|
||||
AddChatMessage("Press TAB to chat", ChatMessageType.Server);
|
||||
@@ -659,7 +671,7 @@ namespace Barotrauma.Networking
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
if (!GameMain.DebugDraw) return;
|
||||
|
||||
int width = 200, height = 300;
|
||||
@@ -696,13 +708,16 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
case VoteType.Sub:
|
||||
msg.Write(((Submarine)userData).Name);
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
break;
|
||||
case VoteType.Mode:
|
||||
msg.Write(((GameModePreset)userData).Name);
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
break;
|
||||
case VoteType.EndRound:
|
||||
msg.Write((bool)userData);
|
||||
break;
|
||||
}
|
||||
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
public bool SpectateClicked(GUIButton button, object userData)
|
||||
@@ -717,6 +732,23 @@ namespace Barotrauma.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool EndRoundClicked(GUIButton button, object userData)
|
||||
{
|
||||
if (!gameStarted) return false;
|
||||
|
||||
if (!Voting.AllowEndVoting)
|
||||
{
|
||||
button.Visible = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vote(VoteType.EndRound, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SendCharacterData()
|
||||
{
|
||||
if (characterInfo == null) return;
|
||||
@@ -794,7 +826,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (client.ServerConnection == null) return;
|
||||
|
||||
type = (gameStarted && myCharacter != null && myCharacter.IsDead) ? ChatMessageType.Dead : ChatMessageType.Default;
|
||||
type = (Screen.Selected == GameMain.GameScreen &&
|
||||
(myCharacter == null || myCharacter.IsDead)) ? ChatMessageType.Dead : ChatMessageType.Default;
|
||||
|
||||
ReliableMessage msg = reliableChannel.CreateMessage();
|
||||
msg.InnerMessage.Write((byte)PacketTypes.Chatmessage);
|
||||
|
||||
@@ -473,6 +473,12 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
case (byte)PacketTypes.Vote:
|
||||
Voting.RegisterVote(inc, ConnectedClients);
|
||||
|
||||
if (Voting.AllowEndVoting &&
|
||||
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
||||
{
|
||||
EndButtonHit(null,null);
|
||||
}
|
||||
break;
|
||||
case (byte)PacketTypes.RequestNetLobbyUpdate:
|
||||
UpdateNetLobby(null, null);
|
||||
@@ -860,9 +866,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
private bool EndButtonHit(GUIButton button, object obj)
|
||||
{
|
||||
if (!gameStarted) return false;
|
||||
|
||||
string endMessage = "The round has ended." + '\n';
|
||||
|
||||
if (TraitorManager!=null)
|
||||
if (TraitorManager != null)
|
||||
{
|
||||
endMessage += TraitorManager.GetEndMessage();
|
||||
}
|
||||
@@ -1092,7 +1100,7 @@ namespace Barotrauma.Networking
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (settingsFrame != null) settingsFrame.Draw(spriteBatch);
|
||||
|
||||
|
||||
if (!ShowNetStats) return;
|
||||
|
||||
int width = 200, height = 300;
|
||||
@@ -1465,14 +1473,22 @@ namespace Barotrauma.Networking
|
||||
jobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0,3));
|
||||
}
|
||||
|
||||
public object GetVote(VoteType voteType)
|
||||
public T GetVote<T>(VoteType voteType)
|
||||
{
|
||||
return votes[(int)voteType];
|
||||
return (votes[(int)voteType] is T) ? (T)votes[(int)voteType] : default(T);
|
||||
}
|
||||
|
||||
public void SetVote(VoteType voteType, object value)
|
||||
{
|
||||
votes[(int)voteType] = value;
|
||||
}
|
||||
|
||||
public void ResetVotes()
|
||||
{
|
||||
for (int i = 0; i<votes.Length; i++)
|
||||
{
|
||||
votes[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Barotrauma.Networking
|
||||
private GUIFrame settingsFrame;
|
||||
|
||||
public float AutoRestartTimer;
|
||||
|
||||
|
||||
private bool autoRestart;
|
||||
|
||||
private bool allowSpectating = true;
|
||||
@@ -85,6 +85,8 @@ namespace Barotrauma.Networking
|
||||
get { return allowSpectating; }
|
||||
}
|
||||
|
||||
public float EndVoteRequiredRatio;
|
||||
|
||||
private void CreateSettingsFrame()
|
||||
{
|
||||
settingsFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f);
|
||||
@@ -93,16 +95,39 @@ namespace Barotrauma.Networking
|
||||
|
||||
new GUITextBlock(new Rectangle(0, -15, 0, 20), "Server settings", GUI.Style, innerFrame, GUI.LargeFont);
|
||||
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, 30, 20, 20), "Randomize level seed", Alignment.Left, innerFrame);
|
||||
var randomizeLevelBox = new GUITickBox(new Rectangle(0, 30, 20, 20), "Randomize level seed between rounds", Alignment.Left, innerFrame);
|
||||
randomizeLevelBox.Selected = randomizeSeed;
|
||||
randomizeLevelBox.OnSelected = ToggleRandomizeSeed;
|
||||
|
||||
var endBox = new GUITickBox(new Rectangle(0, 60, 20, 20), "End round when destination reached", Alignment.Left, innerFrame);
|
||||
endBox.Selected = endRoundAtLevelEnd;
|
||||
endBox.OnSelected = (GUITickBox) => { endRoundAtLevelEnd = GUITickBox.Selected; return true; };
|
||||
|
||||
var endVoteBox = new GUITickBox(new Rectangle(0, 90, 20, 20), "End round by voting", Alignment.Left, innerFrame);
|
||||
endVoteBox.Selected = Voting.AllowEndVoting;
|
||||
endVoteBox.OnSelected = (GUITickBox) =>
|
||||
{
|
||||
Voting.AllowEndVoting = !Voting.AllowEndVoting;
|
||||
GameMain.Server.UpdateVoteStatus();
|
||||
return true;
|
||||
};
|
||||
|
||||
var votesRequiredText = new GUITextBlock(new Rectangle(20, 110, 20, 20), "Votes required: 50 %", GUI.Style, innerFrame, GUI.SmallFont);
|
||||
|
||||
var votesRequiredSlider = new GUIScrollBar(new Rectangle(150,115, 100, 10), GUI.Style, 0.1f, innerFrame);
|
||||
votesRequiredSlider.UserData = votesRequiredText;
|
||||
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;
|
||||
};
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 95, 100, 20), "Submarine selection:", GUI.Style, innerFrame);
|
||||
var selectionFrame = new GUIFrame(new Rectangle(0, 120, 300, 20), null, innerFrame);
|
||||
new GUITextBlock(new Rectangle(0, 95+50, 100, 20), "Submarine selection:", GUI.Style, innerFrame);
|
||||
var selectionFrame = new GUIFrame(new Rectangle(0, 120 + 50, 300, 20), null, innerFrame);
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
var selectionTick = new GUITickBox(new Rectangle(i * 100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
|
||||
@@ -110,9 +135,9 @@ namespace Barotrauma.Networking
|
||||
selectionTick.OnSelected = SwitchSubSelection;
|
||||
selectionTick.UserData = (SelectionMode)i;
|
||||
}
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 145, 100, 20), "Mode selection:", GUI.Style, innerFrame);
|
||||
selectionFrame = new GUIFrame(new Rectangle(0, 170, 300, 20), null, innerFrame);
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 145 + 50, 100, 20), "Mode selection:", GUI.Style, innerFrame);
|
||||
selectionFrame = new GUIFrame(new Rectangle(0, 170 + 50, 300, 20), null, innerFrame);
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
var selectionTick = new GUITickBox(new Rectangle(i*100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
|
||||
@@ -120,8 +145,8 @@ namespace Barotrauma.Networking
|
||||
selectionTick.OnSelected = SwitchModeSelection;
|
||||
selectionTick.UserData = (SelectionMode)i;
|
||||
}
|
||||
|
||||
var allowSpecBox = new GUITickBox(new Rectangle(0, 210, 20, 20), "Allow spectating", Alignment.Left, innerFrame);
|
||||
|
||||
var allowSpecBox = new GUITickBox(new Rectangle(0, 210 + 50, 20, 20), "Allow spectating", Alignment.Left, innerFrame);
|
||||
allowSpecBox.Selected = true;
|
||||
allowSpecBox.OnSelected = ToggleAllowSpectating;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Barotrauma.Networking
|
||||
class NetworkMember
|
||||
{
|
||||
|
||||
protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen };
|
||||
protected static Color[] messageColor = { Color.White, Color.Red, new Color(63,72,204), Color.LightGreen };
|
||||
|
||||
protected NetPeer netPeer;
|
||||
|
||||
@@ -60,6 +60,10 @@ namespace Barotrauma.Networking
|
||||
protected GUIListBox chatBox;
|
||||
protected GUITextBox chatMsgBox;
|
||||
|
||||
|
||||
public int EndVoteCount, EndVoteMax;
|
||||
//private GUITextBlock endVoteText;
|
||||
|
||||
public int Port;
|
||||
|
||||
protected bool gameStarted;
|
||||
@@ -122,7 +126,6 @@ namespace Barotrauma.Networking
|
||||
chatMsgBox.Padding = Vector4.Zero;
|
||||
chatMsgBox.OnEnterPressed = EnterChatMessage;
|
||||
|
||||
|
||||
Voting = new Voting();
|
||||
}
|
||||
|
||||
@@ -247,6 +250,12 @@ namespace Barotrauma.Networking
|
||||
GameMain.GameSession.CrewManager.Draw(spriteBatch);
|
||||
|
||||
inGameHUD.Draw(spriteBatch);
|
||||
|
||||
if (EndVoteCount > 0)
|
||||
{
|
||||
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 150.0f, 40), "Votes: " + EndVoteCount + "/" + EndVoteMax, Color.White);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
|
||||
Reference in New Issue
Block a user