Beispiel #1
0
        public void Update(Chat.Message message)
        {
            Id = message.Id;

            if (m_Name != null)
            {
                m_Name.SetNewText(GuiBaseUtils.FixNameForGui(message.Nickname));
            }

            if (m_Text != null)
            {
                m_Text.SetNewText(m_Name == null ? string.Format("{0}: {1}", GuiBaseUtils.FixNameForGui(message.Nickname), message.Text) : message.Text);

                Transform trans = m_Text.transform;
                Vector3   scale = trans.localScale;
                m_Rect.width  = Mathf.RoundToInt(m_Text.textSize.x * scale.x);
                m_Rect.height = Mathf.RoundToInt(m_Text.textSize.y * scale.y);
            }

            if (m_RankIcon != null)
            {
                m_RankIcon.State = string.Format("Rank_{0}", Mathf.Min(message.Rank, m_RankIcon.Count - 1).ToString("D2"));
            }

            if (m_RankText != null)
            {
                m_RankText.SetNewText(message.Rank.ToString());
            }

            if (m_HighlightBkg != null)
            {
                Vector2   pos    = m_HighlightBkg.GetOrigPos();
                Transform trans  = m_HighlightBkg.transform;
                Vector3   scale  = trans.lossyScale;
                int       offset = Mathf.RoundToInt(pos.y - m_Root.GetOrigPos().y);
                int       width  = Mathf.RoundToInt(m_HighlightBkg.GetWidth());
                int       height = (int)m_Rect.height + 4;

                offset -= offset - Mathf.RoundToInt(m_HighlightBkg.GetHeight() * 0.5f * scale.y);
                pos.y   = pos.y - offset + height * 0.5f * scale.y;

                m_HighlightBkg.UpdateSpritePosAndSize(0, pos.x, pos.y, width, height);

                m_Rect.width = Mathf.RoundToInt(width * scale.x);
                //m_Rect.height = Mathf.RoundToInt(height * scale.y);
            }

            foreach (var button in m_Buttons)
            {
                Transform trans = button.transform;
                Vector3   pos   = trans.localPosition;

                pos.y = m_Rect.height * 0.5f;
                trans.localPosition = pos;
            }

            m_HoverButton = null;
        }
