From 04b0c63f30a0ffc6318009567324b15c87630f5b Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 24 Sep 2017 13:41:54 +0300 Subject: [PATCH] Campaign mode can't be voted for. The host has to manually create/select the campaign save, so switching to the campaign mode when the host isn't present would cause problems. --- .../Source/Networking/Voting.cs | 11 ++++++- .../Source/Screens/NetLobbyScreen.cs | 2 ++ .../Source/GameSession/GameModes/GameMode.cs | 30 ++----------------- .../GameSession/GameModes/GameModePreset.cs | 25 +++++++++++++--- .../Source/Networking/Voting.cs | 2 ++ 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs b/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs index 4852a7057..a8070cdec 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs @@ -38,6 +38,15 @@ namespace Barotrauma allowModeVoting = value; GameMain.NetLobbyScreen.ModeList.Enabled = value || GameMain.Server != null; GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value; + + //gray out modes that can't be voted + foreach (GUITextBlock comp in GameMain.NetLobbyScreen.ModeList.children) + { + comp.TextColor = + new Color(comp.TextColor.R, comp.TextColor.G, comp.TextColor.B, + !allowModeVoting || ((GameModePreset)comp.UserData).Votable ? (byte)255 : (byte)100); + } + if (GameMain.Server != null) { UpdateVoteTexts(value ? GameMain.Server.ConnectedClients : null, VoteType.Mode); @@ -56,7 +65,7 @@ namespace Barotrauma GUIListBox listBox = (voteType == VoteType.Sub) ? GameMain.NetLobbyScreen.SubList : GameMain.NetLobbyScreen.ModeList; - foreach (GUIComponent comp in listBox.children) + foreach (GUITextBlock comp in listBox.children) { GUITextBlock voteText = comp.FindChild("votes") as GUITextBlock; if (voteText != null) comp.RemoveChild(voteText); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index 7374d0ce2..ccef467e4 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -763,6 +763,8 @@ namespace Barotrauma else if (component.Parent == GameMain.NetLobbyScreen.ModeList) { if (!GameMain.Client.Voting.AllowModeVoting) return false; + if (!((GameModePreset)userData).Votable) return false; + voteType = VoteType.Mode; } else diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs index 4689b779d..e7571b808 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs @@ -8,13 +8,9 @@ namespace Barotrauma public static List PresetList = new List(); protected DateTime startTime; - - //public readonly bool IsSinglePlayer; - + protected bool isRunning; - - //protected string name; - + protected GameModePreset preset; private string endMessage; @@ -57,13 +53,6 @@ namespace Barotrauma public virtual void Start() { startTime = DateTime.Now; - //if (duration!=TimeSpan.Zero) - //{ - // endTime = startTime + duration; - // this.duration = duration; - - // timerBar = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null); - //} endMessage = "The round has ended!"; @@ -74,20 +63,7 @@ namespace Barotrauma public virtual void AddToGUIUpdateList() { } - public virtual void Update(float deltaTime) - { - //if (!isRunning) return; - - //if (duration != TimeSpan.Zero) - //{ - // double elapsedTime = (DateTime.Now - startTime).TotalSeconds; - // timerBar.BarSize = (float)(elapsedTime / duration.TotalSeconds); - //} - //if (DateTime.Now >= endTime) - //{ - // End(endMessage); - //} - } + public virtual void Update(float deltaTime) { } public virtual void End(string endMessage = "") { diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs index 7bc0c9278..3cacf5f07 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/GameModePreset.cs @@ -10,17 +10,34 @@ namespace Barotrauma public ConstructorInfo Constructor; public string Name; - public bool IsSinglePlayer; - public string Description; + public bool IsSinglePlayer + { + get; + private set; + } - public GameModePreset(string name, Type type, bool isSinglePlayer = false) + //are clients allowed to vote for this gamemode + public bool Votable + { + get; + private set; + } + + public string Description + { + get; + private set; + } + + public GameModePreset(string name, Type type, bool isSinglePlayer = false, bool votable = true) { this.Name = name; Constructor = type.GetConstructor(new Type[] { typeof(GameModePreset), typeof(object) }); IsSinglePlayer = isSinglePlayer; + Votable = votable; list.Add(this); } @@ -46,7 +63,7 @@ namespace Barotrauma + "an alien artifact or killing a creature that's terrorizing nearby outposts. The game ends " + "when the task is completed or everyone in the crew has died."; - new GameModePreset("Campaign", typeof(MultiplayerCampaign), false); + new GameModePreset("Campaign", typeof(MultiplayerCampaign), false, false); } } } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/Voting.cs b/Barotrauma/BarotraumaShared/Source/Networking/Voting.cs index ab0a55c11..c96b06319 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/Voting.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/Voting.cs @@ -103,6 +103,8 @@ namespace Barotrauma case VoteType.Mode: string modeName = inc.ReadString(); GameModePreset mode = GameModePreset.list.Find(gm => gm.Name == modeName); + if (!mode.Votable) break; + sender.SetVote(voteType, mode); #if CLIENT UpdateVoteTexts(GameMain.Server.ConnectedClients, voteType);