- separate listboxes for both teams in the crew menu

- fixed host getting team ID 0
- fixed clients not spawning if their ID is 0 (= if playing a non-combat mission before IDs have been assigned)
- fixed host's character taking part in the job assignment of both teams
This commit is contained in:
Regalis
2016-10-05 20:15:39 +03:00
parent 41c38575b9
commit fb28fc8cda
4 changed files with 93 additions and 76 deletions

View File

@@ -208,35 +208,48 @@ namespace Barotrauma
public void CreateCrewFrame(List<Character> crew, GUIFrame crewFrame)
{
//crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
//crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
List<byte> teamIDs = crew.Select(c => c.TeamID).Distinct().ToList();
GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame);
crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
crewList.OnSelected = SelectCrewCharacter;
if (!teamIDs.Any()) teamIDs.Add(0);
foreach (Character character in crew)
int listBoxHeight = 300 / teamIDs.Count;
int y = 20;
for (int i = 0; i < teamIDs.Count; i++)
{
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
frame.UserData = character;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent;
frame.HoverColor = Color.LightGray * 0.5f;
frame.SelectedColor = Color.Gold * 0.5f;
if (teamIDs.Count > 1)
{
new GUITextBlock(new Rectangle(0,y-20,100,20),"Team "+teamIDs[i], GUI.Style, crewFrame);
}
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
character.Info.Name + " (" + character.Info.Job.Name + ")",
Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
null, frame);
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
GUIListBox crewList = new GUIListBox(new Rectangle(0, y, 280, listBoxHeight), Color.White * 0.7f, GUI.Style, crewFrame);
crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
crewList.OnSelected = SelectCrewCharacter;
foreach (Character character in crew.FindAll(c => c.TeamID == teamIDs[i]))
{
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
frame.UserData = character;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.Color = (GameMain.NetworkMember != null && GameMain.NetworkMember.Character == character) ? Color.Gold * 0.2f : Color.Transparent;
frame.HoverColor = Color.LightGray * 0.5f;
frame.SelectedColor = Color.Gold * 0.5f;
new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
character.Info.Name + " (" + character.Info.Job.Name + ")",
Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
null, frame);
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
}
y += crewList.Rect.Height + 30;
}
//var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame);
//closeButton.OnClicked = ToggleCrewFrame;
}
protected virtual bool SelectCrewCharacter(GUIComponent component, object obj)

View File

@@ -66,46 +66,48 @@ namespace Barotrauma
int x = 0;
foreach (Character character in gameSession.CrewManager.characters)
{
if (singleplayer || character.TeamID == GameMain.GameSession.CrewManager.WinningTeam)
if (GameMain.GameSession.Mission is CombatMission &&
character.TeamID != GameMain.GameSession.CrewManager.WinningTeam)
{
var characterFrame = new GUIFrame(new Rectangle(x, y, 170, 70), Color.Transparent, GUI.Style, listBox);
characterFrame.OutlineColor = Color.Transparent;
characterFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterFrame.CanBeFocused = false;
character.Info.CreateCharacterFrame(characterFrame,
character.Info.Job != null ? (character.Info.Name + '\n' + "(" + character.Info.Job.Name + ")") : character.Info.Name, null);
string statusText = "OK";
Color statusColor = Color.DarkGreen;
if (character.IsDead)
{
statusText = InfoTextManager.GetInfoText("CauseOfDeath." + character.CauseOfDeath.ToString());
statusColor = Color.DarkRed;
}
else
{
if (character.IsUnconscious)
{
statusText = "Unconscious";
statusColor = Color.DarkOrange;
}
else if (character.Health / character.MaxHealth < 0.8f)
{
statusText = "Injured";
statusColor = Color.DarkOrange;
}
}
new GUITextBlock(new Rectangle(0, 0, 0, 20), statusText,
GUI.Style, Alignment.BottomLeft, Alignment.TopCenter, characterFrame, true, GUI.SmallFont).Color = statusColor * 0.7f;
x += characterFrame.Rect.Width + 10;
continue;
}
var characterFrame = new GUIFrame(new Rectangle(x, y, 170, 70), Color.Transparent, GUI.Style, listBox);
characterFrame.OutlineColor = Color.Transparent;
characterFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterFrame.CanBeFocused = false;
character.Info.CreateCharacterFrame(characterFrame,
character.Info.Job != null ? (character.Info.Name + '\n' + "(" + character.Info.Job.Name + ")") : character.Info.Name, null);
string statusText = "OK";
Color statusColor = Color.DarkGreen;
if (character.IsDead)
{
statusText = InfoTextManager.GetInfoText("CauseOfDeath." + character.CauseOfDeath.ToString());
statusColor = Color.DarkRed;
}
else
{
if (character.IsUnconscious)
{
statusText = "Unconscious";
statusColor = Color.DarkOrange;
}
else if (character.Health / character.MaxHealth < 0.8f)
{
statusText = "Injured";
statusColor = Color.DarkOrange;
}
}
new GUITextBlock(new Rectangle(0, 0, 0, 20), statusText,
GUI.Style, Alignment.BottomLeft, Alignment.TopCenter, characterFrame, true, GUI.SmallFont).Color = statusColor * 0.7f;
x += characterFrame.Rect.Width + 10;
}
y += 120;

