예제 #1
0
    void ParseText()
    {
        _bytesLines = GetBytes();
        char[] chars = text.ToCharArray();
        if (textFile!=null)
            chars = textFile.text.ToCharArray();

        for (int p=0; p<_parsed.Count; p++)
            _parsed[p].Clean();
        _parsed.Clear();

        int dy = System.Convert.ToUInt16(GetDY());
        int yPosition = 0;
        OTSpriteAtlas atlas = (spriteContainer as OTSpriteAtlas);

        OTAtlasData data = atlas.atlasData[0];
        if (data!=null && data.frameSize.y>0 && lineHeight == 0)
            lineHeight = (int)data.frameSize.y;

        sizeChars = new int[]{};
        System.Array.Resize<int>(ref sizeChars, chars.Length);
        int ci = 0;

        OTTextAlinea alinea = new OTTextAlinea(yPosition, lineHeight);
        foreach(char c in chars) {

            if (c=='\r')
            {
                sizeChars[ci++] = 0;
                continue;
            }
            if (c=='\n')
            {
                alinea.End();
                _parsed.Add(alinea);
                yPosition -= dy;
                alinea = new OTTextAlinea(yPosition, lineHeight);
                sizeChars[ci++] = 0;
                continue;
            }
            data = atlas.DataByName(""+c);
            OTContainer.Frame frame = atlas.FrameByName(""+c);

            if (data==null || frame.name=="")
            {
                string charName = ((int)c).ToString();
                data = atlas.DataByName(charName);
                frame = atlas.FrameByName(charName);
            }

            if (data==null || frame.name=="")
            {
                data = atlas.DataByName(""+c+".png");
                frame = atlas.FrameByName(""+c+".png");
            }

            if (data==null || frame.name=="")
            {
                byte b = System.Text.Encoding.ASCII.GetBytes("?")[0];
                data = atlas.DataByName(""+b);
                frame = atlas.FrameByName(""+b);
            }

            if (data==null || frame.name=="")
            {
                data = atlas.DataByName("32");
                frame = atlas.FrameByName("32");
            }

            if (data!=null && data.frameSize.y>0 && lineHeight == 0)
                lineHeight = (int)data.frameSize.y;

            if (data!=null && frame.name == data.name)
            {
                if (data.name!="32")
                {
                    Vector3[] verts = new Vector3[] {
                        new Vector3(frame.offset.x, -frame.offset.y,0),
                        new Vector3(frame.offset.x+frame.size.x, -frame.offset.y,0),
                        new Vector3(frame.offset.x+frame.size.x, -frame.offset.y-frame.size.y,0),
                        new Vector3(frame.offset.x, -frame.offset.y - frame.size.y,0)
                    };
                    alinea.Add(((char)c).ToString(), data, verts, frame.uv);
                }
                else
                   alinea.NextWord(data);

                string dx = data.GetMeta("dx");
                int width = 0;
                if (dx=="")
                    width = (int)(data.offset.x + data.size.x);
                else
                    width = System.Convert.ToUInt16(dx);

                if (width == 0) width = 30;
                sizeChars[ci++] = width;

            }
        }
        alinea.End();
        _parsed.Add(alinea);

        if (wordWrap > 0)
            for (int p=0; p<_parsed.Count; p++)
            {
                _parsed[p].WordWrap(wordWrap, dy);
                for (int pp = p+1; pp<_parsed.Count; pp++)
                    _parsed[pp].lines[0].yPosition -= (dy * (_parsed[p].lines.Count-1));
            }
    }
