Exemplo n.º 1
0
 protected void OnBreakSyntax(RichSyntaxData syntaxData)
 {
     if (m_richText)
     {
         m_richText.AddRichElement(new UGUIRichElementNewline());
     }
 }
Exemplo n.º 2
0
 protected void OnImageSyntax(RichSyntaxData syntaxData)
 {
     if (m_richText)
     {
         var image = syntaxData.GetParamString("name");
         m_richText.AddRichElement(CreateImageElement(image, m_url));
     }
 }
Exemplo n.º 3
0
 protected void OnAnimImageSyntax(RichSyntaxData syntaxData)
 {
     if (m_richText)
     {
         var imagePrefix = syntaxData.GetParamString("name");
         var imageCount  = syntaxData.GetParamUInt("count");
         var animFPS     = syntaxData.GetParamFloat("fps", 30);
         m_richText.AddRichElement(CreateAnimImageElement(imagePrefix, m_url, imageCount, animFPS));
     }
 }
Exemplo n.º 4
0
 protected void OnSizeSyntax(RichSyntaxData syntaxData)
 {
     if (m_richText)
     {
         var width = syntaxData.GetParamFloat("width");
         // TODO should not be called "height"
         var height = syntaxData.GetParamFloat("height");
         m_richText.SetTextWidth(width);
         m_richText.SetVerticalSpace(height);
     }
 }
Exemplo n.º 5
0
 protected override void OnSyntax(RichSyntaxData syntaxData)
 {
     if (syntaxData != null && syntaxData.IsValid())
     {
         var syntaxName = syntaxData.GetName();
         if (m_syntaxHandlers.ContainsKey(syntaxName))
         {
             m_syntaxHandlers[syntaxName](syntaxData);
         }
         else
         {
             Debug.LogError("[NGUIRichSyntaxParser]Can not handle syntax : " + syntaxName);
         }
     }
 }
Exemplo n.º 6
0
 protected void OnImageSyntax(RichSyntaxData syntaxData)
 {
     if (m_richText)
     {
         var image = syntaxData.GetParamString("name");
         Debug.Assert(image != null);
         if (syntaxData.HasParam("size"))
         {
             m_richText.AddRichElement(CreateImageSizeableElement(image, m_url, syntaxData.GetParamVector2("size")));
         }
         else
         {
             m_richText.AddRichElement(CreateImageElement(image, m_url));
         }
     }
 }
Exemplo n.º 7
0
 protected void OnURLEndSyntax(RichSyntaxData syntaxData)
 {
     m_url = null;
 }
Exemplo n.º 8
0
 protected void OnURLBeginSyntax(RichSyntaxData syntaxData)
 {
     m_url = syntaxData.GetParamString("value");
 }
Exemplo n.º 9
0
 protected void OnUnderlineEndSyntax(RichSyntaxData syntaxData)
 {
     m_isUnderline = false;
 }
Exemplo n.º 10
0
 protected void OnUnderlineBeginSyntax(RichSyntaxData syntaxData)
 {
     m_isUnderline = true;
 }
Exemplo n.º 11
0
 protected void OnStyleSyntax(RichSyntaxData syntaxData)
 {
     m_currentFontStyle = syntaxData.GetParamString("value");
 }
 protected virtual void OnSyntax(RichSyntaxData syntaxData)
 {
 }
        protected virtual int ParseSyntax(string config, int startIndex)
        {
            if (!IsSyntaxBeginChar(config[startIndex]))
            {
                Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxBeginChar() + " current : " + config[startIndex] + " at index : " + startIndex);
                // return -1 as error occur
                return(-1);
            }

            RichSyntaxData data = new RichSyntaxData();

            int nextIndex = startIndex + 1;

            while (nextIndex < config.Length)
            {
                // first parse syntax name
                var nameStartIndex = nextIndex;
                nextIndex = ParseIdentity(config, nextIndex);
                var name = config.Substring(nameStartIndex, nextIndex - nameStartIndex);
                if (string.IsNullOrEmpty(name))
                {
                    Debug.LogError("[RichSyntaxParser]Unexpected syntax name at index " + nextIndex);
                    // return -1 as error occur
                    return(-1);
                }
                data.SetName(name.Trim(GetSyntaxTrimChar()));

                // then parse syntax params
                while (nextIndex < config.Length)
                {
                    if (IsSyntaxEndChar(config[nextIndex]))
                    {
                        break;
                    }
                    else
                    {
                        if (!IsSyntaxSeparatorChar(config[nextIndex]))
                        {
                            Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxSeparatorChar() + " current : " + config[nextIndex] + " at index : " + nextIndex);
                            // return -1 as error occur
                            return(-1);
                        }
                        ++nextIndex;
                        var paramStartIndex = nextIndex;
                        nextIndex = ParseIdentity(config, nextIndex);
                        var paramName = config.Substring(paramStartIndex, nextIndex - paramStartIndex);
                        if (string.IsNullOrEmpty(paramName))
                        {
                            Debug.LogError("[RichSyntaxParser]Unexpected syntax param name at index " + paramStartIndex);
                            // return -1 as error occur
                            return(-1);
                        }
                        if (nextIndex >= config.Length || !IsSyntaxAssignChar(config[nextIndex]))
                        {
                            if (nextIndex < config.Length)
                            {
                                Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxAssignChar() + " current : " + config[nextIndex] + " at index : " + nextIndex);
                            }
                            else
                            {
                                Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxAssignChar() + " current is missing at the end of config string ...");
                            }
                            // return -1 as error occur
                            return(-1);
                        }
                        ++nextIndex;
                        paramStartIndex = nextIndex;
                        nextIndex       = ParseIdentity(config, nextIndex);
                        var paramValue = config.Substring(paramStartIndex, nextIndex - paramStartIndex);
                        if (string.IsNullOrEmpty(paramValue))
                        {
                            Debug.LogError("[RichSyntaxParser]Unexpected syntax param value at index " + paramStartIndex);
                            // return -1 as error occur
                            return(-1);
                        }
                        ;

                        data.AddParam(paramName.Trim(GetSyntaxTrimChar()), paramValue.Trim(GetSyntaxTrimChar()));
                    }
                }

                // check next index end char here
                if (nextIndex >= config.Length || !IsSyntaxEndChar(config[nextIndex]))
                {
                    if (nextIndex < config.Length)
                    {
                        Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxEndChar() + " current : " + config[nextIndex] + " at index : " + nextIndex);
                    }
                    else
                    {
                        Debug.LogError("[RichSyntaxParser]Unexpected syntax char expected : " + GetSyntaxEndChar() + " current is missing at the end of the config string ...");
                    }
                    // return -1 as error occur
                    return(-1);
                }
                else
                {
                    ++nextIndex;
                    break;
                }
            }

            if (data.IsValid())
            {
                OnSyntax(data);
            }

            return(nextIndex);
        }