Beispiel #2
0
    //---------------------------------------------------------
    void RegenerateSprites()
    {
        if (IsDataRegenerationNeaded() == false || m_Widget.IsVisible() == false)
        {
            return;
        }

        // regenerate runtime data for new text...
        GenerateRunTimeData();

        string text = Text;

        if (string.IsNullOrEmpty(text) == false && m_Uppercase)
        {
            text = text.ToUpper();
        }

        // destroy old text if any exist...
        m_Widget.PrepareSprites(string.IsNullOrEmpty(text) == true ? 0 : text.Length);

        if (string.IsNullOrEmpty(text) == false && text.Length > 0)
        {
            Vector3 scale = Vector3.one;

            Texture texture = fontTexture;

            int texWidth  = texture ? texture.width : 1;
            int texHeight = texture ? texture.height : 1;

            float lineHeight = m_LineSize.y * texHeight;
            float lineWidth  = m_LineSize.x;
            float widthMult  = m_Widget.GetWidth() / lineWidth;

            // compute down scale if needed
            if (m_Boundaries.IsEmpty() == false)
            {
                Rect clientRect = GetRect();
                Rect rect       = m_Boundaries.Intersect(clientRect);

                float scaleX = rect.width / clientRect.width;
                float scaleY = rect.height / clientRect.height;

                if (scaleY > scaleX)
                {
                    scaleY = scaleX;
                }
                else
                {
                    scaleX = scaleY;
                }

                scale.x *= scaleX;
                scale.y *= scaleY;
            }

            // setup cursor ...
            Vector2 cursor    = GetLeftUpPos(m_Widget.GetOrigPos(), scale);
            float   lineBegin = cursor.x;
            cursor.y += lineHeight * scale.y * 0.5f;         // textHeight*0.5f;

            bool multiline = IsMultiline(text);

            if (multiline == true)
            {
                cursor = SetupCursorForTextAlign(cursor, text, 0, m_Alignment, font, lineBegin, lineWidth, widthMult * scale.x);
            }

            for (int i = 0; i < text.Length; ++i)
            {
                int character = text[i];
                switch (character)
                {
                case '\n':
                    if (multiline == true)
                    {
                        cursor = SetupCursorForTextAlign(cursor, text, i + 1, m_Alignment, font, lineBegin, lineWidth, widthMult * scale.x);
                    }
                    else
                    {
                        cursor.x = lineBegin;
                    }

                    cursor.y = cursor.y + (lineHeight + lineSpace * texHeight) * scale.y;
                    m_Widget.SetTextureCoords(i, 0.0f, 0.0f, 0.0f, 0.0f);
                    m_Widget.UpdateSpritePosAndSize(i, 0, -Screen.height, 1.0f, 1.0f);
                    m_Widget.ShowSprite(i, false);
                    break;

                default:
                {
                    if (useFontEx == false)
                    {
                        Vector2 inTexPos  = new Vector2();
                        Vector2 inTexSize = new Vector2();
                        float   width;

                        GUIBase_Font fontOld = font as GUIBase_Font;
                        fontOld.GetCharDscr(character, out width, ref inTexPos, ref inTexSize);
                        width *= widthMult;

                        int texU = (int)(texWidth * inTexPos.x);
                        int texV = (int)(texHeight * inTexPos.y);
                        int texW = (int)(texWidth * inTexSize.x);
                        int texH = (int)(texHeight * inTexSize.y);

                        cursor.x += 0.5f * width * scale.x;
                        m_Widget.SetTextureCoords(i, texU, texV, texW, texH);
                        m_Widget.UpdateSpritePosAndSize(i, cursor.x, cursor.y, width, lineHeight);
                        cursor.x += 0.5f * width * scale.x;
                    }
                    else
                    {
                        float width;
                        Rect  spriteRect, texRect;

                        GUIBase_FontEx fontEx = font as GUIBase_FontEx;

                        if (fontEx.GetCharDescription(text[i], out width, out spriteRect, out texRect, false, false))
                        {
                            width *= widthMult;

                            Vector2 inCharSize = new Vector2(spriteRect.width * scale.x, spriteRect.height /*****/ * texHeight * scale.y);
                            // TODO :: rewite without texHeight...
                            Vector2 inCharCenter = cursor + new Vector2(spriteRect.center.x * scale.x, 0.0f);

                            m_Widget.SetTextureCoords(i, (int)texRect.x, (int)texRect.y, (int)texRect.width, (int)texRect.height);
                            m_Widget.UpdateSpritePosAndSize(i, inCharCenter.x, inCharCenter.y, inCharSize.x, inCharSize.y);
                            cursor.x += width * scale.x;
                        }
                    }
                    break;
                }
                }
            }
        }

        // we have to force widget update.
        m_RegenerationNeeded = false;
        m_Widget.SetModify();
    }
