(46cd6704b) Add some extra null checks trying to blind fix #1529.

This commit is contained in:
Joonas Rikkonen
2019-06-11 21:49:07 +03:00
parent 7de768085e
commit cf7c0533fe
2 changed files with 31 additions and 24 deletions
@@ -20,8 +20,8 @@ namespace Barotrauma
/// </summary> /// </summary>
const float CharacterWaitOnSwitch = 10.0f; const float CharacterWaitOnSwitch = 10.0f;
private List<CharacterInfo> characterInfos = new List<CharacterInfo>(); private readonly List<CharacterInfo> characterInfos = new List<CharacterInfo>();
private List<Character> characters = new List<Character>(); private readonly List<Character> characters = new List<Character>();
private Point screenResolution; private Point screenResolution;
@@ -437,40 +437,47 @@ namespace Barotrauma
if (characterPreviewFrame != null) if (characterPreviewFrame != null)
{ {
characterPreviewFrame.Parent.RemoveChild(characterPreviewFrame); characterPreviewFrame.Parent?.RemoveChild(characterPreviewFrame);
characterPreviewFrame = null; characterPreviewFrame = null;
} }
if (Campaign is SinglePlayerCampaign) if (characterList != null)
{ {
var hireableCharacters = location.GetHireableCharacters(); if (Campaign is SinglePlayerCampaign)
foreach (GUIComponent child in characterList.Content.Children.ToList())
{ {
if (child.UserData is CharacterInfo character) var hireableCharacters = location.GetHireableCharacters();
foreach (GUIComponent child in characterList.Content.Children.ToList())
{ {
if (GameMain.GameSession.CrewManager.GetCharacterInfos().Contains(character)) { continue; } if (child.UserData is CharacterInfo character)
{
if (GameMain.GameSession.CrewManager != null)
{
if (GameMain.GameSession.CrewManager.GetCharacterInfos().Contains(character)) { continue; }
}
}
else if (child.UserData as string == "mycrew" || child.UserData as string == "hire")
{
continue;
}
characterList.RemoveChild(child);
} }
else if (child.UserData as string == "mycrew" || child.UserData as string == "hire") if (!hireableCharacters.Any())
{ {
continue; new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), characterList.Content.RectTransform), TextManager.Get("HireUnavailable"), textAlignment: Alignment.Center)
{
CanBeFocused = false
};
} }
characterList.RemoveChild(child); else
}
if (!hireableCharacters.Any())
{
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), characterList.Content.RectTransform), TextManager.Get("HireUnavailable"), textAlignment: Alignment.Center)
{ {
CanBeFocused = false foreach (CharacterInfo c in hireableCharacters)
}; {
} var frame = c.CreateCharacterFrame(characterList.Content, c.Name + " (" + c.Job.Name + ")", c);
else new GUITextBlock(new RectTransform(Vector2.One, frame.RectTransform, Anchor.TopRight), c.Salary.ToString(), textAlignment: Alignment.CenterRight);
{ }
foreach (CharacterInfo c in hireableCharacters)
{
var frame = c.CreateCharacterFrame(characterList.Content, c.Name + " (" + c.Job.Name + ")", c);
new GUITextBlock(new RectTransform(Vector2.One, frame.RectTransform, Anchor.TopRight), c.Salary.ToString(), textAlignment: Alignment.CenterRight);
} }
} }
characterList.UpdateScrollBarSize();
} }
characterList.UpdateScrollBarSize(); characterList.UpdateScrollBarSize();