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 static bool ParseActionBtnContent(string value, out string btnName, out string desc, out enUIEventID uiEventID) { string text = "\\[(\\d+)\\|(\\d+)\\|([a-z0-9]{32})\\]"; MatchCollection matchCollection = null; btnName = null; uiEventID = enUIEventID.None; desc = null; if (!string.IsNullOrEmpty(value)) { try { matchCollection = Regex.Matches(value, text); } catch (Exception) { return(false); } } if (matchCollection != null && matchCollection.get_Count() > 0) { Match match = matchCollection.get_Item(0); if (match.get_Groups().get_Count() == 4) { uiEventID = (enUIEventID)Convert.ToInt32(match.get_Groups().get_Item(2).ToString()); CChatParser.GetActionBtnNameAndDesc(uiEventID, out btnName, out desc); return(true); } } return(false); }
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 void CreateButton(string value) { string text = string.Empty; string text2 = string.Empty; string text3 = null; string text4 = null; enUIEventID enUIEventID = enUIEventID.None; if (!CChatParser.ParseActionBtnContent(value, out text3, out text4, out enUIEventID)) { return; } string empty = string.Empty; float num = 0f; bool flag = this.WrapText(text4, (float)this.mPositionX, out empty, out num); if (flag) { int num2 = empty.IndexOf("\\n"); text = empty.Substring(0, num2); text2 = empty.Substring(num2 + 2); if (!string.IsNullOrEmpty(text)) { this.CreateText(text); } if (this.bProc_ChatEntry) { return; } this.mPositionX = this.mOriginalPositionX; this.mPositionY -= CChatParser.lineHeight; if (!string.IsNullOrEmpty(text2)) { this.CreateText(text2); } num += 2.5f; if (this.curEntNode == null) { return; } this.curEntNode.TextObjList.Add(new CTextImageNode(value, CChatParser.InfoType.Button, num, 0f, (float)this.mPositionX, (float)this.mPositionY)); } else { if (!string.IsNullOrEmpty(empty)) { this.CreateText(empty); } num += 2.5f; if (this.curEntNode == null) { return; } this.curEntNode.TextObjList.Add(new CTextImageNode(value, CChatParser.InfoType.Button, num, 0f, (float)this.mPositionX, (float)this.mPositionY)); if ((float)this.mPositionY < this.curEntNode.final_height) { this.curEntNode.final_height = (float)this.mPositionY; } if (this.curEntNode.final_height < -(float)CChatParser.lineHeight * 2f) { this.curEntNode.numLine = 3u; } else if (this.curEntNode.final_height < -(float)CChatParser.lineHeight) { this.curEntNode.numLine = 2u; } else { this.curEntNode.numLine = 1u; } this.mPositionX += (int)num; if ((float)this.mPositionX > this.curEntNode.final_width) { this.curEntNode.final_width = (float)this.mPositionX; } } }
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); }