Beispiel #3
0
    //---------------------------------------------------------
    void RegenerateSprites()
    {
        if (m_RegenerateSprites == false || m_Widget.IsVisible() == false)
        {
            return;
        }

        if (m_Font == null)
        {
            m_Font = MFFontManager.GetFont(m_FontName) as GUIBase_FontEx;
            if (m_Font == null)
            {
                Debug.LogError(gameObject.GetFullName() + " Can't load font with name " + m_FontName);
                return;
            }
        }

        if (m_TextID > 0)
        {
            m_Text = TextDatabase.instance[m_TextID];
        }

        // destroy old text if any exist...
        int maxSprites = text != null && text.Length > 0 ? Mathf.CeilToInt(text.Length * 0.1f) * 10 : 0;

        m_Widget.PrepareSprites(maxSprites);

        if (text != null && text.Length > 0)
        {
            Vector3 scale = transform.lossyScale;
            scale = Vector3.one;

            // setup cursor ...
            Vector2 leftUpPos = new Vector2(m_Widget.GetOrigPos().x - m_Widget.GetWidth() * 0.5f * scale.x,
                                            m_Widget.GetOrigPos().y - m_Widget.GetHeight() * 0.5f * scale.y);
            Vector2 cursor = leftUpPos;

            float maxLineSize = m_Widget.GetWidth() * scale.x;

            scale.x = m_TextScale.x;
            scale.y = m_TextScale.y;

            List <TextLine> textLines = GetLines(text, m_Font, alignment, maxLineSize, scale, lineSpace, IsForTextField);
            if (textLines == null || textLines.Count <= 0)
            {
                return;
            }

            float fontHeight = m_Font.GetFontHeight();
            m_TextSize = new Vector2(m_Widget.GetWidth(), textLines.Count * fontHeight * scale.y + (textLines.Count - 1) * lineSpace * fontHeight * scale.y);

            float width;
            Rect  spriteRect, texRect;

            int spriteIdx = 0;
            foreach (TextLine line in textLines)
            {
                cursor = leftUpPos + line.m_Offset;

                for (int i = line.m_StartIndex; i < line.m_EndIndex; ++i)
                {
                    int character = text[i];

                    if (!IsForTextField && character == ' ')
                    {
                        cursor.x += line.m_SpaceWidth;
                        continue;
                    }
                    switch (character)
                    {
                    case '\n':
                        Debug.LogWarning("function GetLines doesn't work correctly");
                        break;

                    default:
                    {
                        if (m_Font.GetCharDescription(text[i], out width, out spriteRect, out texRect, false, false, false))
                        {
                            Vector2 inCharSize   = new Vector2(spriteRect.width * scale.x, spriteRect.height * scale.y);
                            Vector2 inCharCenter = cursor + new Vector2(spriteRect.center.x * scale.x, 0.0f);

                            m_Widget.SetTextureCoords(spriteIdx, (int)texRect.x, (int)texRect.y, (int)texRect.width, (int)texRect.height);
                            m_Widget.UpdateSpritePosAndSize(spriteIdx, inCharCenter.x, inCharCenter.y, inCharSize.x, inCharSize.y);
                            m_Widget.ShowSprite(spriteIdx, true);
                            cursor.x += width * scale.x;

                            spriteIdx++;
                        }
                        break;
                    }
                    }
                }
            }

            // hide all unused sprites
            while (spriteIdx < maxSprites)
            {
                m_Widget.SetTextureCoords(spriteIdx, 0.0f, 0.0f, 0.0f, 0.0f);
                m_Widget.UpdateSpritePosAndSize(spriteIdx, 0.0f, -Screen.height, 1.0f, 1.0f);
                m_Widget.ShowSprite(spriteIdx, false);
                spriteIdx++;
            }
        }

        // we have to force widget update.
        m_RegenerateSprites = false;
        m_Widget.SetModify();
    }
    void SetHintVisibility(E_Hint hintId, bool state)
    {
        if (state == true)
        {
            if (GuiOptions.showHints == false)
            {
                return;
            }
            if (BuildInfo.Version.Stage == BuildInfo.Stage.Beta)
            {
                return;
            }
        }

        HintInfo info = GetHintInfo(hintId);

        if (info == null)
        {
            return;
        }
        if (info.HintButton == null)
        {
            return;
        }

        info.HintButton.Widget.Show(state, true);

        if (state == true)
        {
            if (m_HintSound != null)
            {
                MFGuiManager.Instance.PlayOneShot(m_HintSound);
            }

            m_CurrentHint = hintId;

            GUIBase_Widget widget = info.HintButton.Widget;
            Transform      trans  = widget.transform;
            Vector3        origin = widget.GetOrigPos();

            origin.y -= info.Offset.y;

            // animate transparency
            Tweener.TweenFromTo(widget,
                                "m_FadeAlpha",
                                0.0f,
                                1.0f,
                                0.2f,
                                Tween.Easing.Quad.EaseIn,
                                (tween, finished) =>
            {
                GUIBase_Widget[] children = widget.GetComponentsInChildren <GUIBase_Widget>();
                foreach (var child in children)
                {
                    child.FadeAlpha = widget.FadeAlpha;
                }
            });

            // animate position
            Tweener.TweenFromTo(this,
                                "m_HintTweenY",
                                origin.y + 25.0f,
                                origin.y,
                                0.15f,
                                Tween.Easing.Sine.EaseInOut,
                                (tween, finished) =>
            {
                trans.position = new Vector3(trans.position.x, m_HintTweenY, trans.position.z);

                if (finished == true)
                {
                    Tweener.TweenFromTo(this,
                                        "m_HintTweenY",
                                        origin.y + 5.0f,
                                        origin.y,
                                        0.15f,
                                        Tween.Easing.Sine.EaseInOut,
                                        (tween1, finished1) => { trans.position = new Vector3(trans.position.x, m_HintTweenY, trans.position.z); });
                }
            });
        }
        else if (m_CurrentHint == hintId)
        {
            m_PreviousHint = m_CurrentHint;
            m_CurrentHint  = E_Hint.Max;

            Tweener.StopTweens(true);
        }
    }
