private bool WrapText(string text, float curPosX, out string finalText, out float length) { float num = curPosX; float num2 = 0f; int num3 = -1; for (int i = 0; i < text.get_Length(); i++) { char ch = text.get_Chars(i); float num4 = (float)CChatParser.GetCharacterWidth(ch, this.viewFontSize); num += num4; num2 += num4; if (num > (float)this.maxWidth) { num3 = i; break; } } length = num2; if (num3 != -1) { text = text.Insert(num3, "\\n"); } finalText = text; return(num3 != -1); }
public void Add(InBattleInputChat.InBatChatEntity ent) { if (ent == null) { return; } if (ent.type == InBattleInputChat.InBatChatEntity.EType.ParseAllColor) { List <string> list = Singleton <CChatController> .instance.ColorParser.Parse(this.m_view.lineWidth - 10, ent.rawText, this.m_view.fontSize); if (list.get_Count() == 1) { ent.line1 = list.get_Item(0); } else if (list.get_Count() >= 2) { ent.line1 = list.get_Item(0); ent.line2 = list.get_Item(1); } } else { bool flag = false; int num = 0; int num2 = 0; for (int i = 0; i < ent.rawText.get_Length(); i++) { int characterWidth = CChatParser.GetCharacterWidth(ent.rawText.get_Chars(i), this.m_view.fontSize); if (num + characterWidth > this.m_view.lineWidth - 10) { flag = true; ent.line1 = ent.rawText.Substring(num2, i); ent.line2 = ent.rawText.Substring(i); break; } num += characterWidth; } if (!flag) { ent.line1 = ent.rawText; } } if (this.m_view != null && this.m_view.IsAllTextLineShowed()) { this.m_chatEntityList.RemoveAt(0); } if (this.m_chatEntityList.Count == InBattleInputChat.CHAT_LINE_COUNT) { this.m_chatEntityList.RemoveAt(0); } this.m_chatEntityList.Add(ent); if (this.m_view != null) { this.m_view.Refresh(this.m_chatEntityList); } }
private string _parse(int lingWidth, string content, List <string> result, out int actualWidth) { int i = 0; bool flag = true; bool flag2 = false; bool flag3 = false; int num = 0; int num2 = 0; string text = string.Empty; while (i < content.get_Length()) { char c = content.get_Chars(i); if (c == '<') { flag2 = this.bHeader_Half_Match(i, content); if (flag2) { num2 = i; i += this.Header_Half_Str.get_Length(); flag = false; } if (flag3 && this.bColorTail_Match(i, content)) { i += this.tail_Str.get_Length(); flag3 = false; continue; } } else if (c == '>' && flag2) { flag = true; flag3 = true; text = content.Substring(num2, i - num2 + 1); i++; continue; } if (flag) { int characterWidth = CChatParser.GetCharacterWidth(c, this.m_viewFontSize); if (num + characterWidth > lingWidth) { if (flag3) { string text2 = content.Substring(0, i); text2 += "</color>"; actualWidth = num; result.Add(text2); string text3 = content.Substring(i); text3 = text + text3; int num3 = 0; string text4 = this._parse(lingWidth, text3, result, out num3); if (!string.IsNullOrEmpty(text4)) { result.Add(text4); } return(string.Empty); } actualWidth = num; string text5 = content.Substring(0, i); result.Add(text5); string content2 = content.Substring(i); int num4 = 0; string text6 = this._parse(lingWidth, content2, result, out num4); if (!string.IsNullOrEmpty(text6)) { result.Add(text6); } return(string.Empty); } else { num += characterWidth; } } i++; } actualWidth = num; return(content); }