UpdateNGUIText() public method

Update NGUIText.current with all the properties from this label.
public UpdateNGUIText ( ) : void
return void
Ejemplo n.º 1
0
 protected void Rebuild()
 {
     if (isValid)
     {
         textLabel.UpdateNGUIText();
         NGUIText.rectHeight = 1000000;
         mTotalLines         = 0;
         for (int i = 0; i < mParagraphs.size; i++)
         {
             Paragraph paragraph = mParagraphs.buffer[i];
             NGUIText.WrapText(paragraph.text, out string finalText);
             paragraph.lines = finalText.Split('\n');
             mTotalLines    += paragraph.lines.Length;
         }
         mTotalLines = 0;
         int j = 0;
         for (int size = mParagraphs.size; j < size; j++)
         {
             mTotalLines += mParagraphs.buffer[j].lines.Length;
         }
         if (scrollBar != null)
         {
             UIScrollBar uIScrollBar = scrollBar as UIScrollBar;
             if (uIScrollBar != null)
             {
                 uIScrollBar.barSize = ((mTotalLines != 0) ? (1f - (float)scrollHeight / (float)mTotalLines) : 1f);
             }
         }
         UpdateVisibleText();
     }
 }
Ejemplo n.º 2
0
		/// <summary>
		/// Returns a line composed of the words in the stack that would
		/// fit into the label.	
		/// The line is returned when the next word wouldn't fit or the last poped
		/// word was a newline.
		/// 
		/// The stack is requiered to have all characters and all whitespaces in
		/// separate elements. The labels text must be blank.
		/// </summary>
		public static string getLine( Stack<string> words, UILabel targetLabel, bool doLinePadding ){
			string line = "";
			string currWord = "";
			Vector2 labelSize = new Vector2( targetLabel.width, targetLabel.height );
			Vector2 textSize  = new Vector2();
			targetLabel.UpdateNGUIText();
			
			//Add next word to the current line as long as the line would fit in the label
			//and not cause a newline.
			while( words.Count > 0 ){
				currWord = words.Peek();
				textSize = NGUIText.CalculatePrintedSize(line + currWord);
				
				if( textSize.y > labelSize.y ){	
					//Check if the current word is a whitespace. If it is, remove it
					if( currWord.Trim() == string.Empty ){
						words.Pop();
						line.Trim();
					}
					textSize = NGUIText.CalculatePrintedSize(line + " ");
					while( textSize.y < labelSize.y && doLinePadding ){
						line += " ";
						textSize = NGUIText.CalculatePrintedSize(line + " ");
					}
					return line;
				}
				line += words.Pop();
			}
			
			return line;
		}			
Ejemplo n.º 3
0
    //打字机完成后 调用此函数
    public void ShowNextIcon()
    {
        te.enabled = false;
        if (string.IsNullOrEmpty(dialogLabel.text) && string.IsNullOrEmpty(nameLabel.text))
        {
            return;
        }
        DataManager.GetInstance().UnblockRightClick();
        DataManager.GetInstance().UnblockWheel();
        typewriting = false;
        //TODO 定位
        List <Vector3> a = new List <Vector3>();

        dialogLabel.UpdateNGUIText();
        NGUIText.PrintExactCharacterPositions(dialogLabel.text, a, new List <int>());
        Vector3 vec = a[a.Count() - 1];

        nextIcon.GetComponent <TweenPosition>().from = new Vector3(vec.x + 12, vec.y);
        nextIcon.GetComponent <TweenPosition>().to   = new Vector3(vec.x + 12, vec.y - 2);
        nextIcon.transform.localPosition             = new Vector3(vec.x + 12, vec.y);
        nextIcon.SetActive(true);
        if (currentPiece != null)
        {
            currentPiece.finish = true;
        }
    }
