void GeneratorLines(float mMaxWidth)
    {
        UGUILine mNewLine = new UGUILine(0);

        mCurWidth = 0;
        while (mResultQueue.Count != 0)
        {
            UGUIRichItem item = mResultQueue.Dequeue();
            switch (item.ItemType)
            {
            case RichItemType.Text:
                mAddTextItemHandler = AddTextToLine;
                CreateTextItem(ref item, ref mNewLine);
                break;

            case RichItemType.Image:
                CreateImageItem(ref item, ref mNewLine);
                break;

            case RichItemType.Href:
                mAddTextItemHandler = AddHrefToLine;
                CreateTextItem(ref item, ref mNewLine);
                break;
            }
        }
        mResultLines.Enqueue(mNewLine);
    }
    void CreateTextItem(ref UGUIRichItem item, ref UGUILine mNewLine)
    {
        //如果没有溢出,则更新当前的宽度,向行中加入新元素
        if (mCurWidth + mRichStyle.GetStrWidth(item.Inner) <= mMaxWidth)
        {
            mCurWidth += mRichStyle.GetStrWidth(item.Inner);
            mNewLine.EnItemQueue(item);
        }
        //如果溢出,开始截断文字,溢出代表至少文字被分割成两个部分,如果被切割成三个部分,则第二部分一定是单独的一行
        else
        {
            mCutList.Clear();
            CutStr(item.Inner, mMaxWidth - mCurWidth, mMaxWidth);
            mAddTextItemHandler(item, ref mNewLine, 0);
            mResultLines.Enqueue(mNewLine);
            mCutList.RemoveAt(0);

            for (int i = 0; i < mCutList.Count; i++)
            {
                if (i != mCutList.Count - 1)
                {
                    UGUILine line = new UGUILine(0);
                    mAddTextItemHandler(item, ref line, i);
                    mResultLines.Enqueue(line);
                }
                else
                {
                    mCurWidth = mRichStyle.GetStrWidth(mCutList[i]);
                    mNewLine  = new UGUILine(0);
                    mAddTextItemHandler(item, ref mNewLine, i);
                }
            }
        }
    }
    public void generate(Queue <UGUILine> mResultLines, Text mTextContent)
    {
        this.mTextContent = mTextContent;
        mlineCount        = mResultLines.Count;
        mCurPos           = Vector2.zero;
        while (mResultLines.Count != 0)
        {
            mCurPos.x  = 0;
            mCurPos.y -= RichStyle.LineHeight;
            UGUILine tmp = mResultLines.Dequeue();
            string   m   = "";
            for (int i = 0; i < tmp.LineNum; i++)
            {
                m         += '\n';
                mCurPos.y -= RichStyle.LineHeight;
            }
            while (tmp.ItemCount != 0)
            {
                UGUIRichItem item = tmp.DeItemQueue();
                switch (item.ItemType)
                {
                case RichItemType.Image:
                    m += RichStyle.EmojiWidthStr;
                    CreateEmojiPrefab(item);
                    mCurPos.x += RichStyle.EmojiSpWidth;
                    break;

                case RichItemType.Text:
                    m         += item.Inner;
                    mCurPos.x += RichStyle.GetStrWidth(item.Inner);
                    break;

                case RichItemType.Href:
                    m += "<color=#FFFFFF00>" + item.Inner + "</color>";
                    CreateHrefPrefab(item);
                    mCurPos.x += RichStyle.GetStrWidth(item.Inner);
                    break;
                }
            }
            mTextContent.text += m;
            mTextContent.text += '\n';
        }
    }
    void CreateImageItem(ref UGUIRichItem item, ref UGUILine mNewLine)
    {
        UGUIRichItemImage imgItem = item as UGUIRichItemImage;

        if (mCurWidth + mRichStyle.EmojiSize.x <= mMaxWidth)
        {
            mCurWidth += mRichStyle.EmojiSpWidth;
            mNewLine.EnItemQueue(imgItem);
            mNewLine.LineNum = mRichStyle.EmojiHeightSpaceNum;
        }
        else
        {
            mResultLines.Enqueue(mNewLine);
            mNewLine = new UGUILine(0);
            mNewLine.EnItemQueue(imgItem);
            mNewLine.LineNum = mRichStyle.EmojiHeightSpaceNum;
            mCurWidth        = mRichStyle.EmojiSize.x;
        }
    }
 public txUGUILine()
 {
     mUGUILine = new UGUILine();
 }
 void AddTextToLine(UGUIRichItem item, ref UGUILine mNewLine, int index)
 {
     mNewLine.EnItemQueue(new UGUIRichItemText(
                              Color.black, mCutList[index]));
 }
 void AddHrefToLine(UGUIRichItem item, ref UGUILine mNewLine, int index)
 {
     mNewLine.EnItemQueue(new UGUIRichItemHref(
                              (item as UGUIRichItemHref).HrefNormalColor, mCutList[index], (item as UGUIRichItemHref).Url));
 }
Exemple #8
0
 public myUGUILine()
 {
     mUGUILine = new UGUILine();
 }