SamsaraGame/assets/Script/panel/XianQiUpPanel.js
2025-04-24 17:03:28 +08:00

229 lines
5.7 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import ItemUtil from "../ts/core/ItemUtil";
import Report from "../ts/gear_2.3.4/net/Report";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
cc.Class({
extends: cc.Component,
properties: {
listContent: cc.Node,
useEquipNodes: [cc.Node],
nextEquipNode: cc.Node,
listItem: cc.Node,
upgradeNode: cc.Node,
tipsNode: cc.Node,
},
ctor() {
this.issend = false;
},
showNextEquipInfo(info) {
this.nextEquipNode.getComponent('EquipItem').loadInfo(info);
},
loadEquipList() {
for (let item of this.useEquipNodes) {
item.getComponent('EquipItem').reset();
item.equiptag = 0;
}
this.nextEquipNode.getComponent('EquipItem').reset();
this.selectedCnt = 0;
this.curInfo = null;
let hadXianqi = false;
let curListY = -40;
let curListX = -80;
//this.listContent.destroyAllChildren();
this.listContent.removeAllChildren();
this.upgradeNode.active = false;
this.tipsNode.active = false;
if (!GameModel.equipData || !GameModel.equipData.info) {
this.tipsNode.active = true;
let tips = this.tipsNode.getChildByName('tips');
if (tips) {
let label = tips.getComponent(cc.Label);
if (label) {
label.string = '你還沒有仙器哦';
} else {
cc.warn(`仙器升級面板:tips不是文本!`);
}
} else {
cc.warn(`仙器升級面板:找不到tips!`);
}
return;
}
let equipList = {};
for (const equip of GameModel.equipData.list) {
if (GameModel.equipData.info[equip]) {
equipList[equip] = GameModel.equipData.info[equip];
};
}
console.log(equipList)
for (const key in equipList) {
let itemInfo = equipList[key];
if (itemInfo.EquipType != 3) {
continue;
}
let item = cc.instantiate(this.listItem);
if (!SKUIUtil.isValid(item)) {
cc.warn(`仙器面板,道具節點無效${this.listItem}!`);
continue;
}
let icon = item.getChildByName("icon");
if (icon) {
let sprite = icon.getComponent(cc.Sprite);
if (sprite) {
sprite.spriteFrame = ItemUtil.getItemIconBy(itemInfo);
} else {
cc.warn(`仙器面板,道具圖標精靈不存在!`);
}
} else {
cc.warn(`仙器面板,道具圖標節點不存在!`);
}
let level = item.getChildByName("level");
if (level) {
let label = level.getComponent(cc.Label);
if (label) {
label.string = itemInfo.Grade;
} else {
cc.warn(`仙器面板,道具等級label不存在!`);
}
} else {
cc.warn(`仙器面板,道具等級節點不存在!`);
}
item.active = true;
item.x = curListX;
item.y = curListY;
curListX += 80;
if (curListX > 80) {
curListX = -80;
curListY -= 80;
}
item.parent = this.listContent;
item.equiptag = key;
hadXianqi = true;
}
if (curListX > -80) {
curListY -= 80;
}
this.listContent.height = -curListY;
if (this.listContent.height < this.listContent.parent.height) {
this.listContent.height = this.listContent.parent.height;
}
if (!hadXianqi) {
this.tipsNode.active = true;
this.tipsNode.getChildByName('tips').getComponent(cc.Label).string = '你還沒有仙器哦';
return;
}
this.upgradeNode.active = true;
this.issend = false;
},
getNextEquipInfo() {
if (this.curInfo && this.curInfo.NextType > 0) {
let params = {
resid: this.curInfo.NextType,
type: this.curInfo.EquipType,
index: this.curInfo.EIndex,
grade: this.curInfo.Grade + 1,
roleid: Report.roleId
};
GameModel.send('c2s_next_equip', params);
} else {
return;
}
},
equipItemClicked(e, d) {
if (!e.target.getComponent(cc.Toggle).isChecked) {
for (let index = 0; index < this.useEquipNodes.length; index++) {
const item = this.useEquipNodes[index];
if (item.equiptag == e.target.equiptag) {
if (index == 0) {
this.nextEquipNode.getComponent('EquipItem').reset();
}
item.getComponent('EquipItem').reset();
item.equiptag = 0;
if (this.selectedCnt > 0) {
this.selectedCnt--;
}
if (this.selectedCnt == 0) {
this.curInfo = null;
}
return;
}
}
return;
}
if (this.selectedCnt >= 3 || (this.curInfo && this.curInfo.Grade > 1 && this.selectedCnt >= 3)) {
e.target.getComponent(cc.Toggle).isChecked = false;
return;
}
let selectedInfo = GameModel.equipData.info[e.target.equiptag];
console.log(selectedInfo)
//仙器階數是否滿足升級要求 新增五階仙器
if (selectedInfo.Grade >= 5 || (this.curInfo != null && this.curInfo.Grade != selectedInfo.Grade)) {
e.target.getComponent(cc.Toggle).isChecked = false;
return;
}
if (this.curInfo != null && this.curInfo.EName != selectedInfo.EName) {
e.target.getComponent(cc.Toggle).isChecked = false;
return;
}
let emptyPos = -1;
for (let index = 0; index < this.useEquipNodes.length; index++) {
const item = this.useEquipNodes[index];
if (item.equiptag == 0) {
emptyPos = index;
break;
}
}
if (emptyPos >= 0) {
this.useEquipNodes[emptyPos].getComponent('EquipItem').loadInfo(selectedInfo);
this.useEquipNodes[emptyPos].equiptag = e.target.equiptag;
if (emptyPos == 0) {
this.curInfo = selectedInfo;
this.getNextEquipInfo();
}
this.selectedCnt++;
}
},
upgradeBtnClicked(e, d) {
if (!this.curInfo) {
return;
}
if (this.curInfo.Grade == 1 && this.selectedCnt < 3) {
return;
}
// 避免多次點擊
if (this.issend == true) {
return;
}
this.issend = true;
// for(let i = 0; i < 10; i++){
GameModel.send('c2s_xianqi_upgrade', {
roleid: Report.roleId,
equipid: this.curInfo.EquipID,
use1: this.useEquipNodes[1].equiptag,
use2: this.useEquipNodes[2].equiptag
});
// }
this.curInfo = null;
this.nextEquipInfo = null;
},
onCloseBtnClicked(e, d) {
this.node.destroy();
}
});