2020-08-07 20:44:32 +08:00

134 lines
4.5 KiB
JavaScript

var NodeBase = require('nodeBase');
let pbRank = require('pbRank');
let Config = require('config');
let Util = require('util');
const i18n = require('LanguageData');
cc.Class({
extends: NodeBase,
properties: {
nd_Score: cc.Node,
pb_rank: cc.Prefab,
rankSelf: cc.Label,
scoreSelf: cc.Label,
selfRankNode: cc.Node,
openRankNode: cc.Node,
btnWechat: cc.Node,
btnWorld: cc.Node,
worldRankView: cc.Node,
btnBgs: [cc.Node],
selfRank: pbRank,
shareBtn: cc.Node,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
i18n.init(cc.jcLanguage, 'en');
this.shareBtn.active = cc.jc.channelID !== cc.jc.channel.ANDROID
if (cc.jc.channelID === cc.jc.channel.TT || cc.jc.channelID === cc.jc.channel.TEST || cc.jc.channelID === cc.jc.channel.ANDROID) {
this.showWorldRank();
this.btnWechat.active = false;
this.btnWorld.active = true;
} else {
this.worldRankView.active = false;
this.selfRank.node.active = false;
this.type = 1;
this.showWchatContext();
}
},
hide(){
this.node.active = false;
(this.closeFun) && this.closeFun()
},
setUP(){
this.nd_Score.removeAllChildren();
var self = this;
cc.jc.rank.reqRankList(function (records, userRank, userScore) {
for(let i = 0; i< records.length; i++ ) {
var rd = records[i];
rd.rank = i + 1;
var nd = cc.instantiate(self.pb_rank);
var scp = nd.getComponent("pbRank").setData(rd);
self.nd_Score.addChild(nd);
}
if(cc.jc.rank.canShowSelf()){
self.rankSelf.string = userRank > 0 ? (userRank >= 999 ? '999+' : userRank + 1) : '-';
self.scoreSelf.string = '' + userScore;
self.selfRankNode.active = true;
self.selfRank.node.active = true;
self.selfRank.setData({
avatar: cc.jc.rank.avatar_url,
nickname: cc.jc.rank.nickname,
rank: userRank + 1,
score: userScore
});
} else {
self.selfRankNode.active = false;
}
}, function () {
console.log(`error get jc rank list`);
})
},
registerCloseFun(closeFun) {
this.closeFun = closeFun
},
onShareClick() {
let param = {rc: {
x: 0,
y: (cc.winSize.height - cc.winSize.width) / 2,
width: cc.winSize.width,
height: cc.winSize.width
}};
let self = this;
cc.jc.ADShare('rank', param, function (result, errcode, flag, isaderr, isdiff) {
if (result) {
Util.showTips(self.node, '分享成功.');
} else {
if (errcode === -100) {
Util.showTips(self.node, Config.share_fail_txt);
} else {
if (isaderr) {
Util.showTips(self.node, Config.ad_fail_txt);
}
}
}
})
},
showWorldRank: function (e) {
if ((cc.jc.channelID !== cc.jc.channel.TT && cc.jc.channelID !== cc.jc.channel.TEST && cc.jc.channelID !== cc.jc.channel.ANDROID)) {
this.type = 0;
this.openRankNode.active = false;
this.worldRankView.active = true;
this.btnWechat.getComponent(cc.Button).interactable = true;
this.btnWorld.getComponent(cc.Button).interactable = false;
this.btnBgs[0].active = false;
this.btnBgs[1].active = true;
}
if(cc.jc.rank.canShowSelf()) {
this.rankSelf.node.active = true;
this.scoreSelf.node.active = true;
this.selfRank.node.active = true;
}
},
showWchatContext: function (e) {
this.type = 1;
this.openRankNode.active = true;
this.worldRankView.active = false;
this.selfRank.node.active = false;
this.btnWechat.getComponent(cc.Button).interactable = false;
this.btnWorld.getComponent(cc.Button).interactable = true;
this.rankSelf.node.active = false;
this.scoreSelf.node.active = false;
this.btnBgs[1].active = false;
this.btnBgs[0].active = true;
},
update(dt) {
// i18n.updateSceneRenderers();
},
});