You can use a class 'ChatMessage' that contains a property 'MessageType'. It can check what type it is and draw itself in the right color. Something like this (unoptimized):
public class ChatMessage
{
public Dictionary<string, Color> TypeColors
{
get;
protected set;
}
private string MessageType;
private string Text;
private string UserName;
private SpriteFont Font;
public ChatMessage(string userName, string text, string type, SpriteFont font)// Gets all the data necessary
{
MessageType = type;
Text = text;
UserName = userName;
Font = font;
InitTypeColors();
}
protected void InitTypeColors()// Set these to what ever you want and add more
{
TypeColors = new Dictionary<string, Color>();
TypeColors["normal"] = Color.Yellow;
TypeColors["message"] = Color.White;
TypeColors["system"] = Color.Red;
}
public void Draw (SpriteBatch batch, Vector2 position)
{
batch.DrawString(Font, UserName, position, TypeColors[MessageType]);// Draws the user name in one color
batch.DrawString(Font, Text, new Vector2(position.X + Font.MeasureString(UserName).X + 15, position.Y), TypeColors["message"]);// then the message, 15 pixels to the right, in the color associated with that type
}
}
Then in your game use a ListList<ChatMessage>
for your chatList.
In your Game Draw method replace this:
spriteBatch.DrawString(font, chatList[i], new Vector2(40, arr1[i]), Color.Yellow);
with this :
chatList[i].Draw(spriteBatch, new Vector2(40, arr1[i]));
That should work, but you may want to optimize the code a bit.