using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
public class HrefAnalysis : TRichAnalysis<HrefAnalysis>
|
{
|
public static readonly Regex HrefRegex = new Regex(@"<a>(.*?)</a>", RegexOptions.Singleline);
|
|
private RichTextMgr.HrefInfo presentHrefInfo = null;
|
|
private static StringBuilder textBuilder = new StringBuilder();
|
|
static int insertIndex = 0;
|
|
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));
|
insertIndex = m_StringBuilder.Length - 3;
|
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;
|
}
|
if (SuitNameAnalysis.SuitName_Regex.IsMatch(split_event))
|
{
|
m_StringBuilder.Insert(insertIndex, 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 = ItemConfig.Get(_id);
|
if (cfg != null && cfg.Type == 113)
|
{
|
Dictionary<int, List<int>> userdatadic = null;
|
string userdata = array[1];
|
userdatadic = ConfigParse.Analysis(userdata);
|
int _itemColor = ItemLogicUtility.Instance.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":
|
{
|
var quality = -1;
|
int.TryParse(array[1],out quality);
|
if (quality != -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 = ItemConfig.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 "jointeam":
|
{
|
presentHrefInfo.mEvents.Add(RichTextEventEnum.JOINTEAM);
|
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;
|
case "auctionbidding":
|
{
|
presentHrefInfo.mEvents.Add(RichTextEventEnum.AuctionBidding);
|
presentHrefInfo.Add(split_value, array[1]);
|
}
|
break;
|
case "randomchat":
|
{
|
presentHrefInfo.mEvents.Add(RichTextEventEnum.RandomChat);
|
presentHrefInfo.Add(split_value, array[1]);
|
}
|
break;
|
case "taskfeedback":
|
{
|
presentHrefInfo.mEvents.Add(RichTextEventEnum.TaskFeedback);
|
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("#item#([\u4e00-\u9fa5a-zA-Z0-9\\|'_\\(\\)()\\. ::\\,\\[\\]a-zA-Z\"\\{\\}-]+?)#item#", RegexOptions.Singleline);
|
|
public bool ExcuteHrefEvent(string msg, int index = 0, bool fromAutoTask = false)
|
{
|
presentHrefInfo = new RichTextMgr.HrefInfo();
|
presentHrefInfo.fromAutoTask = fromAutoTask;
|
foreach (Match match in HrefRegex.Matches(msg))
|
{
|
AnalysisSplitEvent(match.Groups[1].Value);
|
}
|
return presentHrefInfo.Execute(index);
|
}
|
|
public bool ContainsKey(string _msg, string _key)
|
{
|
presentHrefInfo = new RichTextMgr.HrefInfo();
|
foreach (Match match in HrefRegex.Matches(_msg))
|
{
|
AnalysisSplitEvent(match.Groups[1].Value);
|
}
|
return presentHrefInfo.mSplits.ContainsKey(_key);
|
}
|
}
|