Пример #1
0
        /// <summary>
        /// 属性等级解析
        /// </summary>
        /// <param name="reg"></param>
        /// <param name="strText"></param>
        /// <returns></returns>
        public string PropertyLevel_Callback(RegexInfo reg, string strText)
        {
            // 取得属性值
            string          strPropPattern = @"\[(PA|PD|PASD|CRC|MA|MD|COOL|SD|PAF)\s*=\s*(\d*)([+*\-/]?)(\d*)\]";
            Regex           re             = new Regex(strPropPattern);
            MatchCollection matchs         = re.Matches(strText);

            if (matchs.Count == 0)
            {
                return(strText);
            }

            float  fPropValue = 0;
            string strKey     = "";

            do
            {
                Match node = matchs[0];
                if (node.Groups.Count == 0)
                {
                    break;
                }
                strKey = node.Groups[1].ToString();// 正则键值
                if (!m_nodeList.ContainsKey(strKey))
                {
                    break;
                }
                float fPropVal = getPropertyValue(strKey);

                string strOldValue = node.Groups[2].ToString();// 这个值为20或20*5之类的形式
                float  fOldValue   = 1.0f;
                float.TryParse(strOldValue, out fOldValue);
                fPropValue = fPropVal * fOldValue / 100.0f;
            } while (false);
            if (String.IsNullOrEmpty(strKey))
            {
                return(strText);
            }

            // 取得配置区间值
            if (EntityFactory.MainHeroView == null)
            {
                return(strText);
            }

            int nHeroID = EntityFactory.MainHeroView.Property.GetNumProp(ENTITY_PROPERTY.PROPERTY_VOCATION);

            int nIndex = m_dicPropertyLevel[strKey];

            SSchemePropertyPanel propConfig = PropertyPanelConfig.Instance.GetPropertyPanelConfigList(nHeroID, fPropValue, nIndex);

            if (propConfig == null)
            {
                //Debug.LogError(String.Format("propConfig == null,{0},{1}, {2}", nHeroID, fValue, nPropIndex));
                return(strText);
            }

            if (nIndex <= 0)
            {
                return(strText);
            }

            // 取得匹配值
            MatchCollection matchLevel = reg.r.Matches(strText);

            if (matchLevel.Count == 0)
            {
                return(strText);
            }

            string strNewText = String.Format("<color='#{0}'>({1})</color>", propConfig.strColor, propConfig.strDesc);

            Match  levelNode   = matchLevel[0];
            string strOldText  = levelNode.Groups[0].ToString();
            int    nStartPos   = levelNode.Index;
            int    nTextLength = levelNode.Length;

            StringBuilder builder = new StringBuilder(strText);

            // 替换
            builder.Replace(strOldText, strNewText, nStartPos, nTextLength);

            return(builder.ToString());
        }
Пример #2
0
        /// <summary>
        /// 属性格式化
        /// </summary>
        /// <param name="reg"></param>
        /// <param name="strText"></param>
        /// <returns></returns>
        public string Property_Callbak(RegexInfo reg, string strText)
        {
            MatchCollection matchs = reg.r.Matches(strText);

            // 没有匹配的直接返回原值
            if (matchs.Count == 0)
            {
                return(strText);
            }

            // 先将正则出来的结果进行帅选出来进行细化定位(KEY=开始位置)
            List <Match> result = new List <Match>();

            foreach (Match m in matchs)
            {
                result.Add(m);
            }
            // 将位置将序排下顺序,后面的优先处理
            List <Match> sortList = result.OrderByDescending(p => p.Index).ToList();

            StringBuilder builder = new StringBuilder(strText);

            // 将结果中的项目通过指定的函数进行格式化并替换值
            foreach (Match node in sortList)
            {
                if (node.Groups.Count == 0)
                {
                    continue;
                }

                // 获取到键值
                string strKey = node.Groups[1].ToString();
                // 对象容器中没有注册此键值
                if (!m_nodeList.ContainsKey(strKey))
                {
                    continue;
                }

                // 正则出来字符串
                string strOldText = node.Groups[0].ToString();

                PropNode prop       = m_nodeList[strKey];
                string   strNewText = "";
                // 处理值
                if (prop.handler != null)
                {
                    strNewText = prop.handler(node);
                }
                else
                {
                    strNewText = FormatPropertyValue(node, prop);
                }

                // 有变化将进行替换
                if (!strNewText.Equals(strOldText))
                {
                    // 本正则出来字符串在源字符串的起始位置
                    int nStartPos = node.Index;
                    // 正则出来字符串的长度
                    int nTextLength = node.Length;

                    // 替换
                    builder.Replace(strOldText, strNewText, nStartPos, nTextLength);
                }
            }

            return(builder.ToString());
        }
Пример #3
0
        /// <summary>
        /// 格式化字符串为HTML
        /// </summary>
        /// <param name="strText">源字符串</param>
        /// <returns>被格式化后的字符串</returns>
        public static void toHtml(ref string strText, UBB_FORMAT_TYPE type = UBB_FORMAT_TYPE.UGUI)
        {
            if (string.IsNullOrEmpty(strText))
            {
                return;
            }

            // 格式化最前面这个字符,有些脚本中带了这个
            strText = strText.TrimStart(new char[] { '$' });

            //<br>和$这两个比较特殊,不能全用[来判断
            bool bStrTextHasUBB = strText.Contains("[") || strText.Contains("<br>");

            if (bStrTextHasUBB == false)
            {
                return;
            }

            Dictionary <string, RegexInfo> dict = (type == UBB_FORMAT_TYPE.SCANFORM ? ris : ris_ugui);

            foreach (KeyValuePair <string, RegexInfo> keypair in dict)
            {
                int       nLastPatternIndex = 0;
                string    pattern           = keypair.Key;
                RegexInfo ri = keypair.Value;
                if (ri.replace.Length > 0)
                {
                    strText = ri.r.Replace(strText, ri.replace);
                }
                else if (ri.del != null)
                {
                    if (ri.isMatch)
                    {
                        strText = ri.del(ri, strText);
                    }
                    else
                    {
                        // TODO 这个还是耗性能
                        int nLoopTime = 0;
                        while (true)
                        {
                            if (nLoopTime > 10)     // 以防万一还是判断下
                            {
                                Debug.Log("the loop is forever");
                                break;
                            }

                            string sPropertyName = pattern.Substring(1, 3); // 暂时用这么捞逼的方法
                            nLastPatternIndex = strText.IndexOf(sPropertyName, nLastPatternIndex);
                            if (nLastPatternIndex == -1)
                            {
                                nLastPatternIndex = 0;
                                break;
                            }

                            string ret = ri.del(ri, strText);
                            if (ret != null)
                            {
                                strText = ri.r.Replace(strText, ret, 1, nLastPatternIndex);
                            }
                            nLastPatternIndex++;
                            nLoopTime++;
                        }
                    }
                }
            }
        }