예제 #2
0
    void ParseText()
    {
        _bytesLines = GetBytes();
        byte[] chars = System.Text.Encoding.ASCII.GetBytes(text);
        if (textFile!=null)
            chars = System.Text.Encoding.ASCII.GetBytes(textFile.text);

        for (int p=0; p<_parsed.Count; p++)
            _parsed[p].Clean();
        _parsed.Clear();

        int dy = System.Convert.ToUInt16(GetDY());
        int yPosition = 0;
        OTSpriteAtlas atlas = (spriteContainer as OTSpriteAtlas);
        OTTextAlinea alinea = new OTTextAlinea(yPosition);
        foreach(byte c in chars) {

            if (c=='\r') continue;
            if (c=='\n')
            {
                alinea.End();
                _parsed.Add(alinea);
                yPosition -= dy;
                alinea = new OTTextAlinea(yPosition);
                continue;
            }
            OTAtlasData data = atlas.DataByName(""+c);
            OTContainer.Frame frame = atlas.FrameByName(""+c);
            if (data==null || frame.name=="")
            {
                data = atlas.DataByName(""+c+".png");
                frame = atlas.FrameByName(""+c+".png");
            }

            if (data==null || frame.name=="")
            {
                char[] ch = System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { c });
                data = atlas.DataByName(ch[0].ToString());
                frame = atlas.FrameByName(ch[0].ToString());
            }
            if (data==null || frame.name=="")
            {
                char[] ch = System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { c });
                data = atlas.DataByName(ch[0].ToString()+".png");
                frame = atlas.FrameByName(ch[0].ToString()+".png");
            }

            if (data==null || frame.name=="")
            {
                byte b = System.Text.Encoding.ASCII.GetBytes("?")[0];
                data = atlas.DataByName(""+b);
                frame = atlas.FrameByName(""+b);
            }

            if (data==null || frame.name=="")
            {
                data = atlas.DataByName("32");
                frame = atlas.FrameByName("32");
            }

            if (data!=null && frame.name == data.name)
            {
                if (data.name!="32")
                {
                    Vector3[] verts = new Vector3[] {
                        new Vector3(frame.offset.x, -frame.offset.y,0),
                        new Vector3(frame.offset.x+frame.size.x, -frame.offset.y,0),
                        new Vector3(frame.offset.x+frame.size.x, -frame.offset.y-frame.size.y,0),
                        new Vector3(frame.offset.x, -frame.offset.y - frame.size.y,0)
                    };
                    alinea.Add(((char)c).ToString(), data, verts, frame.uv);
                }
                else
                  alinea.NextWord(data);
            }
        }
        alinea.End();
        _parsed.Add(alinea);

        if (wordWrap > 0)
            for (int p=0; p<_parsed.Count; p++)
            {
                _parsed[p].WordWrap(wordWrap, dy);
                for (int pp = p+1; pp<_parsed.Count; pp++)
                    _parsed[pp].lines[0].yPosition -= (dy * (_parsed[p].lines.Count-1));
            }
    }
예제 #3
0
    void ParseText()
    {
        _bytesLines = GetBytes();
        char[] chars = text.ToCharArray();
        if (textFile != null)
        {
            chars = textFile.text.ToCharArray();
        }

        for (int p = 0; p < _parsed.Count; p++)
        {
            _parsed[p].Clean();
        }
        _parsed.Clear();


        int           dy        = System.Convert.ToUInt16(GetDY());
        int           yPosition = 0;
        OTSpriteAtlas atlas     = (spriteContainer as OTSpriteAtlas);


        OTAtlasData data = atlas.atlasData[0];

        if (data != null && data.frameSize.y > 0 && lineHeight == 0)
        {
            lineHeight = (int)data.frameSize.y;
        }


        sizeChars = new int[] {};
        System.Array.Resize <int>(ref sizeChars, chars.Length);
        int ci = 0;

        OTTextAlinea alinea = new OTTextAlinea(yPosition, lineHeight);

        foreach (char c in chars)
        {
            if (c == '\r')
            {
                sizeChars[ci++] = 0;
                continue;
            }
            if (c == '\n')
            {
                alinea.End();
                _parsed.Add(alinea);
                yPosition      -= dy;
                alinea          = new OTTextAlinea(yPosition, lineHeight);
                sizeChars[ci++] = 0;
                continue;
            }
            data = atlas.DataByName("" + c);
            OTContainer.Frame frame = atlas.FrameByName("" + c);

            if (data == null || frame.name == "")
            {
                string charName = ((int)c).ToString();
                data  = atlas.DataByName(charName);
                frame = atlas.FrameByName(charName);
            }

            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("" + c + ".png");
                frame = atlas.FrameByName("" + c + ".png");
            }

            if (data == null || frame.name == "")
            {
                byte b = System.Text.Encoding.ASCII.GetBytes("?")[0];
                data  = atlas.DataByName("" + b);
                frame = atlas.FrameByName("" + b);
            }

            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("32");
                frame = atlas.FrameByName("32");
            }

            if (data != null && data.frameSize.y > 0 && lineHeight == 0)
            {
                lineHeight = (int)data.frameSize.y;
            }

            if (data != null && frame.name == data.name)
            {
                if (data.name != "32")
                {
                    Vector3[] verts = new Vector3[] {
                        new Vector3(frame.offset.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y - frame.size.y, 0),
                        new Vector3(frame.offset.x, -frame.offset.y - frame.size.y, 0)
                    };
                    alinea.Add(((char)c).ToString(), data, verts, frame.uv);
                }
                else
                {
                    alinea.NextWord(data);
                }


                string dx    = data.GetMeta("dx");
                int    width = 0;
                if (dx == "")
                {
                    width = (int)(data.offset.x + data.size.x);
                }
                else
                {
                    width = System.Convert.ToUInt16(dx);
                }

                if (width == 0)
                {
                    width = 30;
                }
                sizeChars[ci++] = width;
            }
        }
        alinea.End();
        _parsed.Add(alinea);

        if (wordWrap > 0)
        {
            for (int p = 0; p < _parsed.Count; p++)
            {
                _parsed[p].WordWrap(wordWrap, dy);
                for (int pp = p + 1; pp < _parsed.Count; pp++)
                {
                    _parsed[pp].lines[0].yPosition -= (dy * (_parsed[p].lines.Count - 1));
                }
            }
        }
    }
