Example #1
0
        // #后面接5个字符,为动画的名称
        bool ParserCartoon(string text)
        {
            Cartoon cartoon    = null;
            int     currentPos = d_curPos;

            for (int i = max_cartoon_length; i >= 1; --i)
            {
                if (currentPos + i > text.Length)
                {
                    continue;
                }

                string name = text.Substring(currentPos, i);
                cartoon = Tools.GetCartoon(name);
                if (cartoon != null)
                {
                    currentPos += i;
                    break;
                }
            }

            if (cartoon == null)
            {
                return(false);
            }

            d_curPos = currentPos;
            save(false);

            CartoonNode cn = CreateNode <CartoonNode>();

            cn.cartoon = cartoon;
            cn.width   = cartoon.width;
            cn.height  = cartoon.height;
            cn.SetConfig(currentConfig);
            // 表情不变色
            cn.d_color = Color.white;
            d_nodeList.Add(cn);

            return(true);
        }
Example #2
0
        void RegTag()
        {
            TagFuns = new Dictionary <string, Action <string, string> >();

            Reg("sprite ", (string tag, TagAttributes att) =>
            {
                string name    = att.getValueAsString("n");
                ISprite sprite = Tools.GetSprite(name);
                if (sprite == null)
                {
                    // 没有查找到
                    Debug.LogErrorFormat("not find sprite:{0}!", name);
                    return;
                }

                Vector2 size = new Vector2(sprite.width, sprite.height);

                SpriteNode sn = CreateNode <SpriteNode>();
                sn.SetSprite(sprite);
                sn.SetConfig(currentConfig);

                SetSizeConfig(sn, att, size);
                SetDefaultConfig(sn, att);

                d_nodeList.Add(sn);
            });

            Reg("pos ", (string tag, TagAttributes att) =>
            {
                SetPosNode node = CreateNode <SetPosNode>();
                node.d_value    = att.getValueAsFloat("v", 0);
                node.type       = (TypePosition)att.getValueAsInteger("t", (int)(TypePosition.Absolute));
                d_nodeList.Add(node);
            });

            Reg("RectSprite ", (string tag, TagAttributes att) =>
            {
                ISprite s = Tools.GetSprite(att.getValueAsString("n")); // 名字
                if (s == null)
                {
                    // 没有查找到
                    Debug.LogErrorFormat("not find sprite:{0}!", att.getValueAsString("n"));
                    return;
                }

                RectSpriteNode sn = CreateNode <RectSpriteNode>();
                sn.SetConfig(currentConfig);
                //Rect rect = s.rect;
                sn.SetSprite(s);

                sn.rect.width  = att.getValueAsFloat("w", s.width);
                sn.rect.height = att.getValueAsFloat("h", s.height);

                switch (att.getValueAsInteger("t", 0))
                {
                case 1: sn.rect.height = sn.rect.width * s.height / s.width; break;

                case 2: sn.rect.width = sn.rect.height * s.width / s.height; break;
                }

                sn.rect.x = att.getValueAsFloat("px", 0f);
                sn.rect.y = att.getValueAsFloat("py", 0f);

                SetDefaultConfig(sn, att);

                d_nodeList.Add(sn);
            });

            Reg("hy ", (string tag, TagAttributes att) =>
            {
                HyperlinkNode node = CreateNode <HyperlinkNode>();
                node.SetConfig(currentConfig);
                node.d_text      = att.getValueAsString("t");
                node.d_link      = att.getValueAsString("l");
                node.d_fontSize  = att.getValueAsInteger("fs", node.d_fontSize);
                node.d_fontStyle = (FontStyle)att.getValueAsInteger("ft", (int)node.d_fontStyle);

                if (att.exists("fn"))
                {
                    node.d_font = Tools.GetFont(att.getValueAsString("fn"));
                }

                node.d_color   = ParserColorName(att.getValueAsString("fc"), 0, node.d_color);
                node.hoveColor = ParserColorName(att.getValueAsString("fhc"), 0, node.d_color);

                node.d_bUnderline = att.getValueAsBool("ul", node.d_bUnderline);
                node.d_bStrickout = att.getValueAsBool("so", node.d_bStrickout);
                d_nodeList.Add(node);
            });

            Reg("face ", (string tag, TagAttributes att) =>
            {
                string name = att.getValueAsString("n");
                Cartoon c   = Tools.GetCartoon(name);
                if (c == null)
                {
                    return;
                }

                CartoonNode cn = CreateNode <CartoonNode>();
                cn.cartoon     = c;
                cn.width       = c.width;
                cn.height      = c.height;

                cn.SetConfig(currentConfig);

                SetSizeConfig(cn, att, new Vector2(c.width, c.height));
                SetDefaultConfig(cn, att);

                d_nodeList.Add(cn);
            });

            TagFuns.Add("color=", (string tag, string param) =>
            {
                if (string.IsNullOrEmpty(param))
                {
                    return;
                }

                currentConfig.fontColor = ParserColorName(param, 0, currentConfig.fontColor);
            });

            TagFuns.Add("/color", (string tag, string param) =>
            {
                currentConfig.fontColor = startConfig.fontColor;
            });

            TagFuns.Add("b", (string tag, string param) =>
            {
                currentConfig.fontStyle |= FontStyle.Bold;
            });

            TagFuns.Add("/b", (string tag, string param) =>
            {
                currentConfig.fontStyle &= ~FontStyle.Bold;
            });

            TagFuns.Add("i", (string tag, string param) =>
            {
                currentConfig.fontStyle |= FontStyle.Italic;
            });

            TagFuns.Add("/i", (string tag, string param) =>
            {
                currentConfig.fontStyle &= ~FontStyle.Italic;
            });

            TagFuns.Add("size=", (string tag, string param) =>
            {
                currentConfig.fontSize = (int)Tools.stringToFloat(param, currentConfig.fontSize);
            });

            TagFuns.Add("/size", (string tag, string param) =>
            {
                currentConfig.fontSize = startConfig.fontSize;
            });

            // 描边效果
            Reg("ol ", (string tag, TagAttributes att) =>
            {
                currentConfig.effectType = EffectType.Outline;
                ParamEffectType(ref currentConfig, att);
            });

            TagFuns.Add("/ol", (string tag, string param) =>
            {
                currentConfig.effectType = EffectType.Null;
            });

            // 阴影
            Reg("so ", (string tag, TagAttributes att) =>
            {
                currentConfig.effectType = EffectType.Shadow;
                ParamEffectType(ref currentConfig, att);
            });

            TagFuns.Add("/so", (string tag, string param) =>
            {
                currentConfig.effectType = EffectType.Null;
            });

            Reg("offset ", (string tag, TagAttributes att) =>
            {
                float x = att.getValueAsFloat("x", 0f);
                float y = att.getValueAsFloat("y", 0f);

                if (x <= 0f && y <= 0f)
                {
                    return;
                }

                currentConfig.isOffset        = true;
                currentConfig.offsetRect.xMin = -x / 2f;
                currentConfig.offsetRect.xMax = x / 2f;

                currentConfig.offsetRect.yMin = -x / 2f;
                currentConfig.offsetRect.yMax = x / 2f;
            });

            // 外部结点
            Reg("external ", (tag, att) =>
            {
                if (getExternalNode == null)
                {
                    Debug.LogErrorFormat("external node but getExternalNode is null!");
                    return;
                }

                ExternalNode sn = CreateNode <ExternalNode>();
                sn.SetConfig(currentConfig);
                sn.Set(getExternalNode(att));

                d_nodeList.Add(sn);
            });
        }