190 lines
6.0 KiB
JavaScript
190 lines
6.0 KiB
JavaScript
import GameModel from "../ts/core/GameModel";
|
|
import GameUtil from "../ts/core/GameUtil";
|
|
import ItemUtil from "../ts/core/ItemUtil";
|
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|
import SkillUtil from "../ts/game/skill/core/SkillUtil";
|
|
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
|
|
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
listContent: cc.Node,
|
|
listItem: cc.Prefab,
|
|
typeNode: cc.Node,
|
|
xiedaiLab: cc.Label,
|
|
discriptionLab: cc.Label,
|
|
nameLab: cc.Label,
|
|
rateLab: cc.Label,
|
|
hpLab: cc.Label,
|
|
mpLab: cc.Label,
|
|
atkLab: cc.Label,
|
|
spdLab: cc.Label,
|
|
|
|
tipNode: cc.Node,
|
|
buzhuoBtn: cc.Node,
|
|
hechengBtn: cc.Node,
|
|
hechengPre: cc.Prefab,
|
|
activityGetBtn: cc.Node,//活動獲得
|
|
skillNode: cc.Node,
|
|
selectTypeNode: cc.Node
|
|
},
|
|
|
|
onLoad() {
|
|
this.curPetInfo = null;
|
|
this.selectTypeNode.on("click", this.tapTypeTip, this);
|
|
this.loadPetList();
|
|
},
|
|
|
|
loadPetList(grade = -1) {
|
|
let curListY = -40;
|
|
let curListX = -80;
|
|
this.listContent.destroyAllChildren();
|
|
for (const key in GameModel.conf_pet) {
|
|
if (key == 'datatype') {
|
|
continue;
|
|
}
|
|
if ((grade > -1 && grade < 3 && grade != GameModel.conf_pet[key].classify))
|
|
continue;
|
|
if ((grade == 3 && GameModel.conf_pet[key].classify < 3))
|
|
continue;
|
|
let itemInfo = SKDataUtil.clone(GameModel.conf_pet[key]);
|
|
let item = cc.instantiate(this.listItem);
|
|
item.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon(itemInfo.resid);
|
|
item.getChildByName('level').getComponent(cc.Label).string = itemInfo.xiedailevel;
|
|
item.getChildByName('level').color = GameUtil.getReliveColor(itemInfo.xiedairelive);
|
|
if (GameModel.player.level >= itemInfo.xiedailevel && GameModel.player.relive >= itemInfo.xiedairelive) {
|
|
item.getChildByName('level').active = false;
|
|
} else {
|
|
item.getChildByName('mask').active = true;
|
|
}
|
|
item.active = true;
|
|
item.x = curListX;
|
|
item.y = curListY;
|
|
curListX += 80;
|
|
if (curListX > 80) {
|
|
curListX = -80;
|
|
curListY -= 80;
|
|
}
|
|
item.parent = this.listContent;
|
|
item.petid = key;
|
|
item.on("toggle", () => {
|
|
this.petItemClicked(item)
|
|
}, this)
|
|
if (this.curPetInfo == null) {
|
|
this.curPetInfo = itemInfo;
|
|
item.getComponent(cc.Toggle).isChecked = true;
|
|
this.showPetInfo();
|
|
}
|
|
}
|
|
if (curListX > -80) {
|
|
curListY -= 80;
|
|
}
|
|
this.listContent.height = -curListY;
|
|
if (this.listContent.height < this.listContent.parent.height) {
|
|
this.listContent.height = this.listContent.parent.height;
|
|
}
|
|
},
|
|
|
|
selectGradeList(e, level) {
|
|
// level: 0全部 1普通 2高級 3特殊 4神獸和特殊神獸
|
|
// json : 0普通 1高級 2特殊 3神獸 4特殊神獸
|
|
cc.find("typeList", this.selectTypeNode).active = false;
|
|
this.curPetInfo = null;
|
|
this.loadPetList(level - 1)
|
|
},
|
|
tapTypeTip() {
|
|
cc.find("typeList", this.selectTypeNode).active = true;
|
|
},
|
|
showPetInfo() {
|
|
this.curPetInfo.rate = JSON.parse(this.curPetInfo.rate);
|
|
this.curPetInfo.hp = JSON.parse(this.curPetInfo.hp);
|
|
this.curPetInfo.mp = JSON.parse(this.curPetInfo.mp);
|
|
this.curPetInfo.atk = JSON.parse(this.curPetInfo.atk);
|
|
this.curPetInfo.spd = JSON.parse(this.curPetInfo.spd);
|
|
for (let index = 0; index < 5; index++) {
|
|
this.typeNode.getChildByName(index + '').active = false;
|
|
}
|
|
this.node.getChildByName('UIRole').getComponent('UIRole').setInfo({ resid: this.curPetInfo.resid, name: '' });
|
|
|
|
this.typeNode.getChildByName(this.curPetInfo.grade + '').active = true;
|
|
this.nameLab.string = this.curPetInfo.name;
|
|
GameUtil.setReliveLabel(this.xiedaiLab, 1, this.curPetInfo.xiedairelive, this.curPetInfo.xiedailevel);
|
|
|
|
this.rateLab.string = this.curPetInfo.rate[0] + ' - ' + this.curPetInfo.rate[1];
|
|
this.hpLab.string = this.curPetInfo.hp[0] + ' - ' + this.curPetInfo.hp[1];
|
|
this.mpLab.string = this.curPetInfo.mp[0] + ' - ' + this.curPetInfo.mp[1];
|
|
this.atkLab.string = this.curPetInfo.atk[0] + ' - ' + this.curPetInfo.atk[1];
|
|
this.spdLab.string = this.curPetInfo.spd[0] + ' - ' + this.curPetInfo.spd[1];
|
|
|
|
this.discriptionLab.string = this.curPetInfo.intro;
|
|
|
|
this.tipNode.active = false;
|
|
this.buzhuoBtn.active = false;
|
|
this.hechengBtn.active = false;
|
|
this.activityGetBtn.active = false;
|
|
if (GameModel.player.level >= this.curPetInfo.xiedailevel && GameModel.player.relive >= this.curPetInfo.xiedairelive) {
|
|
if (this.curPetInfo.gettype == 1) {
|
|
if (this.activityGet(this.curPetInfo.id))
|
|
this.activityGetBtn.active = true
|
|
else
|
|
this.hechengBtn.active = true;
|
|
} else {
|
|
this.buzhuoBtn.active = true;
|
|
}
|
|
} else {
|
|
this.tipNode.active = true;
|
|
this.tipNode.getChildByName('level').getComponent(cc.Label).string = this.xiedaiLab.string;
|
|
}
|
|
|
|
this.skillNode.active = false;
|
|
if (this.curPetInfo.skill > 0) {
|
|
this.skillNode.active = true;
|
|
this.skillNode.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = SkillUtil.getSkillIcon(this.curPetInfo.skill);
|
|
let btn = this.skillNode.getComponent(cc.Button);
|
|
let handle = btn.clickEvents[0];
|
|
handle.customEventData = this.curPetInfo.skill;
|
|
}
|
|
},
|
|
activityGet(id) {
|
|
let list = [1052,1053,1054,1057,1058,1061,1062,1063,1064,1069,1070,1071,1072,1073,1074,1075];
|
|
for (let i in list) {
|
|
if (id == list[i]) return true;
|
|
}
|
|
return false
|
|
},
|
|
tipActivityGet() {
|
|
MsgAlert.addMsg("需通過活動獲得");
|
|
},
|
|
petItemClicked(e, d) {
|
|
if (e.getComponent(cc.Toggle).isChecked) {
|
|
let petid = Number(e.petid);
|
|
this.curPetInfo = SKDataUtil.clone(GameModel.conf_pet[petid]);
|
|
this.showPetInfo();
|
|
}
|
|
},
|
|
|
|
buzhuoBtnClicked(e, d) {
|
|
if (!GameModel.player.itemList[10001]) {
|
|
MsgAlert.addMsg("引妖香不足");
|
|
} else {
|
|
ItemUtil.useItem(10001);
|
|
let logic = this.node.parent.getComponent('PetPanel');
|
|
if (SKUIUtil.isValid(logic)) {
|
|
logic.destroy();
|
|
}
|
|
}
|
|
},
|
|
|
|
clear() {
|
|
let uirolenode = this.node.getChildByName('UIRole');
|
|
uirolenode.getComponent('UIRole').clear();
|
|
},
|
|
|
|
hechengBtnClicked(e, d) {
|
|
let hecheng = cc.instantiate(this.hechengPre);
|
|
hecheng.parent = this.node.parent;
|
|
},
|
|
});
|