cc.Class({ extends: cc.Component, properties: { content: cc.Node, prefab: cc.Prefab, prefabme: cc.Prefab, GoldMedal: cc.SpriteFrame, SilverMedal:cc.SpriteFrame, BronzeMedal:cc.SpriteFrame, }, onLoad() { this.nodes = []; this.ranklist = cc.find("Canvas/ranklist"); this.info = cc.find("Canvas/info"); // this.Transcend = UtilsPrefabs.getNode("Transcend",cc.find("Canvas")); // this.animCtrl = this.Transcend.getComponent("cc.Animation"); // console.log("动画组件紫玉到底有没有",this.Transcend); // // // // if (this.animCtrl!=null) { // this.animCtrl.on('finished', this.finished,this); // } // this.canvasAdopt(); }, finished : function(){ // console.log("动画回调了吗",this.Transcendnode); if (this.Transcendnode != null) { this.Transcendnode.active = false; } }, canvasAdopt() { // 适配解决方案 let canvas = cc.director.getScene().getChildByName('Canvas').getComponent(cc.Canvas) // 设计分辨率比 let rateR = canvas.designResolution.height/canvas.designResolution.width; // 显示分辨率比 let rateV = cc.view.getVisibleSize().height / cc.view.getVisibleSize().width; console.log("winSize: rateR: " + rateR + " rateV: " + rateV); if (rateV > rateR) { canvas.fitHeight = false; canvas.fitWidth = true; console.log("winSize: fitWidth"); } else { canvas.fitHeight = true; canvas.fitWidth = false; console.log("winSize: fitHeight"); } }, getFriend : function(){ this.removeAll(); if (cc.sys.platform === cc.sys.WECHAT_GAME){ wx.getFriendCloudStorage({ keyList: ['score'], success: function (res) { // console.log("朋友数据是",res.data); // console.log("我的数据是",userData.openId); // console.log(res.data[0].KVDataList[0].value); // for (let i = 0; i < res.data.length; i++) { // let friendInfo = res.data[i]; // if (!friendInfo) { // _self.createPrefab(); // continue; // } // _self.createUserBlock(friendInfo,i); // } //添加排行榜为 自己的条目在下面 this.testListView(this.initData(res.data)); this.addMyItem(); }.bind(this), fail: function (res) { console.error(res); }.bind(this) }); // console.log("自己的"); // this.testListView(); } else{ this.testListView(this.initData(null)); //添加排行榜为 自己的条目在下面 this.addMyItem(); } }, removeAll : function(){ for (var i = 0; i { if (err) console.error(err); ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture); }); setTimeout(function () { this.info.active = false; }.bind(this),4000) }, setleftmidrightRankListData : function(listdata){ // console.log("进来的数据是",listdata); this.closeRanklist(); // console.log("我在统计数组5",listdata); this.ranklist.active = true; for (var i = 0; i { if (err) console.error(err); ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture); }); } } this.ranklist.getChildByName("sub").on(cc.Node.EventType.TOUCH_END, function (event) { this.closeRanklist(); }.bind(this)); setTimeout(function () { this.closeRanklist(); }.bind(this),5000) }, closeRanklist : function(){ for (var i = 0; i { if (err) console.error(err); userIcon.spriteFrame = new cc.SpriteFrame(texture); }); }, setItemDataB : function(b){ let nickName = b.name; let avatarUrl = b.avatarUrl; let ScoreValue = b.id; // console.log("ScoreValue="+ScoreValue); this.Transcendnode = UtilsPrefabs.getNode("Transcend",cc.find("Canvas")); var Other = UtilsPrefabs.getNode("Other",this.Transcendnode); var block = UtilsPrefabs.getNode("block",Other); let userName = block.getChildByName('userName').getComponent(cc.Label); let userIcon = block.getChildByName('mask').children[0].getComponent(cc.Sprite); let Scorelabel = block.getChildByName('Score').getComponent(cc.Label); userName.string = nickName; Scorelabel.string = ScoreValue; // console.log(nickName + '\'s info has been getten.'); cc.loader.load({ url: avatarUrl, type: 'png' }, (err, texture) => { if (err) console.error(err); userIcon.spriteFrame = new cc.SpriteFrame(texture); }); }, onClickItem: function () { }, setOnClickItem: function (onClickItem) { this.onClickItem = onClickItem; }, createUserBlock (user,index) { let node = this.createPrefab(index); // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname. let nickName = user.nickName ? user.nickName : user.nickname; let avatarUrl = user.avatarUrl; let ScoreValue = (user.KVDataList)[0].value; // console.log("ScoreValue="+ScoreValue); let userName = node.getChildByName('userName').getComponent(cc.Label); let userIcon = node.getChildByName('mask').children[0].getComponent(cc.Sprite); let Scorelabel = node.getChildByName('Score').getComponent(cc.Label); userName.string = nickName; Scorelabel.string = ScoreValue; // console.log(nickName + '\'s info has been getten.'); cc.loader.load({ url: avatarUrl, type: 'png' }, (err, texture) => { if (err) console.error(err); userIcon.spriteFrame = new cc.SpriteFrame(texture); }); }, createPrefab (index) { let node = cc.instantiate(this.prefab); node.parent = this.content; this.nodes.push(node); switch (index) { case 0: node.spriteFrame=this.GoldMedal; break; case 1: node.spriteFrame=this.SilverMedal; break; case 2: node.spriteFrame=this.BronzeMedal; break; } return node; }, initcreateUserInfo : function(listdata,node){ cc.loader.loadRes(UtilsPrefabs.PrefabsName[6], function (err, texture) { this.itemprefab = cc.instantiate(texture); for (let i = 0; i < listdata.listData.length; i++) { let info = listdata.listData[i]; var StockSort = UtilsPrefabs.getNode("StockSort",node); var ScrollView = UtilsPrefabs.getNode("ScrollView",StockSort); var view = UtilsPrefabs.getNode("view",ScrollView); var content = UtilsPrefabs.getNode("content",view); this.createUserInfo(info,i,content); } }.bind(this)); }, createUserInfo (user,index,nodes) { var itemnode = cc.instantiate(this.itemprefab); nodes.addChild(itemnode); var Layout = UtilsPrefabs.getNode("Layout",itemnode); var Name = UtilsPrefabs.getNode("Name",Layout); var Code = UtilsPrefabs.getNode("Code",Layout); var Price = UtilsPrefabs.getNode("Price",Layout); var Fluctuate = UtilsPrefabs.getNode("Fluctuate",Layout); var TotalPossession = UtilsPrefabs.getNode("TotalPossession",Layout); Name.getComponent(cc.Label).string = user.name; Code.getComponent(cc.Label).string = user.id; Price.getComponent(cc.Label).string = user.Price; Fluctuate.getComponent(cc.Label).string = user.Fluctuate; TotalPossession.getComponent(cc.Label).string = user.TotalPossession; // console.log("来了吗",user,index,nodes); }, // callback: function (button) { // //do whatever you want with button // //另外,注意这种方式注册的事件,也无法传递 customEventData // console.log("111111111111111111111111111111111"); // } // callback: function (event, customEventData) { // //这里 event 是一个 Touch Event 对象,你可以通过 event.target 取到事件的发送节点 // var node = event.target; // var button = node.getComponent(cc.Button); // //这里的 customEventData 参数就等于你之前设置的 "foobar" // console.log("111111111111111111111111111111111"); // } });