using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using TableConfig; using UnityEngine; public class HrefAnalysis : TRichAnalysis { public static readonly Regex HrefRegex = new Regex(@"(.*?)", RegexOptions.Singleline); private RichTextMgr.HrefInfo presentHrefInfo = null; private static StringBuilder textBuilder = new StringBuilder(); public override string Analysis(string val, bool IsRich) { if (!HrefRegex.IsMatch(val)) { return val; } int index = 0; m_StringBuilder.Length = 0; foreach (Match match in HrefRegex.Matches(val)) { textBuilder.Length = 0; RichTextMgr.HrefInfo hrefInfo = new RichTextMgr.HrefInfo(); presentHrefInfo = hrefInfo; if (RichTextMgr.Inst.presentRichText != null) { presentHrefInfo.unlineColor = UIHelper.GetUIColor(TextColType.Green, RichTextMgr.Inst.presentRichText.colorType == RichText.ColorType.Bright); } m_StringBuilder.Append(val.Substring(index, match.Groups[1].Index - index)); AnalysisSplitEvent(match.Groups[1].Value); m_StringBuilder.Append(textBuilder); AnalysisImg(textBuilder.ToString(), m_StringBuilder.Length); index = match.Groups[1].Index + match.Groups[1].Length; if (RichTextMgr.Inst.GetHrefList() != null) { RichTextMgr.Inst.GetHrefList().Add(hrefInfo); } else { hrefInfo = null; } } m_StringBuilder.Append(val.Substring(index, val.Length - index)); presentHrefInfo = null; return m_StringBuilder.ToString(); } public override string CalculateTextIndex(string val, int index) { if (!HrefRegex.IsMatch(val)) { return val; } MatchCollection matchArray = HrefRegex.Matches(val); m_StringBuilder.Length = 0; int length = 0; for (int i = 0; i < matchArray.Count; i++) { Match match = matchArray[i]; m_StringBuilder.Append(val.Substring(length, match.Index - length)); length = match.Index + match.Length; if (RichTextMgr.Inst.GetHrefList() != null) { RichTextMgr.HrefInfo hrefInfo = RichTextMgr.Inst.GetHrefList()[i]; hrefInfo.start = m_StringBuilder.Length * 4; hrefInfo.end = (m_StringBuilder.Length + match.Groups[1].Length - 1) * 4 + 3; //hrefInfo.mPosDic.Add(m_StringBuilder.Length * 4, (m_StringBuilder.Length + match.Groups[1].Length - 1) * 4 + 3); } m_StringBuilder.Append(match.Groups[1].Value); } m_StringBuilder.Append(val.Substring(length, val.Length - length)); return m_StringBuilder.ToString(); } private void AnalysisSplitEvent(string val) { string[] array = GetSplitEvent(val); if (array.Length > 0) { foreach (var split_event in array) { if (ImgAnalysis.Unity_Img_Regex.IsMatch(split_event)) { //textBuilder.Append(split_event); continue; } AnalysisSplitData(split_event); } } } private void AnalysisSplitData(string val) { string[] array = GetSplitData(val); if (array.Length > 0) { foreach (var split_data in array) { AnalysisSplitValue(split_data); } } } private void AnalysisSplitValue(string val) { string[] array = GetSplitValue(val); if (array.Length == 2) { string split_value = array[0].ToLower(); switch (split_value) { case "movenpc": { presentHrefInfo.mEvents.Add(RichTextEventEnum.MOVENPC); presentHrefInfo.Add(split_value, array[1]); } break; case "movepos": { presentHrefInfo.mEvents.Add(RichTextEventEnum.MOVEPOS); } break; case "flynpc": { presentHrefInfo.mEvents.Add(RichTextEventEnum.FLYNPC); presentHrefInfo.Add(split_value, array[1]); } break; case "applyfairy": { presentHrefInfo.mEvents.Add(RichTextEventEnum.APPLYFAIRY); presentHrefInfo.Add(split_value, array[1]); } break; case "ul": { int ul = 1; int.TryParse(array[1], out ul); presentHrefInfo.unline = ul > 0; } break; case "userdata": { if (presentHrefInfo.mSplits.ContainsKey("showitem")) { var _id = 0; if (int.TryParse(presentHrefInfo.mSplits["showitem"], out _id)) { ItemConfig cfg = Config.Instance.Get(_id); if (cfg != null && cfg.Type == 111) { Dictionary> userdatadic = null; string userdata = array[1]; userdatadic = ConfigParse.Analysis(userdata); int _itemColor = ModelCenter.Instance.GetModel().GetItemQuality(cfg.ID, userdatadic); var text = RichTextMgr.Inst.presentRichText; int colorType = 0; if (text != null) { colorType = text.colorType == RichText.ColorType.Dark ? 0 : 1; } presentHrefInfo.unlineColor = UIHelper.GetUIColor(_itemColor, colorType == 1); } } } presentHrefInfo.Add(split_value, array[1]); } break; case "color": { int quality = int.Parse(array[1]); var text = RichTextMgr.Inst.presentRichText; int colorType = 0; if (text != null) { colorType = text.colorType == RichText.ColorType.Dark ? 0 : 1; } presentHrefInfo.unlineColor = UIHelper.GetUIColor(quality, colorType == 1); } break; case "showitem": { presentHrefInfo.mEvents.Add(RichTextEventEnum.SHOWITEM); presentHrefInfo.Add(split_value, array[1]); var _itemId = int.Parse(array[1]); var _itemCfg = Config.Instance.Get(_itemId); var text = RichTextMgr.Inst.presentRichText; int colorType = 0; if (text != null) { colorType = text.colorType == RichText.ColorType.Dark ? 0 : 1; } presentHrefInfo.unlineColor = UIHelper.GetUIColor(_itemCfg.ItemColor, colorType == 1); } break; case "enterfb": { presentHrefInfo.mEvents.Add(RichTextEventEnum.ENTERFB); presentHrefInfo.Add(split_value, array[1]); } break; case "invite": { presentHrefInfo.mEvents.Add(RichTextEventEnum.INVITE); presentHrefInfo.Add(split_value, array[1]); } break; case "openui": { presentHrefInfo.mEvents.Add(RichTextEventEnum.OPENUI); presentHrefInfo.Add(split_value, array[1]); } break; case "showplayer": { presentHrefInfo.mEvents.Add(RichTextEventEnum.SHOWPLAYER); presentHrefInfo.Add(split_value, array[1]); } break; case "findplayer": { presentHrefInfo.mEvents.Add(RichTextEventEnum.FindPlayer); } break; case "tip": { presentHrefInfo.mEvents.Add(RichTextEventEnum.TIP); presentHrefInfo.Add(split_value, array[1]); } break; case "getway": { presentHrefInfo.mEvents.Add(RichTextEventEnum.GetWay); presentHrefInfo.Add(split_value, array[1]); } break; default: { presentHrefInfo.Add(split_value, array[1]); } break; } } else { textBuilder.Append(array[0]); } } private void AnalysisImg(string val, int length) { if (!ImgAnalysis.Unity_Img_Regex.IsMatch(val)) { return; } foreach (Match match in ImgAnalysis.Unity_Img_Regex.Matches(val)) { int index = int.Parse(match.Groups[2].Value); if (RichTextMgr.Inst.GetImgList() != null) { RichTextMgr.Inst.GetImgList()[index].href = presentHrefInfo; } m_StringBuilder.Append(match.Value); } } public static Regex EquipRegex = new Regex(@"\[([\u4e00-\u9fa5a-zA-Z0-9\|'_\(\)()\. ::]+?)\]", RegexOptions.Singleline); public static Regex EquipDetailRegex = new Regex("\\*([\u4e00-\u9fa5a-zA-Z0-9\\|'_\\(\\)()\\. ::\\,\\[\\]a-zA-Z\"\\{\\}]+?)\\*", RegexOptions.Singleline); public bool ExcuteHrefEvent(string msg, int index = 0) { presentHrefInfo = new RichTextMgr.HrefInfo(); AnalysisSplitEvent(msg); return presentHrefInfo.Execute(index); } public bool ContainsKey(string _msg, string _key) { presentHrefInfo = new RichTextMgr.HrefInfo(); AnalysisSplitEvent(_msg); return presentHrefInfo.mSplits.ContainsKey(_key); } }