pubgv3/assets/scripts/UI/userinfo/UIRoleInfo.js
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

228 lines
6.3 KiB
JavaScript

var gameConfig = require("gameConfig");
var Utils = require("Utils");
cc.Class({
extends: cc.Component,
properties: {
lb_total_kills: {
default: null,
type: cc.Label,
},
lb_game_times: {
default: null,
type: cc.Label,
},
lb_win_times: {
default: null,
type: cc.Label,
},
lb_win_rate: {
default: null,
type: cc.Label,
},
lb_max_kills: {
default: null,
type: cc.Label,
},
lb_avg_kills: {
default: null,
type: cc.Label,
},
lb_max_damage_out: {
default: null,
type: cc.Label,
},
lb_avg_damage_out: {
default: null,
type: cc.Label,
},
lb_saiji: {
default: null,
type: cc.Label,
},
lb_name: {
default: null,
type: cc.Label,
},
lb_lv: {
default: null,
type: cc.Label,
},
lb_nowrank: {
default: null,
type: cc.Label,
},
lb_maxrank: {
default: null,
type: cc.Label,
},
sp_nowrank: {
default: null,
type: cc.Sprite,
},
sp_maxrank: {
default: null,
type: cc.Sprite,
},
sp_head: {
default: null,
type: cc.Sprite,
},
sp_headkuang: {
default: null,
type: cc.Sprite,
},
spine_hero: {
default: null,
type: sp.Skeleton,
},
pr_progress: {
default: null,
type: cc.ProgressBar,
},
nd_star: {
default: null,
type: cc.Node,
},
pb_set: {
default: null,
type: cc.Prefab,
},
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
cc.Notifier.on(
"refreshBaseInfo",
this,
this.refreshBaseInfo.bind(this)
);
},
onDestroy() {
cc.Notifier.off("refreshBaseInfo", this);
},
refreshBaseInfo() {
var pdata = cc.playerData;
if (this.nowheadid != pdata.head_id) {
this.nowheadid = pdata.head_id;
this.refrshhead(pdata.head_id);
}
if (this.nowheroid != pdata.hero_id) {
this.nowheroid = pdata.hero_id;
this.refreshhero(pdata.hero_id);
}
if (this.kuandid != pdata.head_frame) {
this.kuandid = pdata.head_frame;
this.refreshkuang(pdata.head_frame);
}
},
start() {},
refrshhead(headid) {
Utils.setitem(this, headid, this.sp_head);
},
refreshkuang(kuangid) {
Utils.setitem(this, kuangid, this.sp_headkuang);
},
refreshhero(v) {
var skinres = cc.playerData.getheroSkinbyId(v, 0);
cc.loader.loadRes(
"spine/heropic/pic_hero" + skinres,
sp.SkeletonData,
function (err, sp) {
this.spine_hero.skeletonData = sp;
this.spine_hero._updateSkeletonData();
this.spine_hero.setAnimation(0, "animation", true);
}.bind(this)
);
},
initdata(v) {
var nowsaiji = v.history_seasons[v.history_seasons.length - 1];
this.lb_total_kills.string = nowsaiji.total_kills;
this.lb_game_times.string = nowsaiji.game_times;
this.lb_win_times.string = nowsaiji.win_times;
this.lb_win_rate.string = nowsaiji.win_rate + "%";
this.lb_max_kills.string = nowsaiji.max_kills;
this.lb_avg_kills.string = nowsaiji.avg_kills;
this.lb_max_damage_out.string = nowsaiji.max_damage_out;
this.lb_avg_damage_out.string = nowsaiji.avg_damage_out;
this.lb_saiji.string = "S" + nowsaiji.season_id;
this.lb_name.string = v.name;
this.lb_lv.string = "LV." + v.level;
var rankcfg1 = gameConfig.rank[v.current_rank];
var rankcfg2 = gameConfig.rank[v.history_best_rank];
this.lb_nowrank.string = rankcfg1.desc;
this.lb_maxrank.string = rankcfg2.desc;
cc.loader.loadRes(
"textures/rankIcon/" + rankcfg1.icon,
cc.SpriteFrame,
function (err, res) {
if (!err && this.isValid) {
this.sp_nowrank.spriteFrame = res;
}
}.bind(this)
);
cc.loader.loadRes(
"textures/rankIcon/" + rankcfg2.icon,
cc.SpriteFrame,
function (err, res) {
if (!err && this.isValid) {
this.sp_maxrank.spriteFrame = res;
}
}.bind(this)
);
this.refrshhead(v.head_id);
this.refreshkuang(v.head_frame);
this.refreshhero(v.hero_id);
this.pr_progress.progress = v.exp / v.max_exp;
this.theStar(
Number(nowsaiji.star_kills) / 100,
Number(nowsaiji.star_damage) / 100,
Number(nowsaiji.star_alive) / 100,
Number(nowsaiji.star_recover) / 100,
Number(nowsaiji.star_win) / 100
);
},
onclose() {
this.node.destroy();
},
theStar(r1, r2, r3, r4, r5) {
var temp = [r1, r2, r3, r4, r5];
console.log(temp);
var leng = 108 / 2;
var ctx = this.nd_star.getComponent(cc.Graphics);
for (var i = 0; i < 5; i++) {
let dir = cc.v2(
Math.cos((-i * 72 + 90) * (Math.PI / 180)),
Math.sin((-i * 72 + 90) * (Math.PI / 180))
);
dir = dir.normalize();
let pos = cc.v2(dir.x * temp[i] * leng, dir.y * temp[i] * leng);
if (i == 0) {
ctx.moveTo(pos.x, pos.y);
} else {
ctx.lineTo(pos.x, pos.y);
}
}
ctx.close();
ctx.stroke();
ctx.fill();
},
callset() {
var nd = cc.instantiate(this.pb_set);
this.node.addChild(nd);
},
// update (dt) {},
});