View File

@@ -907,12 +907,13 @@ namespace Barotrauma.Networking
if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
for (int j = 1; j <= teamCount; j++)
for (int teamID = 1; teamID <= teamCount; teamID++)
{
List<Client> teamClients = connectedClients.FindAll(c => c.TeamID == j);
if (!teamClients.Any() && j!=1) continue;
List<Client> teamClients = teamCount == 1 ? connectedClients : connectedClients.FindAll(c => c.TeamID == teamID);
AssignJobs(teamClients);
if (!teamClients.Any() && teamID > 1) continue;
AssignJobs(teamClients, teamID==1);
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
@@ -929,13 +930,14 @@ namespace Barotrauma.Networking
client.characterInfo.Job = new Job(client.assignedJob);
}
if (characterInfo != null && j == 1)
//host's character
if (characterInfo != null && teamID == 1)
{
characterInfo.Job = new Job(GameMain.NetLobbyScreen.JobPreferences[0]);
characterInfos.Add(characterInfo);
}
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[j - 1]);
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[teamID - 1]);
for (int i = 0; i < teamClients.Count; i++)
{
@@ -945,17 +947,17 @@ namespace Barotrauma.Networking
GameMain.GameSession.CrewManager.characters.Add(teamClients[i].Character);
teamClients[i].Character.TeamID = teamClients[i].TeamID;
teamClients[i].Character.TeamID = (byte)teamID;
}
//host plays in team 1
if (characterInfo != null && j == 1)
if (characterInfo != null && teamID == 1)
{
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
Character.Controlled = myCharacter;
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
myCharacter.TeamID = (byte)teamID;
Character.Controlled = myCharacter;
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
}
}
@@ -1781,13 +1783,13 @@ namespace Barotrauma.Networking
SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients);
}
public void AssignJobs(List<Client> unassigned)
public void AssignJobs(List<Client> unassigned, bool assignHost)
{
unassigned = new List<Client>(unassigned);
int[] assignedClientCount = new int[JobPrefab.List.Count];
if (characterInfo!=null)
if (characterInfo!=null && assignHost)
{
assignedClientCount[JobPrefab.List.FindIndex(jp => jp == GameMain.NetLobbyScreen.JobPreferences[0])]=1;
}

View File

@@ -392,12 +392,12 @@ namespace Barotrauma.Networking
var clients = GetClientsToRespawn();
server.AssignJobs(clients);
clients.ForEach(c => c.characterInfo.Job = new Job(c.assignedJob));
List<CharacterInfo> characterInfos = clients.Select(c => c.characterInfo).ToList();
if (server.Character != null && server.Character.IsDead) characterInfos.Add(server.CharacterInfo);
server.AssignJobs(clients, server.Character != null && server.Character.IsDead);
clients.ForEach(c => c.characterInfo.Job = new Job(c.assignedJob));
//the spawnpoints where the characters will spawn
var shuttleSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle);
//the spawnpoints where they would spawn if they were spawned inside the main sub