示例#1
0
        /// <summary>
        /// 更换使用语言,将配置文件中的语言反射到UI组件上
        /// </summary>
        /// <param name="section"></param>
        public void ChangeLanguage(INISection section)
        {
            if (reflections == null)
            {
                return;
            }
            var all = reflections.All;

            for (int i = 0; i < all.Length; i++)
            {
                HText txt = all[i].Value as HText;
                if (txt != null)
                {
                    var str = section.GetValue(all[i].name);
                    if (str != null)
                    {
                        if (str != "")
                        {
                            txt.Text = str.Replace("\\n", "\n");
                        }
                        else
                        {
                            txt.Text = str;
                        }
                    }
                }
                else
                {
                    InputBox box = all[i].Value as InputBox;
                    if (box != null)
                    {
                        var str = section.GetValue(all[i].name);
                        if (str != null)
                        {
                            if (str != "")
                            {
                                box.TipString = str.Replace("\\n", "\n");
                            }
                            else
                            {
                                box.TipString = str;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// 添加当前帧文本与字体的关联
 /// </summary>
 /// <param name="text"></param>
 /// <param name="font"></param>
 public static void AddContext(HText text, Font font)
 {
     for (int i = 0; i < top; i++)
     {
         if (TextBuffer[i].font == font)
         {
             TextBuffer[i].buf.Add(text);
             return;
         }
     }
     TextBuffer[top].font = font;
     if (TextBuffer[top].buf == null)
     {
         TextBuffer[top].buf = new List <HText>();
     }
     TextBuffer[top].buf.Add(text);
     TextBuffer[top].rebuild = false;
     top++;
 }
示例#3
0
        protected unsafe void SaveHText(FakeStruct fake, HText src)
        {
            HTextData *tar = (HTextData *)fake.ip;

            tar->text = fake.buffer.AddData(src.m_text);
            if (src._font != null)
            {
                tar->font = fake.buffer.AddData(src._font.name);
            }
            tar->pivot       = src.TextPivot;
            tar->m_hof       = src.m_hof;
            tar->m_vof       = src.m_vof;
            tar->anchor      = src.TextAnchor;
            tar->m_richText  = src.m_richText;
            tar->m_lineSpace = src.m_lineSpace;
            tar->m_fontSize  = src.m_fontSize;
            tar->m_align     = src.m_align;
            tar->m_fontStyle = src.m_fontStyle;
            tar->sizeFitter  = src.sizeFitter;
        }
示例#4
0
 static void RequestTexture(Font font, HText text)
 {
     if (text.m_richText)
     {
         StringEx str = text.stringEx;
         if (str.HaveLabel)
         {
             var info = str.lableInfos;
             if (info != null)
             {
                 for (int i = 0; i < info.Count; i++)
                 {
                     var son = new StringEx(info[i].Text, false);
                     font.RequestCharactersInTexture(son.noEmoji, info[i].fontSize, info[i].style);
                 }
                 return;
             }
         }
     }
     font.RequestCharactersInTexture(text.stringEx.noEmoji, text.m_fontSize, text.m_fontStyle);
 }
示例#5
0
        public static void ChangeText(HText text, EmojiString str)
        {
            verts.Clear();
            lines.Clear();
            chars.Clear();
            Target  = text;
            Content = str;
            text.GetGenerationSettings(ref text.m_sizeDelta, ref HText.settings);
            HText.settings.richText = false;
            var    g  = HText.Generator;
            string fs = Content.FilterString;

            if (contentType == ContentType.Password)
            {
                ContentHeight = g.GetPreferredHeight(new string('●', fs.Length), HText.settings);
            }
            else
            {
                ContentHeight = g.GetPreferredHeight(fs, HText.settings);
            }
            VisibleCount = g.characterCountVisible;
            if (g.lines.Count > 0)
            {
                float per = ContentHeight / g.lines.Count;
                ShowRow = (int)(text.m_sizeDelta.y / per);
            }
            else
            {
                ShowRow = (int)text.m_sizeDelta.y / text.FontSize;
            }
            StartY = ContentHeight * 0.5f - text.m_sizeDelta.y * 0.5f;
            verts.AddRange(g.verts);
            chars.AddRange(g.characters);
            LineInfo line = new LineInfo();

            if (g.lines.Count > 0)
            {
                var l = g.lines[0];
                for (int i = 1; i < g.lines.Count; i++)
                {
                    var n = g.lines[i];
                    line.startCharIdx = l.startCharIdx;
                    line.endIdx       = n.startCharIdx - 1;
                    line.topY         = l.topY;
                    line.endY         = n.topY;
                    l = n;
                    lines.Add(line);
                }
                l = g.lines[g.lines.Count - 1];
                line.startCharIdx = l.startCharIdx;
                line.endIdx       = chars.Count - 1;
                line.topY         = l.topY;
                line.endY         = g.lines[0].topY - ContentHeight - g.lines[g.lines.Count - 1].leading;
                lines.Add(line);
            }
            if (StartPress.Index > fs.Length)
            {
                SetPressIndex(fs.Length, ref StartPress);
                EndPress = StartPress;
            }
            SetShowStart(ShowStart);
        }
示例#6
0
文件: HText.cs 项目: pkwzsqsdly/HGUI
        /// <summary>
        /// 创建带有表情符的网格
        /// </summary>
        /// <param name="text"></param>
        protected static void CreateEmojiMesh(HText text)
        {
            if (text.TmpVerts.DataCount == 0)
            {
                text.vertInfo.DataCount  = 0;
                text.trisInfo.DataCount  = 0;
                text.trisInfo2.DataCount = 0;
                return;
            }
            bufferA.Clear();
            bufferB.Clear();
            var emojis = text.emojiString.emojis;
            var str    = text.emojiString.FilterString;
            var verts  = text.TmpVerts;
            int c      = verts.DataCount;

            text.tris = null;
            if (text.vertInfo.Size == 0)
            {
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            else
            if (text.vertInfo.Size <c | text.vertInfo.Size> c + 32)
            {
                text.vertInfo.Release();
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            var       emoji = text.emojiString;
            EmojiInfo info  = null;

            if (emoji.emojis.Count > 0)
            {
                info = emoji.emojis[0];
            }
            int     index = 0;
            int     e     = c / 4;
            int     ac    = 0;
            Color32 col   = Color.white;

            unsafe
            {
                HVertex *   hv  = text.vertInfo.Addr;
                TextVertex *src = verts.Addr;
                for (int i = 0; i < e; i++)
                {
                    int s  = i * 4;
                    int ss = ac;
                    int ti = src[s].Index;
                    for (int j = 0; j < 4; j++)
                    {
                        hv[ss].position = src[s].position;
                        hv[ss].color    = src[s].color;
                        hv[ss].uv       = src[s].uv;
                        hv[ss].uv4.x    = 1;
                        hv[ss].uv4.y    = 1;
                        hv[ss].picture  = 0;
                        s++;
                        ss++;
                    }
                    if (info != null)
                    {
                        if (ti > info.pos)
                        {
                            info = null;
                            for (int j = index; j < emoji.emojis.Count; j++)
                            {
                                if (emoji.emojis[j].pos >= ti)
                                {
                                    index = j;
                                    info  = emoji.emojis[j];
                                    break;
                                }
                            }
                        }
                        ss = ac;
                        if (info != null)
                        {
                            if (ti == info.pos)
                            {
                                AddTris(bufferB, ac);
                                hv[ss].uv      = info.uv[0];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[1];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[2];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[3];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                            }
                            else
                            {
                                AddTris(bufferA, ac);
                            }
                        }
                        else
                        {
                            AddTris(bufferA, ac);
                        }
                    }
                    else
                    {
                        AddTris(bufferA, ac);
                    }
                    ac += 4;
                }
            }
            text.vertInfo.DataCount = ac;
            ApplyTris(text);
        }
示例#7
0
        static void CreateEmojiMesh(HText text)
        {
            if (text.verts == null)
            {
                return;
            }
            bufferA.Clear();
            bufferB.Clear();
            var emojis = text.emojiString.emojis;
            var str    = text.emojiString.FilterString;
            var verts  = text.verts;
            int c      = verts.Length;

            if (c == 0)
            {
                text.vertices = null;
                text.tris     = null;
                return;
            }
            HVertex[] hv = new HVertex[c];

            int e = c / 4;

            for (int i = 0; i < c; i++)
            {
                hv[i].position = verts[i].position;
                hv[i].color    = verts[i].color;
                hv[i].uv       = verts[i].uv0;
                hv[i].uv4.x    = 1;
                hv[i].uv4.y    = 1;
            }
            if (emojis.Count > 0)
            {
                var   info = emojis[0];
                Color col  = Color.white;
                int   p    = 0;
                int   si   = 0;
                int   len  = str.Length;
                for (int i = 0; i < len; i++)
                {
                    bool yes = true;

                    for (int j = 0; j < key_noMesh.Length; j++)
                    {
                        if (key_noMesh[j] == str[i])
                        {
                            yes = false;
                            break;
                        }
                    }
                    if (yes)
                    {
                        if (i == info.pos)
                        {
                            int o = p * 4;
                            hv[o].uv      = info.uv[0];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[1];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[2];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[3];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            si++;
                            if (si < emojis.Count)
                            {
                                info = emojis[si];
                            }
                            int s = p * 4;
                            bufferB.Add(s);
                            bufferB.Add(s + 1);
                            bufferB.Add(s + 2);
                            bufferB.Add(s + 2);
                            bufferB.Add(s + 3);
                            bufferB.Add(s);
                        }
                        else
                        {
                            int s = p * 4;
                            bufferA.Add(s);
                            bufferA.Add(s + 1);
                            bufferA.Add(s + 2);
                            bufferA.Add(s + 2);
                            bufferA.Add(s + 3);
                            bufferA.Add(s);
                        }
                        p++;
                        if (p >= e)
                        {
                            break;
                        }
                    }
                }
                if (bufferB.Count > 0)
                {
                    if (text.subTris == null)
                    {
                        text.subTris = new int[2][];
                    }
                    text.subTris[0] = bufferA.ToArray();
                    text.subTris[1] = bufferB.ToArray();
                    text.tris       = null;
                }
                else
                {
                    text.tris    = bufferA.ToArray();
                    text.subTris = null;
                }
            }
            else
            {
                text.tris    = CreateTri(c);
                text.subTris = null;
            }
            text.vertices = hv;
        }