Ejemplo n.º 4
0
    public static Vector2 compute(UILabel label)
    {
        Vector2 result = Vector2.zero;
        string  text   = label.processedText;

        if (string.IsNullOrEmpty(text))
        {
            return(result);
        }
        label.UpdateNGUIText();
        int index = label.text.Length - 1;

        NGUIText.PrintCharacterPositions(text, UILabel.mTempVerts, UILabel.mTempIndices);
        if (UILabel.mTempVerts.size > 0)
        {
            label.ApplyOffset(UILabel.mTempVerts, 0);
            for (int i = 0; i < UILabel.mTempIndices.size; i++)
            {
                if (UILabel.mTempIndices[i] == index)
                {
                    result = UILabel.mTempVerts[i];
                    break;
                }
            }
            UILabel.mTempVerts.Clear();
            UILabel.mTempIndices.Clear();
        }
        NGUIText.bitmapFont  = null;
        NGUIText.dynamicFont = null;
        return(result);
    }
Ejemplo n.º 5
0
    private static float computeFloat(UILabel label)
    {
        float  result = 0, preData = 0;
        string text = label.processedText;

        if (string.IsNullOrEmpty(text))
        {
            return(result);
        }
        label.UpdateNGUIText();
        NGUIText.PrintCharacterPositions(text, UILabel.mTempVerts, UILabel.mTempIndices);
        if (UILabel.mTempVerts.size > 0)
        {
            label.ApplyOffset(UILabel.mTempVerts, 0);
            for (int i = 0; i < UILabel.mTempIndices.size; i += 2)
            {
                float x = UILabel.mTempVerts[i].x;
                if (x > preData)
                {
                    result += x - preData;
                }
                else
                {
                    result += label.fontSize;
                }
                preData = x;
            }
            UILabel.mTempVerts.Clear();
            UILabel.mTempIndices.Clear();
        }
        NGUIText.bitmapFont  = null;
        NGUIText.dynamicFont = null;
        return(result);
    }
Ejemplo n.º 6
0
    public static void Show(Vector3 position, String message)
    {
        if (QuadMistGetCardDialog.main.dialog != (UnityEngine.Object)null)
        {
            Singleton <DialogManager> .Instance.ReleaseDialogToPool(QuadMistGetCardDialog.main.dialog);

            QuadMistGetCardDialog.main.dialog = (Dialog)null;
        }
        UILabel dialogLabel = Singleton <DialogManager> .Instance.GetDialogLabel();

        Int32 width = dialogLabel.width;

        dialogLabel.width = Convert.ToInt32(UIManager.UIContentSize.x);
        dialogLabel.ProcessText();
        dialogLabel.UpdateNGUIText();
        Int32 num = Convert.ToInt32((NGUIText.CalculatePrintedSize2(message).x + Dialog.DialogPhraseXPadding * 2f) / UIManager.ResourceXMultipier) + 1;

        dialogLabel.width = width;
        QuadMistGetCardDialog.main.dialog = Singleton <DialogManager> .Instance.AttachDialog(String.Concat(new Object[]
        {
            "[STRT=",
            num,
            ",1][CENT][NANI][IMME]",
            message,
            "[TIME=-1]"
        }), 0, 1, Dialog.TailPosition.AutoPosition, Dialog.WindowStyle.WindowStylePlain, new Vector2(10000f, 10000f), Dialog.CaptionType.None);

        QuadMistGetCardDialog.main.dialog.transform.localPosition = new Vector3(0f, -220f);
    }
