Example #1
0
    public void UpdateContent(int curLevel)
    {
        List <FriendScoreData> scoreDataList = HighScoreModel.Instance.getFriendScoresForLevel(curLevel);

        for (int i = 1; i < scoreDataList.Count; i++)
        {
            GameObject newCell = (GameObject)Instantiate(cellObj);
            newCell.transform.parent     = this.transform;
            newCell.transform.localScale = new Vector3(1, 1, 1);
        }

        UIGrid gridCom = this.GetComponent <UIGrid>();

        gridCom.Reposition();

        for (int i = 0; i < scoreDataList.Count; i++)
        {
            FriendScoreData scoreData = scoreDataList[i];

            GameObject childCellObj = transform.GetChild(i).gameObject;

            GameObject nameObj   = childCellObj.transform.Find("NameLabel").gameObject;
            UILabel    nameLabel = nameObj.GetComponent <UILabel>();
            nameLabel.text = scoreData.name;

            GameObject scoreObj   = childCellObj.transform.Find("ScoreLabel").gameObject;
            UILabel    scoreLabel = scoreObj.GetComponent <UILabel>();
            scoreLabel.text = scoreData.score.ToString();

            GameObject rankObj   = childCellObj.transform.Find("RankLabel").gameObject;
            UILabel    rankLabel = rankObj.GetComponent <UILabel>();
            rankLabel.text = (i + 1).ToString();
        }
    }
    public void UpdateScoreTable(int levelIdx)
    {
        // set panel to initial position
        GameObject panelObj = GameObject.Find("FriendListPanel");

        panelObj.transform.localPosition = new Vector3(-250, 110, 6);
        UIPanel panelCom = panelObj.GetComponent <UIPanel>();

        panelCom.clipRange = new Vector4(250, 0, 768, 420);

        // get friend score data
        List <FriendScoreData> scoreDataList = HighScoreModel.Instance.getFriendScoresForLevel(levelIdx);

        GameObject scoreTable = GameObject.Find("FriendScoreTable").gameObject;

        if (scoreTable == null)
        {
            return;
        }

        // set showed cells' number
        for (int i = 0; i < scoreTable.transform.childCount; i++)
        {
            GameObject childObj = scoreTable.transform.GetChild(i).gameObject;
            childObj.SetActive(i < scoreDataList.Count);
        }

        // update content
        for (int i = 0; i < scoreDataList.Count; i++)
        {
            FriendScoreData scoreData = scoreDataList[i];

            GameObject childCellObj = scoreTable.transform.GetChild(i).gameObject;

            GameObject backgroundObj    = childCellObj.transform.Find("background").gameObject;
            UISprite   backgroundSprite = backgroundObj.GetComponent <UISprite>();
            if (scoreData.isMe)
            {
                backgroundSprite.spriteName = "me_score_board";
            }
            else
            {
                backgroundSprite.spriteName = "score_board";
            }

            GameObject nameObj   = childCellObj.transform.Find("NameLabel").gameObject;
            UILabel    nameLabel = nameObj.GetComponent <UILabel>();
            nameLabel.text = scoreData.name;
            //nameLabel.text = "11111111111111111111111111";

            GameObject scoreObj   = childCellObj.transform.Find("ScoreLabel").gameObject;
            UILabel    scoreLabel = scoreObj.GetComponent <UILabel>();
            scoreLabel.text = scoreData.score.ToString();

            GameObject rankObj   = childCellObj.transform.Find("RankLabel").gameObject;
            UILabel    rankLabel = rankObj.GetComponent <UILabel>();
            rankLabel.text = (i + 1).ToString();

            int id = 0;
            int.TryParse(scoreData.platformID, out id);
            int    mod        = id % 10;
            string spriteName = "avatar_00" + mod.ToString();
            spriteName = mod != 0 ? spriteName : "avatar_010";

            GameObject iconObj    = childCellObj.transform.Find("Icon").gameObject;
            UISprite   iconSprite = iconObj.GetComponent <UISprite>();
            iconSprite.spriteName = spriteName;
        }
    }