const JobPageType = require('../utils/GameEnum').JobPageType;
const GameModel = require('../utils/GameModule');
const DWTool = require('../utils/DWTool');
cc.Class({
extends: cc.Component,
properties: {
iconSprite: cc.Sprite,
firstSprite: cc.Sprite,
firstText: cc.RichText,
secondSprite: cc.Sprite,
secondText: cc.RichText,
},
// onLoad () {},
start() {
},
setConfirmButton(button) {
this.button = button;
},
bindData(type) {
let leftIcon = '';
let secondIcon = '';
if (type === JobPageType.ChangeJob) {
leftIcon = './job/change_job_consume_icon';
secondIcon = './job/change_job_card';
this.secondText.string = '转职卡(0/15)';
} else {
leftIcon = './job/level_up_consume_icon';
secondIcon = './job/level_up_consume_actor';
this.secondText.string = '转职卡(0/15)';
}
cc.loader.loadRes(leftIcon, cc.SpriteFrame, (error, spriteFrame) => {
this.iconSprite.spriteFrame = spriteFrame;
});
cc.loader.loadRes(secondIcon, cc.SpriteFrame, (error, spriteFrame) => {
this.secondSprite.spriteFrame = spriteFrame;
});
},
bindChangeJob(gold, cardInfo, pack) {
let color = '#ffffff';
if (gold <= GameModel.userInfo.grossIncome) {
color = '#ffffff';
} else {
color = '#f33e35';
}
let coinNumber = DWTool.coinParse(gold);
this.firstText.string = `${coinNumber}`;
let cardCount = 0;
if (pack && pack.length > 0) {
cardCount = pack[0].count;
}
this.secondText.string = this.stringFormat(cardInfo.name, cardCount, cardInfo.number);
cc.loader.loadRes('./job/change_job_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
this.iconSprite.spriteFrame = spriteFrame;
});
cc.loader.loadRes('./job/change_job_card', cc.SpriteFrame, (error, spriteFrame) => {
this.secondSprite.spriteFrame = spriteFrame;
});
},
bindDataLevelUp(gold, cardInfo, pack) {
let color = '#ffffff';
if (gold <= GameModel.userInfo.grossIncome) {
color = '#ffffff';
} else {
color = '#f33e35';
}
let coinNumber = DWTool.coinParse(gold);
this.firstText.string = `${coinNumber}`;
let cardCount = 0;
if (pack && pack.length > 0) {
cardCount = pack[0].count;
}
this.secondText.string = this.stringFormat(cardInfo.name, cardCount, cardInfo.number);
cc.loader.loadRes('./job/level_up_consume_icon', cc.SpriteFrame, (error, spriteFrame) => {
this.iconSprite.spriteFrame = spriteFrame;
});
cc.loader.loadRes('./job/level_up_card', cc.SpriteFrame, (error, spriteFrame) => {
this.secondSprite.spriteFrame = spriteFrame;
});
},
stringFormat(name, pack, consume) {
this.button.interactable = pack >= consume;
let color = consume > pack ? '#f33e35' : '#ffffff'
return `${name}(${pack}/${consume})`;
},
// update (dt) {},
});