Beispiel #5
0
    //-----------------------------------------------------
    void SetNumber(int number, int max, bool force)
    {
        if (m_Value == number && false == force)
        {
            return;
        }

        int absNumber = Mathf.Abs(number);

        if (absNumber > max)
        {
            absNumber = max;
        }

        m_Value = number;

        int div1 = 1;
        int div2 = 10;

        int visibleDigits = 0;

        for (int digitIdx = 0; digitIdx < numberDigits; ++digitIdx)
        {
            int rest = (absNumber % div2) / div1;

            if ((absNumber > (div1 - 1)) || (digitIdx == 0) || m_KeepZeros)
            {
                // Show digit
                m_Widget.ShowSprite(digitIdx, true);

                // set correct UV
                MFGuiSprite   s        = m_Widget.GetSprite(digitIdx);
                MFGuiUVCoords uvCoords = s.uvCoords;
                uvCoords.U = m_UvLeft + m_UvWidth * rest;
                uvCoords.V = 1.0f - (m_UvTop + m_UvHeight);
                s.uvCoords = uvCoords;

                visibleDigits++;
            }
            else
            {
                // Hide digit
                m_Widget.ShowSprite(digitIdx, false);
            }

            div1  = div2;
            div2 *= 10;
        }

        if (visibleDigits == 0)
        {
            return;
        }
        if (visibleDigits == m_LastVisibleDigits && force == false)
        {
            return;
        }
        m_LastVisibleDigits = visibleDigits;

        Transform trans = transform;
        Vector3   scale = trans.lossyScale;

        float   width     = m_Widget.GetWidth() / numberDigits;
        float   height    = m_Widget.GetHeight();
        float   halfWidth = m_Widget.GetWidth() * scale.x * 0.5f;
        Vector3 deltaPos  = new Vector3(halfWidth, 0.0f);
        Vector3 rightPos  = m_Widget.GetOrigPos() + deltaPos;

        Vector3 delta;

        switch (m_Alignment)
        {
        case TextAlignment.Left:
            delta       = deltaPos / (numberDigits * 0.5f);
            rightPos.x -= (numberDigits - visibleDigits) * delta.x;
            break;

        case TextAlignment.Center:
            delta = deltaPos / (visibleDigits * 0.5f);
            break;

        default:
            delta = deltaPos / (numberDigits * 0.5f);
            break;
        }

        for (int idx = 0; idx < visibleDigits; ++idx)
        {
            m_Widget.UpdateSpritePosAndSize(idx, rightPos.x - (idx + 0.5f) * delta.x, rightPos.y - (idx + 0.5f) * delta.y, width, height);
        }
    }