Example #1
0
    /*
     * @brief draw score
     * @param int score
     * @param int x
     * @param int y
     * @param int count : draw number count
     * @param int anchor : ( 0 = left , 1 = center , 2 = right )
     * @param interval : draw number interval
     * @param zero : draw zero number
     * */
    void drawScore(long score, int x, int y, int count, float magnification = 1.0f, TextAlignment anchor = TextAlignment.Left
                   , int interval = 0, bool zero = false, bool plus = false, bool minus = false)
    {
        if (count <= 0)
        {
            return;
        }

        bool drawMinus = false;

        if (minus == true)
        {
            if (score < 0)
            {
                score     = score * (-1);
                drawMinus = true;
            }
        }
        else
        {
            if (score < 0)
            {
                score = 0;
            }
        }

        int   i = 0;
        int   j = 0;
        int   drawFirstCount = -1;
        bool  tempDrawZero   = false;
        float drawX          = x;
        int   drawScore      = (int)score;

        //set draw x postion
        if (anchor.Equals(TextAlignment.Left))
        {
        }
        else if (anchor.Equals(TextAlignment.Center))
        {
            drawX -= ((((float)imgW * (float)magnification * (float)count) + ((float)interval * magnification * (float)(count - 1))) / 2);
        }
        else if (anchor.Equals(TextAlignment.Right))
        {
            drawX -= (((float)imgW * (float)magnification * (float)count) + ((float)interval * magnification * (float)(count - 1)));
        }

        //set result value
        int temp = 0;

        for (i = 0, j = count - 1; i < count; i++, j--)
        {
            temp       = drawScore / (int)arrDivisionNum[j];
            drawScore -= (temp * (int)arrDivisionNum[j]);
            arrResultNum.Add(temp);
        }

        //draw number
        //GUI.BeginGroup( new Rect(drawX,y,drawX+(imgW*count)+(interval*(count-1)),y+imgH) );
        //GUI.BeginGroup( new Rect( 0, y, Screen.width, y+imgH ) );

        for (i = 0; i < count; i++)
        {
            if (score == 0 && i == count - 1)
            {
                tempDrawZero = true;
            }

            if (tempDrawZero == false)
            {
                if (i == 0)
                {
                    tempDrawZero = zero;
                }
                if ((tempDrawZero == false) && ((int)arrResultNum[i] != 0))
                {
                    tempDrawZero = true;
                }
            }

            //draw number
            if (tempDrawZero == true || zero == true)
            {
                if (drawFirstCount == -1)
                {
                    drawFirstCount = i;
                }
                rect.Set(drawX + ((float)imgW * magnification * (float)i) + ((float)interval * magnification * (float)i), y, (float)imgW * magnification, (float)imgH * magnification);
                //GUI.DrawTexture( rect , (Texture2D)getNumberTexture( (int)arrResultNum[i] ) ); //12 image count
                GUI.DrawTextureWithTexCoords(rect, (Texture2D)texNum, new Rect(oneImageW * ((int)arrResultNum[i]), 0.0f, oneImageW, 1.0f));               //1 image
            }
        }

        //draw plus, minus
        if (zero == false)
        {
            if (drawFirstCount != -1)
            {
                drawFirstCount--;
                rect.Set(drawX + ((float)imgW * magnification * (float)drawFirstCount) + ((float)interval * magnification * (float)drawFirstCount), y
                         , (float)imgW * magnification, (float)imgH * magnification);
                if (plus == true && score != 0)
                {
                    GUI.DrawTextureWithTexCoords(rect, (Texture2D)texNum, new Rect(oneImageW * 10, 0.0f, oneImageW, 1.0f));
                }
                if (drawMinus == true)
                {
                    GUI.DrawTextureWithTexCoords(rect, (Texture2D)texNum, new Rect(oneImageW * 11, 0.0f, oneImageW, 1.0f));
                }
            }
        }

        //GUI.EndGroup();

        //release ArrayList
        for (i = 0; i < arrResultNum.Count; i++)
        {
            arrResultNum.Remove(i);
        }
        arrResultNum.Clear();
    }
Example #2
0
 /*
  * @brief get Screen alignment value
  * @param TextAlignment align
  * */
 public int getScreen(TextAlignment align)
 {
     return(align.Equals(TextAlignment.Center) ? (Screen.width >> 1) : (align.Equals(TextAlignment.Right) ? (Screen.width) : 0));
 }