Beispiel #1
0
    //---------------------------------------------------------
    public void SetValue(int idx, int type)
    {
        if (idx >= 0 && idx < m_MaxCount)
        {
            // set correct UV
            MFGuiSprite s = m_Widget.GetSprite(idx + 1);

            if (s != null)
            {
                if (type == -1)
                {
                    // TODO - nerenderovat nic
                    //s.lowerLeftUV	= usedSpritesUV[0].lowerLeftUV;
                    //s.uvDimensions	= usedSpritesUV[0].uvDimensions;
                }
                else if (type >= 0 && type < m_UsedSprites.Length)
                {
                    s.uvCoords = new MFGuiUVCoords(m_UsedSpritesUV[idx].m_LowerLeftUV, m_UsedSpritesUV[idx].m_UvDimensions);
                }
            }
        }
    }
Beispiel #2
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);
        }
    }