Roy 6 lat temu
rodzic
commit
4717e6723c
2 zmienionych plików z 69 dodań i 26 usunięć
  1. 40 14
      assets/Script/Rank/FriendRank.js
  2. 29 12
      assets/Script/Rank/RankItem.js

+ 40 - 14
assets/Script/Rank/FriendRank.js

@@ -6,43 +6,69 @@ cc.Class({
         scrollView: cc.ScrollView,
         content: cc.Node,
         prefabRankItem: cc.Node,
-        itemScriptName:'',
+        itemScriptName: '',
     },
 
     // LIFE-CYCLE CALLBACKS:
 
-    onLoad () {
+    onLoad() {
         this.listAdapter = new ListViewAdapter(this.scrollView);
-
         this.users = [];
 
-
+        //-------------------------------------test--------------------------------------------------------------------------//
         this.mineScore = {
-            name:"user"+i,
-            rank:i+1,
-            score:(100-i*2)
+            nick: "user" + i,
+            url: "http://www.psahz.com/uploads/allimg/181006/094Q62X3-2.jpg",
+            score: (100 - i * 2)
         };
 
-        this.prefabRankItem.getComponent('RankItem').updateItem(this.mineScore,0);
+        this.prefabRankItem.getComponent('RankItem').updateItem(this.mineScore, 0);
 
-        for(i=0;i<30;i++){
+        for (i = 0; i < 30; i++) {
             this.user = {
-                name:"user"+i,
-                rank:i+1,
-                score:(100-i*2)
+                nick: "user" + i,
+                url: "http://www.psahz.com/uploads/allimg/181006/094Q62X3-2.jpg",
+                score: (100 - i * 2)
             };
 
             this.users.push(this.user);
         }
 
         this.listAdapter.updateItems(this.users, this.prefabRankItem, this.itemScriptName);
+
+
+        //-------------------------------------test--------------------------------------------------------------------------//
+
+
+        // BK.QQ.getRankListWithoutRoom(attr, order, rankType, function (errCode, cmd, data) {
+        //     BK.Script.log(1, 1, "getRankListWithoutRoom callback  cmd" + cmd + " errCode:" + errCode + "  data:" + JSON.stringify(data));
+        //     // 返回错误码信息
+        //     if (errCode !== 0) {
+        //         BK.Script.log(1, 1, '获取排行榜数据失败!错误码:' + errCode);
+        //         return;
+        //     }
+        //     // 解析数据
+        //     if (data) {
+        //         for (var i = 0; i < data.data.ranking_list.length; ++i) {
+        //             var rd = data.data.ranking_list[i];
+        //             // rd 的字段如下:
+        //             //var rd = {
+        //             //    url: '',            // 头像的 url
+        //             //    nick: '',           // 昵称
+        //             //    score: 1,           // 分数
+        //             //    selfFlag: false,    // 是否是自己
+        //             //};
+        //         }
+        //     }
+        // });
+
     },
 
-    start () {
+    start() {
 
     },
 
-    update (dt) {
+    update(dt) {
         if (this.listAdapter) {
             this.listAdapter.update(dt);
         }

+ 29 - 12
assets/Script/Rank/RankItem.js

@@ -4,28 +4,45 @@ cc.Class({
     extends: cc.Component,
 
     properties: {
-        rankLabel:cc.Label,
-        rankSprite:cc.Sprite,   
+        rankLabel: cc.Label,
+        rankSprite: cc.Sprite,
         avatar: cc.Sprite,
-        nameLabel:cc.Label,
-        scoreLabel:cc.Label,
-        rankSpriteList:[cc.SpriteFrame],
+        nameLabel: cc.Label,
+        scoreLabel: cc.Label,
+        rankSpriteList: [cc.SpriteFrame],
     },
 
-    onLoad () {
+    onLoad() {
         this._itemId = 0;
     },
 
-    start () {
+    start() {
 
     },
 
-    updateItem(data,itemId){
-        this._itemId = itemId,
-        this.rankLabel.string = data.rank;
-        this.rankSprite.spriteFrame = this.rankSpriteList[0];
+    updateItem(data, itemId) {
+        this._itemId = itemId;
+
+        if (data.rank < 3) {
+            this.rankSprite.node.active = true;
+            this.rankLabel.node.active = false;
+            this.rankSprite.spriteFrame = this.rankSpriteList[this._itemId];
+        } else {
+            this.rankSprite.node.active = false;
+            this.rankLabel.node.active = true;
+            this.rankLabel.string = this._itemId + 1;
+        }
+
         this.scoreLabel.string = data.score;
-        this.nameLabel.string = data.name;
+        this.nameLabel.string = data.nick;
+
+        cc.loader.loadRes(data.url, cc.SpriteFrame, (error, spriteFrame) => {
+            if (error) {
+
+            } else {
+                this.avatar.spriteFrame = spriteFrame;
+            }
+        });
     }
 
     // update (dt) {},