Fixed characters not appearing in the round summary in mp, minor CrewManager refactoring

This commit is contained in:
Joonas Rikkonen
2017-11-20 20:21:18 +02:00
parent 765587efd7
commit fce7d43ef3
13 changed files with 89 additions and 57 deletions
@@ -9,8 +9,8 @@ namespace Barotrauma
{
class CrewManager
{
public List<Character> characters;
public List<CharacterInfo> CharacterInfos;
private List<CharacterInfo> characterInfos;
private List<Character> characters;
public int WinningTeam = 1;
@@ -27,7 +27,7 @@ namespace Barotrauma
public CrewManager()
{
characters = new List<Character>();
CharacterInfos = new List<CharacterInfo>();
characterInfos = new List<CharacterInfo>();
guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent);
guiFrame.Padding = Vector4.One * 5.0f;
@@ -50,10 +50,20 @@ namespace Barotrauma
{
if (subElement.Name.ToString().ToLowerInvariant() != "character") continue;
CharacterInfos.Add(new CharacterInfo(subElement));
characterInfos.Add(new CharacterInfo(subElement));
}
}
public List<Character> GetCharacters()
{
return characters;
}
public List<CharacterInfo> GetCharacterInfos()
{
return characterInfos;
}
public bool SelectCharacter(GUIComponent component, object selection)
{
//listBox.Select(selection);
@@ -108,28 +118,44 @@ namespace Barotrauma
public void AddCharacter(Character character)
{
characters.Add(character);
if (!CharacterInfos.Contains(character.Info))
if (!characterInfos.Contains(character.Info))
{
CharacterInfos.Add(character.Info);
characterInfos.Add(character.Info);
}
if (character is AICharacter)
{
commander.UpdateCharacters();
character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character);
GUIFrame orderFrame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, "ListBoxElement", orderListBox);
orderFrame.UserData = character;
var ai = character.AIController as HumanAIController;
if (ai == null)
{
DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController");
return;
}
SetCharacterOrder(character, ai.CurrentOrder);
}
}
character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character);
public void RemoveCharacter(Character character)
{
characters.Remove(character);
}
GUIFrame orderFrame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, "ListBoxElement", orderListBox);
orderFrame.UserData = character;
var ai = character.AIController as HumanAIController;
if (ai == null)
public void AddCharacterInfo(CharacterInfo characterInfo)
{
if (characterInfos.Contains(characterInfo))
{
DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController");
DebugConsole.ThrowError("Tried to add the same character info to CrewManager twice.\n" +Environment.StackTrace);
return;
}
SetCharacterOrder(character, ai.CurrentOrder);
characterInfos.Add(characterInfo);
}
public void AddToGUIUpdateList()
@@ -180,11 +206,7 @@ namespace Barotrauma
if (killedCharacter is AICharacter)
{
commander.UpdateCharacters();
}
//if (characters.Find(c => !c.IsDead)==null)
//{
// Game1.GameSession.EndShift(null, null);
//}
}
}
public void CreateCrewFrame(List<Character> crew, GUIFrame crewFrame)
@@ -231,8 +253,6 @@ namespace Barotrauma
y += crewList.Rect.Height + 30;
}
}
protected virtual bool SelectCrewCharacter(Character character, GUIComponent crewList)
@@ -254,35 +274,28 @@ namespace Barotrauma
return true;
}
//private bool ToggleCrewFrame(GUIButton button, object obj)
//{
// if (crewFrame == null) CreateCrewFrame(characters);
// crewFrameOpen = !crewFrameOpen;
// return true;
//}
public void StartRound()
{
listBox.ClearChildren();
characters.Clear();
WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(CharacterInfos, Submarine.MainSub, false);
WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub, false);
for (int i = 0; i < waypoints.Length; i++)
{
Character character;
if (CharacterInfos[i].HullID != null)
if (characterInfos[i].HullID != null)
{
var hull = Entity.FindEntityByID((ushort)CharacterInfos[i].HullID) as Hull;
var hull = Entity.FindEntityByID((ushort)characterInfos[i].HullID) as Hull;
if (hull == null) continue;
character = Character.Create(CharacterInfos[i], hull.WorldPosition);
character = Character.Create(characterInfos[i], hull.WorldPosition);
}
else
{
character = Character.Create(CharacterInfos[i], waypoints[i].WorldPosition);
character = Character.Create(characterInfos[i], waypoints[i].WorldPosition);
Character.Controlled = character;
if (character.Info != null && !character.Info.StartItemsGiven)
@@ -308,18 +321,26 @@ namespace Barotrauma
continue;
}
CharacterInfos.Remove(c.Info);
characterInfos.Remove(c.Info);
}
//remove characterinfos whose character doesn't exist anymore
//(i.e. character was removed during the round)
CharacterInfos.RemoveAll(c => c.Character == null);
characterInfos.RemoveAll(c => c.Character == null);
characters.Clear();
listBox.ClearChildren();
orderListBox.ClearChildren();
}
public void Reset()
{
characters.Clear();
characterInfos.Clear();
listBox.ClearChildren();
orderListBox.ClearChildren();
}
public void Draw(SpriteBatch spriteBatch)
{
if (commander.IsOpen)
@@ -336,7 +357,7 @@ namespace Barotrauma
{
XElement element = new XElement("crew");
foreach (CharacterInfo ci in CharacterInfos)
foreach (CharacterInfo ci in characterInfos)
{
ci.Save(element);
}
@@ -48,7 +48,7 @@ namespace Barotrauma
break;
}
CrewManager.CharacterInfos.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab));
CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab));
}
}
@@ -74,7 +74,7 @@ namespace Barotrauma
if (Money < characterInfo.Salary) return false;
hireManager.availableCharacters.Remove(characterInfo);
CrewManager.CharacterInfos.Add(characterInfo);
CrewManager.AddCharacterInfo(characterInfo);
Money -= characterInfo.Salary;
return true;
@@ -155,7 +155,7 @@ namespace Barotrauma
if (!crewDead)
{
if (!CrewManager.characters.Any(c => !c.IsDead)) crewDead = true;
if (!CrewManager.GetCharacters().Any(c => !c.IsDead)) crewDead = true;
}
else
{
@@ -169,7 +169,7 @@ namespace Barotrauma
{
isRunning = false;
bool success = CrewManager.characters.Any(c => !c.IsDead);
bool success = CrewManager.GetCharacters().Any(c => !c.IsDead);
if (success)
{
@@ -290,7 +290,7 @@ namespace Barotrauma
var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f);
SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endround" : "crewdead";
SoundPlayer.OverrideMusicType = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead";
CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic");
@@ -77,7 +77,7 @@ namespace Barotrauma
switch (selectedTab)
{
case InfoFrameTab.Crew:
CrewManager.CreateCrewFrame(CrewManager.characters, infoFrame.children[0] as GUIFrame);
CrewManager.CreateCrewFrame(CrewManager.GetCharacters(), infoFrame.children[0] as GUIFrame);
break;
case InfoFrameTab.Mission:
CreateMissionInfo(infoFrame.children[0] as GUIFrame);
@@ -26,7 +26,7 @@ namespace Barotrauma
{
bool singleplayer = GameMain.NetworkMember == null;
bool gameOver = gameSession.CrewManager.characters.All(c => c.IsDead);
bool gameOver = gameSession.CrewManager.GetCharacters().All(c => c.IsDead);
bool progress = Submarine.MainSub.AtEndPosition;
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.8f, null);
@@ -59,7 +59,7 @@ namespace Barotrauma
GUIListBox listBox = new GUIListBox(new Rectangle(0,y,0,90), null, Alignment.TopLeft, "", innerFrame, true);
int x = 0;
foreach (CharacterInfo characterInfo in gameSession.CrewManager.CharacterInfos)
foreach (CharacterInfo characterInfo in gameSession.CrewManager.GetCharacterInfos())
{
if (GameMain.GameSession.Mission is CombatMission &&
characterInfo.TeamID != GameMain.GameSession.CrewManager.WinningTeam)