/// <summary> /// Adds text to the tab. For multi-line text strings, does text wrapping. For text length > 415 pixels, does text wrapping /// </summary> /// <param name="who">Person that spoke</param> /// <param name="text">Message that was spoken</param> /// <param name="icon">Icon to display next to the chat</param> /// <param name="col">Rendering color (enumerated value)</param> public void AddText(string who, string text, ChatType icon = ChatType.None, ChatColor col = ChatColor.Default) { const int LINE_LEN = 415; //special case: blank line, like in the news panel between news items if (string.IsNullOrWhiteSpace(who) && string.IsNullOrWhiteSpace(text)) { lock (ChatStringsLock) chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), " "); scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } return; } //don't do multi-line processing if we don't need to if (EOGame.Instance.DBGFont.MeasureString(text).X < LINE_LEN) { lock (ChatStringsLock) chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), text); scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } return; } string buffer = text, newLine = ""; string whoPadding = ""; //padding string for additional lines if it is a multi-line message if (!string.IsNullOrEmpty(who)) { while (EOGame.Instance.DBGFont.MeasureString(whoPadding).X < EOGame.Instance.DBGFont.MeasureString(who).X) { whoPadding += " "; } } List <string> chatStringsToAdd = new List <string>(); char[] whiteSpace = { ' ', '\t', '\n' }; string endOfLine = WhichTab == ChatTabs.None ? "" : "-"; string nextWord = ""; while (buffer.Length > 0) //keep going until the buffer is empty { //get the next word bool endOfWord = true, lineOverFlow = true; //these are negative logic booleans: will be set to false when flagged while (buffer.Length > 0 && (endOfWord = !whiteSpace.Contains(buffer[0])) && (lineOverFlow = EOGame.Instance.DBGFont.MeasureString(whoPadding + newLine + nextWord + endOfLine).X < LINE_LEN)) { nextWord += buffer[0]; buffer = buffer.Remove(0, 1); } //flip the bools so the program reads more logically endOfWord = !endOfWord; lineOverFlow = !lineOverFlow; if (endOfWord) { newLine += nextWord + buffer[0]; buffer = buffer.Remove(0, 1); nextWord = ""; } else if (lineOverFlow) { newLine += nextWord + endOfLine; chatStringsToAdd.Add(newLine); newLine = nextWord = ""; } else { newLine += nextWord; chatStringsToAdd.Add(newLine); } } for (int i = 0; i < chatStringsToAdd.Count; ++i) { lock (ChatStringsLock) { if (i == 0) { chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), chatStringsToAdd[0]); } else { chatStrings.Add(new ChatIndex(chatStrings.Count, ChatType.None, whoPadding), chatStringsToAdd[i]); } } } scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } }
/// <summary> /// Adds text to the tab. For multi-line text strings, does text wrapping. For text length > 415 pixels, does text wrapping /// </summary> /// <param name="who">Person that spoke</param> /// <param name="text">Message that was spoken</param> /// <param name="icon">Icon to display next to the chat</param> /// <param name="col">Rendering color (enumerated value)</param> public void AddText(string who, string text, ChatType icon = ChatType.None, ChatColor col = ChatColor.Default) { const int LINE_LEN = 415; //special case: blank line, like in the news panel between news items if (string.IsNullOrWhiteSpace(who) && string.IsNullOrWhiteSpace(text)) { lock (ChatStringsLock) chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), " "); scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } return; } string whoPadding = ""; //padding string for additional lines if it is a multi-line message if (!string.IsNullOrEmpty(who)) { while (EOGame.Instance.DBGFont.MeasureString(whoPadding).X < EOGame.Instance.DBGFont.MeasureString(who).X) { whoPadding += " "; } } TextSplitter ts = new TextSplitter(text, EOGame.Instance.DBGFont) { LineLength = LINE_LEN, LineEnd = WhichTab == ChatTabs.None ? "" : "-", LineStart = whoPadding }; //don't do multi-line processing if we don't need to if (!ts.NeedsProcessing) { lock (ChatStringsLock) chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), text); scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } return; } List <string> chatStringsToAdd = ts.SplitIntoLines(); for (int i = 0; i < chatStringsToAdd.Count; ++i) { lock (ChatStringsLock) { if (i == 0) { chatStrings.Add(new ChatIndex(chatStrings.Count, icon, who, col), chatStringsToAdd[0]); } else { chatStrings.Add(new ChatIndex(chatStrings.Count, ChatType.None, whoPadding), chatStringsToAdd[i]); } } } scrollBar.UpdateDimensions(chatStrings.Count); if (chatStrings.Count > 7 && WhichTab != ChatTabs.None) { scrollBar.ScrollToEnd(); } if (!Selected) { tabLabel.ForeColor = System.Drawing.Color.White; } if (!Visible) { Visible = true; } }