| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- item: cc.Prefab,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- // console.log("排行页面看见");
- },
- //排行榜
- start() {
- this.typelist = 2;
- let ranklist = this.ranklist = UtilsPrefabs.getNode("ranklist", this.node);
- //左面
- let ranklist_back = this.ranklist_back = UtilsPrefabs.getNode("ranklist_back", this.node);
- //右面
- let ranklist_next = this.ranklist_next = UtilsPrefabs.getNode("ranklist_next", this.node);
- // let NewButton = UtilsPrefabs.getNode("New Button", this.node);
- // var i = "https://ss0.bdstatic.com/" +
- // "70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/" +
- // "u=3356744803,2445309553&fm=26&gp=0.jpg"
- // utils.loadHttpSpriteFrame(i, NewButton.getComponent(cc.Sprite));
- // item/ranklist_bg
- //返回到结算页面
- let backbutton = this.backbutton = UtilsPrefabs.getNode("backbutton", this.node);
- UtilsPrefabs.setOn(ranklist_back, function () {
- this.ranklist_backCallback();
- }.bind(this));
- UtilsPrefabs.setOn(ranklist_next, function () {
- this.ranklist_nextCallback();
- }.bind(this));
- UtilsPrefabs.setOn(this.backbutton, function () {
- if (this.backButtonClick != null) {
- this.backButtonClick();
- }
- }.bind(this));
- this.listDataPage = 0;
- this.morePagea = 1;
- this.listDataPageCout = 5;
- this.setListData();
- this.checkRankListCount();
- },
- //检查 排行榜长度如果不够长 就不显示下一页
- checkRankListCount : function(){
- //左右按钮 如果小于 每页 规定的 数字 就不显示
- if (RankingListData.listdata1.length<=this.listDataPageCout) {
- this.ranklist_next.active = false;
- this.ranklist_back.active = false;
- }
- let ranklist_bg = UtilsPrefabs.getNode("ranklist_bg", this.node);
- this.checkRanking(RankingListData.myRank,ranklist_bg);
- this.setItemData(RankingListData.myRank,ranklist_bg);
- },
- setbackButtonClickListeniner : function (backButtonClick) {
- this.backButtonClick = backButtonClick;
- },
- backButtonClick : function () {
- },
- ranklist_backCallback: function () {
- this.addCurr(false);
- },
- ranklist_nextCallback: function () {
- this.addCurr(true);
- },
- setListData: function () {
- this.listDataPagearr = [];
- let tempArr = [];
- let tempi = 0;
- for (var i = 0; i < RankingListData.listdata1.length; i++) {
- tempArr.push(RankingListData.listdata1[i]);
- if (tempArr.length >= this.listDataPageCout || i == RankingListData.listdata1.length-1) {
- this.listDataPagearr.push(tempArr);
- tempArr = [];
- }
- // console.log("计数",tempArr ,tempArr.length);
- }
- // console.log("分段数组是什么",this.listDataPagearr);
- // let tag = true;
- //
- // let tempArr = [];
- // while (tag){
- // temp.list[x]
- // }
- //
- this.setItemDataList(this.listDataPage);
- this.isShowButton();
- },
- setItemDataList : function(page){
- for (var i = 0; i <this.ranklist.children.length ; i++) {
- this.ranklist.children[i].destroy();
- }
- for (var i = 0; i < this.listDataPagearr[page].length; i++) {
- let temp = this.listDataPagearr[page][i];
- let x = i;
- // UtilsPrefabs
- // .init(this.ranklist)
- // .addPrefabsName("item/ranklist_bg", null, x, function (node) {
- let item = this.getItem(this.ranklist);
- this.checkRanking(temp,item);
- this.setItemData(temp,item);
- // }.bind(this));
- }
- },
- getItem : function(layout){
- let node = cc.instantiate(this.item);
- node.parent = layout;
- return node;
- },
- checkRanking: function (data,node) {
- let Medal = UtilsPrefabs.getNode("Medal", node);
- // console.log("都有啥" ,Medal);
- let ranklist_gold = UtilsPrefabs.getNode("ranklist_gold", Medal);
- let ranklist_silver = UtilsPrefabs.getNode("ranklist_silver", Medal);
- let ranklist_copper = UtilsPrefabs.getNode("ranklist_copper", Medal);
- let num = UtilsPrefabs.getNode("num", Medal);
- ranklist_gold.active = false;
- ranklist_silver.active = false;
- ranklist_copper.active = false;
- if (num!=null) {
- num.active = false;
- }
- switch (data.rank) {
- case 1:
- ranklist_gold.active = true;
- break;
- case 2:
- ranklist_silver.active = true;
- break;
- case 3:
- ranklist_copper.active = true;
- break;
- default:
- if (num!=null) {
- num.active = true;
- num.getComponent(cc.Label).string = data.rank;
- }
- break;
- }
- },
- setItemData : function (data,node) {
- let ranklist_ic = UtilsPrefabs.getNode("ranklist_ic", node);
- let playername = UtilsPrefabs.getNode("playername", node);
- let Score = UtilsPrefabs.getNode("Score", node);
- // ranklist_ic.width = 76;
- // ranklist_ic.height = 76;
- utils.loadHttpSpriteFrame(data.portraits, ranklist_ic.getComponent(cc.Sprite));
- // console.log("你把个时候",ranklist_ic);
- playername.getComponent(cc.Label).string = data.nickName;
- Score.getComponent(cc.Label).string = data.score;
- },
- //增加或者减少 索引的时候
- addCurr : function(b){
- // console.log("增加 减少",b,"当前索引",this.curr,"总长度是",this.listview.children.length);
- if (b) {
- if (this.listDataPage < this.listDataPagearr.length-1) {
- this.listDataPage++;
- }
- if (this.listDataPage == this.listDataPagearr.length-1) {
- utils.isMobile(function () {
- this.morePagea++;
- Manager.getRanking( this.typelist,this.morePagea,0,10)
- }.bind(this));
- }
- }else{
- if (this.listDataPage > 0) {
- this.listDataPage--;
- }
- }
- this.setItemDataList(this.listDataPage);
- this.isShowButton();
- },
- //是否显示 上一页或者下一页的 按钮
- isShowButton : function(){
- // console.log("现在是",this.listDataPage);
- if (this.listDataPage == 0) {
- this.ranklist_back.active = false;
- this.ranklist_next.active = true;
- }else if (this.listDataPage == this.listDataPagearr.length-1) {
- this.ranklist_back.active = true;
- this.ranklist_next.active = false;
- }else{
- this.ranklist_back.active = true;
- this.ranklist_next.active = true;
- }
- },
- // update (dt) {},
- });
|