Ejemplo n.º 7
0
    public void calculateSpaceSize()
    {
        string oldStr = label.text;

        mTempVerts.Clear();
        mTempIndices.Clear();

        label.text = _FaceChar_;
        string text = label.processedText;

        label.UpdateNGUIText();
        NGUIText.PrintExactCharacterPositions(text, mTempVerts, mTempIndices);
        if (mTempVerts.size > 1)
        {
            spaceSize   = mTempVerts [mTempVerts.size - 1].x - mTempVerts [0].x;
            spaceNumber = Mathf.CeilToInt(faceSize / spaceSize);
        }
        mTempVerts.Clear();
        mTempIndices.Clear();
        label.text = oldStr;
        faceStr    = "";
        for (int i = 0; i < spaceNumber; i++)
        {
            faceStr += _FaceChar_;
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        /*
         * if (GameRoom.CurState == MPManager.RoomStates.WaitingForPlayersConnected)
         *      StateLabel.text = "Players Connected";
         * else if (GameRoom.CurState == MPManager.RoomStates.WaitingForPlayersReady)
         *      StateLabel.text = "Waiting for Ready";
         */
        StateLabel.text = GameRoom.CurState.ToString();

        PlayersLabel.text = "";

        if (GameRoom._playersInRoom != null)
        {
            foreach (MPPlayer loopedPlayer in GameRoom._playersInRoom)
            {
                if (loopedPlayer == null)
                {
                    Debug.Log("looped player null");
                }
                else
                {
                    PlayersLabel.text += "\n" + loopedPlayer.GetID() + " " + loopedPlayer.GetState();
                }
            }

            PlayersLabel.UpdateNGUIText();
        }
    }
Ejemplo n.º 9
0
    static int UpdateNGUIText(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        UILabel obj = (UILabel)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UILabel");

        obj.UpdateNGUIText();
        return(0);
    }
Ejemplo n.º 10
0
    private IEnumerator ShowDialogWithCoroutine(Hand playerHand)
    {
        this.isReady = false;
        if (this.dialog != (UnityEngine.Object)null)
        {
            Singleton <DialogManager> .Instance.ReleaseDialogToPool(this.dialog);
        }
        String  text        = FF9TextTool.CardName((Int32)playerHand.SelectedUI.Data.id);
        UILabel dialogLabel = Singleton <DialogManager> .Instance.GetDialogLabel();

        Int32 oldWidth = dialogLabel.width;

        dialogLabel.width = Convert.ToInt32(UIManager.UIContentSize.x);
        dialogLabel.ProcessText();
        dialogLabel.UpdateNGUIText();
        Int32 width = Convert.ToInt32((NGUIText.CalculatePrintedSize2(text).x + Dialog.DialogPhraseXPadding * 2f) / UIManager.ResourceXMultipier) + 1;

        dialogLabel.width = oldWidth;
        this.dialog       = Singleton <DialogManager> .Instance.AttachDialog(String.Concat(new Object[]
        {
            "[STRT=",
            width,
            ",1][CENT][NANI][IMME]",
            text,
            "[TIME=-1]"
        }), 0, 1, Dialog.TailPosition.AutoPosition, Dialog.WindowStyle.WindowStylePlain, new Vector2(10000f, 10000f), Dialog.CaptionType.None);

        this.dialog.Panel.depth       -= 2;
        this.dialog.phrasePanel.depth -= 2;
        while (this.dialog.CurrentState != Dialog.State.CompleteAnimation)
        {
            yield return(new WaitForEndOfFrame());
        }
        Vector2       targetPosition = this.CalculateDialogTargetPosition(playerHand.Select, playerHand.Count);
        TweenPosition tweenPos       = this.dialog.GetComponent <TweenPosition>();

        if (tweenPos == (UnityEngine.Object)null)
        {
            tweenPos = this.dialog.gameObject.AddComponent <TweenPosition>();
        }
        tweenPos.ignoreTimeScale = false;
        tweenPos.from            = new Vector3(targetPosition.x + 800f, targetPosition.y);
        tweenPos.to = targetPosition;
        tweenPos.ResetToBeginning();
        tweenPos.duration       = 0.3f;
        tweenPos.enabled        = true;
        tweenPos.animationCurve = this.AnimationCurv;
        Single countDown = tweenPos.duration;

        while (countDown >= 0f)
        {
            countDown -= Time.deltaTime;
            yield return(new WaitForEndOfFrame());
        }
        UnityEngine.Object.Destroy(tweenPos);
        this.isReady = true;
        yield break;
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Rebuild the visible text.
    /// </summary>

    protected void Rebuild()
    {
        if (isValid)
        {
            // Although we could simply use UILabel.Wrap, it would mean setting the same data
            // over and over every paragraph, which is not ideal. It's faster to only do it once
            // and then do wrapping ourselves in the 'for' loop below.
            textLabel.UpdateNGUIText();
            NGUIText.current.lineHeight = 1000000;

            UIFont bitmapFont = textLabel.bitmapFont;
            mTotalLines = 0;

            for (int i = 0; i < mParagraphs.size; ++i)
            {
                string    final;
                Paragraph p = mParagraphs.buffer[i];

                if (bitmapFont != null)
                {
                    if (bitmapFont.WrapText(p.text, out final))
                    {
                        p.lines      = final.Split('\n');
                        mTotalLines += p.lines.Length;
                    }
                }
#if DYNAMIC_FONT
                else if (NGUIText.WrapText(textLabel.trueTypeFont, p.text, out final))
                {
                    p.lines      = final.Split('\n');
                    mTotalLines += p.lines.Length;
                }
#endif
            }

            // Recalculate the total number of lines
            mTotalLines = 0;
            for (int i = 0, imax = mParagraphs.size; i < imax; ++i)
            {
                mTotalLines += mParagraphs.buffer[i].lines.Length;
            }

            // Update the bar's size
            if (scrollBar != null)
            {
                UIScrollBar sb = scrollBar as UIScrollBar;
                if (sb != null)
                {
                    sb.barSize = 1f - (float)scrollHeight / mTotalLines;
                }
            }

            // Update the visible text
            UpdateVisibleText();
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Rebuild the visible text.
    /// </summary>

    public void Rebuild()
    {
        if (isValid)
        {
            mLastWidth  = textLabel.width;
            mLastHeight = textLabel.height;

            // Although we could simply use UILabel.Wrap, it would mean setting the same data
            // over and over every paragraph, which is not ideal. It's faster to only do it once
            // and then do wrapping ourselves in the 'for' loop below.
            textLabel.UpdateNGUIText();
            NGUIText.rectHeight   = 1000000;
            NGUIText.regionHeight = 1000000;
            mTotalLines           = 0;

            for (int i = 0; i < paragraphs.size; ++i)
            {
                string    final;
                Paragraph p = mParagraphs.buffer[i];
                NGUIText.WrapText(p.text, out final, false, true);
                p.lines      = final.Split('\n');
                mTotalLines += p.lines.Length;
            }

            // Recalculate the total number of lines
            mTotalLines = 0;
            for (int i = 0, imax = mParagraphs.size; i < imax; ++i)
            {
                mTotalLines += mParagraphs.buffer[i].lines.Length;
            }

            // Update the bar's size
            if (scrollBar != null)
            {
                UIScrollBar sb = scrollBar as UIScrollBar;
                if (sb != null)
                {
                    float size = (mTotalLines == 0) ? 1f : 1f - (float)scrollHeight / mTotalLines;
                    if (size < 0.8f)
                    {
                        sb.barSize = size;
                        scrollBar.gameObject.SetActive(true);
                    }
                    else
                    {
                        scrollBar.gameObject.SetActive(false);
                    }
                }
            }

            // Update the visible text
            UpdateVisibleText();
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Rebuild the visible text.
        /// </summary>
        protected void Rebuild()
        {
            if (isValid)
            {
                // Although we could simply use UILabel.Wrap, it would mean setting the same data
                // over and over every paragraph, which is not ideal. It's faster to only do it once
                // and then do wrapping ourselves in the 'for' loop below.
                Label.UpdateNGUIText();
                NGUIText.rectHeight = 1000000;
                mTotalLines         = 0;
                bool success = true;

                for (int i = 0; i < mParagraphs.size; ++i)
                {
                    string    final;
                    Paragraph p = mParagraphs.buffer[i];

                    if (NGUIText.WrapText(p.text, out final))
                    {
                        p.lines      = final.Split('\n');
                        mTotalLines += p.lines.Length;
                    }
                    else
                    {
                        success = false;
                        break;
                    }
                }

                // Recalculate the total number of lines
                mTotalLines = 0;

                if (success)
                {
                    for (int i = 0, imax = mParagraphs.size; i < imax; ++i)
                    {
                        mTotalLines += mParagraphs.buffer[i].lines.Length;
                    }
                }

                // Update the bar's visibility and size
                if (Bar != null)
                {
                    Bar.gameObject.SetActive(scrollHeight != 0);
                    if (Bar.gameObject.activeSelf == true)
                    {
                        Bar.BarSize = (mTotalLines == 0) ? 1f : 1f - (float)scrollHeight / mTotalLines;
                    }
                }

                // Update the visible text
                UpdateVisibleText();
            }
        }
Ejemplo n.º 14
0
 private void UpdateText()
 {
     if (textMesh != null)
     {
         textMesh.text = ((!language) ? Japanese : English);
     }
     else
     {
         label.text = ((!language) ? Japanese : English);
         label.UpdateNGUIText();
     }
 }
Ejemplo n.º 15
0
    public float GetStringLen(string text)
    {
        float stringLen = 0f;

        if (!string.IsNullOrEmpty(text))
        {
            label = gameObject.GetComponent <UILabel>();
            label.UpdateNGUIText();
            stringLen = NGUIText.CalculatePrintedSize(text).x;
        }
        return(stringLen);
    }
Ejemplo n.º 16
0
 static public int UpdateNGUIText(IntPtr l)
 {
     try {
         UILabel self = (UILabel)checkSelf(l);
         self.UpdateNGUIText();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 17
0
        public static void SetWrapLabel(UILabel lab, string text, int height)
        {
            string text2 = null;

            lab.UpdateNGUIText();
            if (!lab.Wrap(text, out text2, height))
            {
                text2  = text2.Substring(0, text2.Length - 1);
                text2 += "...";
            }
            lab.text = text2;
        }
Ejemplo n.º 18
0
	static int UpdateNGUIText(IntPtr L)
	{
		try
		{
			ToLua.CheckArgsCount(L, 1);
			UILabel obj = (UILabel)ToLua.CheckObject<UILabel>(L, 1);
			obj.UpdateNGUIText();
			return 0;
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
Ejemplo n.º 19
0
        public override int GetTextWidth(string content)
        {
            var oldText = _label.text;
            var oldFlow = _label.overflowMethod;

            _label.text           = content;
            _label.overflowMethod = UILabel.Overflow.ResizeFreely;
            _label.UpdateNGUIText();
            var w = _label.width;

            _label.text           = oldText;
            _label.overflowMethod = oldFlow;
            return(w);
        }
Ejemplo n.º 20
0
    /// <summary>
    /// Rebuild the visible text.
    /// </summary>

    protected void Rebuild()
    {
        if (isValid)
        {
            // Although we could simply use UILabel.Wrap, it would mean setting the same data
            // over and over every paragraph, which is not ideal. It's faster to only do it once
            // and then do wrapping ourselves in the 'for' loop below.
            textLabel.UpdateNGUIText();
            NGUIText.rectHeight = 1000000;
            mTotalLines         = 0;

            for (int i = 0; i < mParagraphs.size; ++i)
            {
                string    final;
                Paragraph p = mParagraphs.buffer[i];
                NGUIText.WrapText(p.text, out final);
                p.lines = final.Split('\n');
                if (p.voice != null)
                {
                    mTotalLines += 5;
                }
                mTotalLines += p.lines.Length;
            }

            // Recalculate the total number of lines
            mTotalLines = 0;
            for (int i = 0, imax = mParagraphs.size; i < imax; ++i)
            {
                mTotalLines += mParagraphs.buffer[i].lines.Length;
                if (mParagraphs.buffer[i].voice != null)
                {
                    mTotalLines += 5;
                }
            }

            // Update the bar's size
            if (scrollBar != null)
            {
                UIScrollBar sb = scrollBar as UIScrollBar;
                if (sb != null)
                {
                    sb.barSize = (mTotalLines == 0) ? 1f : 1f - (float)scrollHeight / mTotalLines;
                }
            }

            // Update the visible text
            UpdateVisibleText();
        }
    }
Ejemplo n.º 21
0
    private void UpdateEmptySlotLabelSize(UILabel emptySlotLabel)
    {
        emptySlotLabel.SetAnchor((Transform)null);
        emptySlotLabel.updateAnchors = UIRect.AnchorUpdate.OnStart;
        Int32 width  = emptySlotLabel.width;
        Int32 height = emptySlotLabel.height;

        emptySlotLabel.width  = (Int32)UIManager.UIContentSize.x;
        emptySlotLabel.height = (Int32)UIManager.UIContentSize.y;
        emptySlotLabel.ProcessText();
        emptySlotLabel.UpdateNGUIText();
        Int32 num = (Int32)NGUIText.CalculatePrintedSize(emptySlotLabel.text).x + 3;

        emptySlotLabel.width  = (Int32)((width >= num) ? width : num);
        emptySlotLabel.height = height;
    }
Ejemplo n.º 22
0
    public static int UpdateNGUIText(IntPtr l)
    {
        int result;

        try
        {
            UILabel uILabel = (UILabel)LuaObject.checkSelf(l);
            uILabel.UpdateNGUIText();
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 23
0
    /// <summary>
    /// 测量给定<see cref="UILabel"/>的宽度能容纳的字符串长度
    /// </summary>
    /// <param name="label"></param>
    /// <param name="text">要测量的字符串,为null则采用<c>label.text</c></param>
    /// <param name="startIndex">起始下标</param>
    /// <returns>满足<paramref name="label"/>一行宽度的字符串末尾下标,其他则返回<paramref name="startIndex"/></returns>
    /// <remarks>该函数不会改变<paramref name="label"/>的状态,但会污染<see cref="NGUIText"/>的状态</remarks>
    public static int WrapLine(this UILabel label, string text = null, int startIndex = 0)
    {
        if (label == null)
        {
            return(startIndex);
        }
        if (text == null)
        {
            text = label.text;
        }
        if (startIndex < 0 || startIndex >= text.Length)
        {
            return(startIndex);
        }

        label.UpdateNGUIText();         // 更新 NGUIText 的状态
        if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 1 || NGUIText.finalLineHeight < 1f)
        {
            return(startIndex);
        }
        NGUIText.Prepare(text);         // 准备字体以备测量

        var cur_extent = 0f;
        var prev       = 0;

        for (var c = startIndex; c < text.Length; ++c)
        {
            var ch = text[c];
            var w  = NGUIText.GetGlyphWidth(ch, prev);
            if (w == 0f)
            {
                continue;
            }
            cur_extent += w + NGUIText.finalSpacingX;
            if (NGUIText.rectWidth < cur_extent)
            {
                return(c);
            }
        }

        return(text.Length);
    }
Ejemplo n.º 24
0
    public static void GenerateEmotion(UILabel chatContent, UIAtlas atlas, Transform emojiHitch)
    {
        BetterList <Vector3> betterList = new BetterList <Vector3>();
        BetterList <int>     indices    = new BetterList <int>();
        List <GameObject>    list       = new List <GameObject>();

        chatContent.pivot = UIWidget.Pivot.Left;
        chatContent.UpdateNGUIText();
        NGUIText.PrintCharacterPositions(chatContent.text, betterList, indices);
        int num = 0;

        for (int num2 = 0; num2 != Tools_StringCheck.listEmotionData.Count; num2++)
        {
            GameObject gameObject = new GameObject();
            UISprite   uISprite   = gameObject.AddComponent <UISprite>();
            if (null != emojiHitch)
            {
                uISprite.transform.parent = emojiHitch;
            }
            uISprite.depth = chatContent.depth + 1;
            uISprite.transform.localScale = new Vector3(1f, 1f, 1f);
            uISprite.name       = "emotion" + num2;
            uISprite.atlas      = atlas;
            uISprite.spriteName = Tools_StringCheck.listEmotionData[num2].serialNumber;
            uISprite.SetDimensions(38, 38);
            if (Tools_StringCheck.listEmotionData != null && Tools_StringCheck.listEmotionData.Count > 1)
            {
                if (Tools_StringCheck.listEmotionData[0].position == 0 && num2 != 0)
                {
                    num = -8;
                }
                else
                {
                    num = 0;
                }
            }
            int i = (2 * Tools_StringCheck.listEmotionData[num2].position != 0) ? (2 * Tools_StringCheck.listEmotionData[num2].position - 1) : 0;
            uISprite.transform.localPosition = new Vector3(chatContent.transform.localPosition.x, 0f, chatContent.transform.localPosition.z) + betterList[i] + new Vector3((float)(uISprite.width / 2 + -(float)chatContent.spacingX + num), (float)(-(float)chatContent.spacingY / 2 + 21), 0f);
        }
    }
Ejemplo n.º 25
0
        void OnEnable()
        {
            _nameLabel = GetComponent <UILabel>();
            if (_nameLabel == null)
            {
                YxDebug.Log("No Label! No Name!");
                return;
            }
            if (_panel == null)
            {
                _panel = GetComponent <UIPanel>() ?? GetComponentInParent <UIPanel>();
            }
            if (_panel == null)
            {
                return;
            }

            _nameLabel.UpdateNGUIText();
            int     labelWidth = _nameLabel.width;
            float   viewWidth  = _panel.GetViewSize().x;
            Vector3 pos        = transform.localPosition;

            _startPos = new Vector3(viewWidth / -2, pos.y, pos.z);

            if (labelWidth > viewWidth + _nameLabel.fontSize && !_isMoving)
            {
                _isMoving        = true;
                _nameLabel.pivot = UIWidget.Pivot.Left;
                StartCoroutine(LabelMove());
            }
            else
            {
                _isMoving = false;
                _nameLabel.overflowMethod          = UILabel.Overflow.ShrinkContent;
                _nameLabel.pivot                   = UIWidget.Pivot.Center;
                _nameLabel.width                   = 100;
                _nameLabel.transform.localPosition = Vector3.zero;
            }
        }
Ejemplo n.º 26
0
    public void Show(string text, float width = 0)
    {
        Transform child;

        for (int i = 0; i < transform.childCount; i++)
        {
            child = transform.GetChild(i);
            if (child.name == "Icon(Clone)")
            {
                Destroy(child.gameObject);
            }
        }
        if (label == null)
        {
            label = gameObject.GetComponent <UILabel>();
        }

        if (spriteIcon == null)
        {
            spriteIcon = gameObject.transform.Find("Icon").gameObject.GetComponent <UISprite>();
        }
        label.text = "";
        label.UpdateNGUIText();
        per_height = label.height;
        cur_height = per_height;
        cur_width  = 0;
        if (e_list == null)
        {
            e_list = new List <IconData>();
        }
        m_curIndex = 0;

        max_width = width;
        System.Text.StringBuilder _sb = LuaInterface.StringBuilderCache.Acquire();

        float ch_width = 0.0f;
        int   length = text.Length;
        int   n = 0, m = 0;
        float space_width = NGUIText.CalculatePrintedSize(" ").x;
        int   lengthIcon  = 0;

        if (spriteIcon != null)
        {
            lengthIcon = (int)Math.Ceiling(spriteIcon.localSize.x / space_width);
        }
        for (int i = 0; i < length; i++)
        {
            if (m > i)
            {
                _sb.Append(text[i]);
                continue;
            }
            if (n > 0)
            {
                n--;
                continue;
            }

            if (text[i] == '[')
            {
                int  index     = i;
                bool is_symbol = NGUIText.ParseSymbol(text, ref index);
                if (is_symbol)
                {
                    m = index;
                    _sb.Append(text[i]);
                    continue;
                }
            }

            if (text[i] == '\n' && i + 1 <= length)
            {
                cur_width   = 0;
                cur_height += per_height;
                _sb.Append("\n");
                continue;
            }

            if (text[i] == '[' && text.Substring(i, 5).Equals("[img]"))
            {
                if (cur_width + 2 * space_width > max_width)
                {
                    cur_height += per_height;
                    cur_width   = 0;
                    _sb.Append("\n");
                }
                int      indexEnd     = text.IndexOf("[-]", i);
                string   eName        = text.Substring(i + 5, indexEnd - i - 5);
                IconData e            = null;
                bool     isExpression = false;
                if (eName != null || eName != "")
                {
                    isExpression = true;
                    e            = GetEmoticonByIndex(m_curIndex);
                    m_curIndex++;
                    e.eName    = eName;
                    e.pos.x    = cur_width + 2;
                    e.pos.y    = -1 * cur_height;
                    cur_width += lengthIcon * space_width;
                    for (int j = 0; j < lengthIcon; j++)
                    {
                        _sb.Append(" ");
                    }
                }

                if (!isExpression)
                {
                    _sb.Append(text[i]);
                }
                else
                {
                    n = indexEnd - i + 2;
                }
            }
            else
            {
                ch_width   = NGUIText.CalculatePrintedSize(text[i].ToString()).x;
                cur_width += ch_width;
                if (cur_width > max_width)
                {
                    _sb.Append("\n");
                    cur_height += per_height;
                    cur_width   = ch_width;
                }
                _sb.Append(text[i]);
            }
        }
        label.text = LuaInterface.StringBuilderCache.GetStringAndRelease(_sb);//output_str;
        Show_emoticon();
    }
Ejemplo n.º 27
0
 public void SetItemPaidCurrency(string currency)
 {
     paidCurrencyLabel.text = currency;
     paidCurrencyLabel.UpdateNGUIText();
     paidCurrency = int.Parse(currency);
 }