예제 #4
0
    void ParseText()
    {
        _bytesLines = GetBytes();
        byte[] chars = System.Text.Encoding.ASCII.GetBytes(text);
        if (textFile != null)
        {
            chars = System.Text.Encoding.ASCII.GetBytes(textFile.text);
        }

        for (int p = 0; p < _parsed.Count; p++)
        {
            _parsed[p].Clean();
        }
        _parsed.Clear();

        int           dy        = System.Convert.ToUInt16(GetDY());
        int           yPosition = 0;
        OTSpriteAtlas atlas     = (spriteContainer as OTSpriteAtlas);
        OTTextAlinea  alinea    = new OTTextAlinea(yPosition);

        foreach (byte c in chars)
        {
            if (c == '\r')
            {
                continue;
            }
            if (c == '\n')
            {
                alinea.End();
                _parsed.Add(alinea);
                yPosition -= dy;
                alinea     = new OTTextAlinea(yPosition);
                continue;
            }
            OTAtlasData       data  = atlas.DataByName("" + c);
            OTContainer.Frame frame = atlas.FrameByName("" + c);
            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("" + c + ".png");
                frame = atlas.FrameByName("" + c + ".png");
            }

            if (data == null || frame.name == "")
            {
                char[] ch = System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { c });
                data  = atlas.DataByName(ch[0].ToString());
                frame = atlas.FrameByName(ch[0].ToString());
            }
            if (data == null || frame.name == "")
            {
                char[] ch = System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { c });
                data  = atlas.DataByName(ch[0].ToString() + ".png");
                frame = atlas.FrameByName(ch[0].ToString() + ".png");
            }

            if (data == null || frame.name == "")
            {
                byte b = System.Text.Encoding.ASCII.GetBytes("?")[0];
                data  = atlas.DataByName("" + b);
                frame = atlas.FrameByName("" + b);
            }

            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("32");
                frame = atlas.FrameByName("32");
            }

            if (data != null && frame.name == data.name)
            {
                if (data.name != "32")
                {
                    Vector3[] verts = new Vector3[] {
                        new Vector3(frame.offset.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y - frame.size.y, 0),
                        new Vector3(frame.offset.x, -frame.offset.y - frame.size.y, 0)
                    };
                    alinea.Add(((char)c).ToString(), data, verts, frame.uv);
                }
                else
                {
                    alinea.NextWord(data);
                }
            }
        }
        alinea.End();
        _parsed.Add(alinea);

        if (wordWrap > 0)
        {
            for (int p = 0; p < _parsed.Count; p++)
            {
                _parsed[p].WordWrap(wordWrap, dy);
                for (int pp = p + 1; pp < _parsed.Count; pp++)
                {
                    _parsed[pp].lines[0].yPosition -= (dy * (_parsed[p].lines.Count - 1));
                }
            }
        }
    }