Преглед на файлове

游戏结束时的排行榜

Roy преди 6 години
родител
ревизия
015225bdc5
променени са 5 файла, в които са добавени 158 реда и са изтрити 20 реда
  1. 1 1
      assets/Scene/GameSence.fire
  2. 13 9
      assets/Script/Game/GameOverItem.js
  3. 132 0
      assets/Script/Game/GameOverRank.js
  4. 9 0
      assets/Script/Game/GameOverRank.js.meta
  5. 3 10
      assets/Script/Rank/RankItem.js

+ 1 - 1
assets/Scene/GameSence.fire

@@ -5041,7 +5041,7 @@
       }
     ],
     "_tag": -1,
-    "_active": false,
+    "_active": true,
     "_components": [],
     "_prefab": null,
     "_id": "06IIz3RchD8rEsbWDwvkB3",

+ 13 - 9
assets/Script/Game/GameOverItem.js

@@ -1,14 +1,18 @@
 cc.Class({
-  extends: cc.Component,
+    extends: cc.Component,
 
-  properties: {
-    sprite: cc.Sprite,
-    score: cc.Label,
-  },
+    properties: {
+        sprite: cc.Sprite,
+        score: cc.Label,
+    },
 
-  // onLoad () {},
+    // onLoad () {},
 
-  start() {},
+    start() {},
 
-// update (dt) {},
-})
+    updateItem() {
+
+    },
+
+    // update (dt) {},
+})

+ 132 - 0
assets/Script/Game/GameOverRank.js

@@ -0,0 +1,132 @@
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        item1: cc.Node,
+        item2: cc.Node,
+        item3: cc.Node
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {},
+
+    onEnable() {
+        if (CC_QQPLAY) {
+            var attr = 'score'; // 使用哪一种上报数据做排行,可传入score,a1,a2等
+            var order = 1; // 排序的方法:[ 1: 从大到小(单局),2: 从小到大(单局),3: 由大到小(累积)]
+            var rankType = 0; // 要查询的排行榜类型,0: 好友排行榜
+            let self = this
+            BK.QQ.getRankListWithoutRoom(attr, order, rankType, function (errCode, cmd, data) {
+                // 返回错误码信息
+                if (errCode !== 0) {
+                    BK.Script.log(1, 1, '获取排行榜数据失败!错误码:' + errCode)
+                    return
+                }
+                // 解析数据
+                if (data) {
+                    self.bindRank(data.data.ranking_list);
+                }
+            })
+        } else {
+            let reponse = {
+                'errCode': 0,
+                'cmd': 'apollo_router_game.apollo_user_rankinglist_linkcmd_custom_ranking',
+                'data': {
+                    'data': {
+                        'ranking_list': [{
+                            'nick': '石达开',
+                            'url': 'http://img0.imgtn.bdimg.com/it/u=789186820,4034808660&fm=27&gp=0.jpg',
+                            'score': 1234,
+                            'a1': 121,
+                            'a2': 22,
+                            'selfFlag': true
+                        }, {
+                            'nick': '绝世佳人',
+                            'url': 'http://a.hiphotos.baidu.com/zhidao/pic/item/21a4462309f79052782f28490ff3d7ca7bcbd591.jpg',
+                            'score': 924,
+                            'a1': 101,
+                            'a2': 20,
+                            'selfFlag': false
+                        }, {
+                            'nick': '千山万水',
+                            'url': 'http://img5.imgtn.bdimg.com/it/u=1443063381,2025721196&fm=27&gp=0.jpg',
+                            'score': 712,
+                            'a1': 134,
+                            'a2': 24,
+                            'selfFlag': false
+                        }, {
+                            'nick': '三年二班',
+                            'url': 'http://img1.imgtn.bdimg.com/it/u=3463612537,3165214774&fm=27&gp=0.jpg',
+                            'score': 527,
+                            'a1': 167,
+                            'a2': 23,
+                            'selfFlag': false
+                        }, {
+                            'nick': 'henry',
+                            'url': 'http://img5.imgtn.bdimg.com/it/u=377014827,3751078472&fm=27&gp=0.jpg',
+                            'score': 327,
+                            'a1': 154,
+                            'a2': 32,
+                            'selfFlag': false
+                        }, {
+                            'nick': '图样图森破',
+                            'url': 'http://img2.imgtn.bdimg.com/it/u=1269743249,2763282807&fm=27&gp=0.jpg',
+                            'score': 227,
+                            'a1': 125,
+                            'a2': 86,
+                            'selfFlag': false
+                        }, {
+                            'nick': 'Mo_Bai',
+                            'url': 'http://img3.imgtn.bdimg.com/it/u=3166078695,1890527236&fm=27&gp=0.jpg',
+                            'score': 167,
+                            'a1': 138,
+                            'a2': 39,
+                            'selfFlag': false
+                        }]
+                    }
+                }
+            }
+            self.bindRank(reponse.data.data.ranking_list);
+        }
+    },
+
+
+    bindRank(rankList){
+        for (var i = 0; i < rankList.length; ++i) {
+            var rd = rankList[i]
+            // rd 的字段如下:
+            // var rd = {
+            //    url: '',            // 头像的 url
+            //    nick: '',           // 昵称
+            //    score: 1,           // 分数
+            //    selfFlag: false,    // 是否是自己
+            // }
+            if (rd.selfFlag) {
+                if (i > 0) {
+                    self.item1.active = true;
+                    self.item2.active = true;
+
+                    self.item1.updateItem(rankList[i - 1]);
+                    self.item2.updateItem(rd);
+                    if (i + 1 < rankList.length) {
+                        self.item3.active = true;
+                        self.item3.updateItem(rankList[i + 1]);
+                    }
+                } else {
+                    self.item1.active = false;
+                    self.item2.active = true;
+                    self.item2.updateItem(rd);
+                    if (i + 1 < rankList.length) {
+                        self.item3.active = true;
+                        self.item3.updateItem(rankList[i + 1]);
+                    }
+                }
+            }
+        }
+    },
+
+    start() {},
+
+    // update (dt) {},
+})

+ 9 - 0
assets/Script/Game/GameOverRank.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "d10ad99d-2518-4fac-9248-691f4f354ddd",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 3 - 10
assets/Script/Rank/RankItem.js

@@ -1,5 +1,3 @@
-
-
 cc.Class({
     extends: cc.Component,
 
@@ -36,14 +34,9 @@ cc.Class({
         this.scoreLabel.string = data.score;
         this.nameLabel.string = data.nick;
 
-
-        if (CC_QQPLAY) {
-            var img = BK.Image.loadImage("GameRes://texture/icon.png");
-            this.avatar.spriteFrame = new cc.SpriteFrame(img);
-        }
-
         cc.loader.load({
-            url: data.url, type: 'jpg'
+            url: data.url,
+            type: 'jpg'
         }, (err, texture) => {
             if (err === undefined || err === null) {
                 this.avatar.spriteFrame = new cc.SpriteFrame(texture);
@@ -54,4 +47,4 @@ cc.Class({
     }
 
     // update (dt) {},
-});
+});