SamsaraGame/assets/Script/panel/WingUpdatePanel.js

576 lines
18 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
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 EquipUtil from "../ts/game/equip/EquipUtil";
/**翅膀蓮花面板 */
cc.Class({
extends: cc.Component,
properties: {
titleNodes: [cc.Node],
listContent: cc.Node,
upgradeNode: cc.Node,
refineNode: cc.Node,
inlayNode: cc.Node,
recastNode: cc.Node,
tipsNode: cc.Node,
refinePreNode: cc.Node,
recastPreNode: cc.Node,
equipListItem: cc.Prefab,
shenbingUpPre: cc.Prefab,
xianqiUpPre: cc.Prefab,
},
onLoad() {
this.name = 'WingUpdatePanel';
this.listItems = [];
this.curSelected = null;
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this));
this.nextEquipInfo = null;
this.refineData = null;
this.recastData = null;
this.refineItemId = 0;
this.itemId1 = 10411;
this.loadEquipList();
},
start() {
},
reloadListData(info) {
for (let index = 0; index < this.listItems.length; index++) {
if (this.listItems[index].getComponent('EquipListItem').iteminfo.EquipID == info.EquipID) {
this.listItems[index].getComponent('EquipListItem').loadInfo(info);
if (this.listItems[index] == this.curSelected) {
this.showInfo();
}
}
}
},
loadEquipList() {
this.upgradeNode.active = false;
this.refineNode.active = false;
this.inlayNode.active = false;
this.recastNode.active = false;
this.tipsNode.active = false;
let curListY = 0;
this.listContent.destroyAllChildren();
this.listItems = [];
if (!GameModel.equipData || !GameModel.equipData.info) {
return;
}
let list = GameModel.equipData.info;
for (let key in list) {
let itemInfo = list[key];
// 非翅膀不顯示
if (itemInfo.EIndex != 6) {
continue;
}
let item = cc.instantiate(this.equipListItem);
item.x = 0;
item.y = curListY;
curListY -= 90;
item.parent = this.listContent;
item.getComponent('EquipListItem').loadInfo(itemInfo);
if (GameModel.equipData.use[itemInfo.EIndex] == itemInfo.EquipID) {
cc.find('tips', item).active = true;
}
let btn = item.getComponent(cc.Button);
var clickEventHandler = new cc.Component.EventHandler();
clickEventHandler.target = this.node;
clickEventHandler.component = "WingUpdatePanel";
clickEventHandler.handler = "equipItemClicked";
btn.clickEvents.push(clickEventHandler);
this.listItems.push(item);
}
this.listContent.height = -curListY;
if (this.listContent.height < this.listContent.parent.height) {
this.listContent.height = this.listContent.parent.height;
}
if (this.listItems.length < 1) {
return;
}
this.curSelected = this.listItems[0];
this.curSelected.getComponent('EquipListItem').selected();
this.curInfo = this.curSelected.getComponent('EquipListItem').iteminfo;
this.upgradeNode.active = true;
this.showInfo();
},
getNextEquipInfo() {
let resid = 0;
let type = 0;
let grade = 0;
if (this.curInfo.EquipType == 0) {
type = 1;
grade = 1;
} else if ((this.curInfo.EquipType == 1 || this.curInfo.EquipType == 2 || this.curInfo.EquipType == 3) && this.curInfo.NextType > 0) {
resid = this.curInfo.NextType;
type = this.curInfo.EquipType;
grade = this.curInfo.Grade + 1;
} else {
return;
}
GameModel.send('c2s_next_equip', {
resid: resid,
type: type,
index: this.curInfo.EIndex,
grade: grade,
roleid: GameModel.player.roleid
});
},
getRecastInfo() {
let resid = 0;
let type = 0;
let grade = 0;
if (this.curInfo.EquipType == 0 || this.curInfo.EquipType == 2) {
return;
}
else if (this.curInfo.EquipType == 1) {
type = 1;
grade = this.curInfo.Grade;
} else if (this.curInfo.EquipType == 3) {
resid = 0;
type = this.curInfo.EquipType;
grade = this.curInfo.Grade;
} else {
return;
}
GameModel.send('c2s_next_equip', {
resid: resid,
type: type,
index: this.curInfo.EIndex,
grade: grade,
roleid: GameModel.player.roleid
});
},
setCurItem(equipid) {
for (let item of this.listItems) {
let itemInfo = item.getComponent('EquipListItem').iteminfo;
if (itemInfo.EquipID == equipid) {
if (this.curSelected != null) {
this.curSelected.getComponent('EquipListItem').unSelected();
}
this.refineItemId = 0;
this.curSelected = item;
this.curSelected.getComponent('EquipListItem').selected();
this.curInfo = itemInfo;
this.nextEquipInfo = null;
this.showInfo();
if (this.listContent.y + this.listContent.parent.height < -(item.y - 90)) {
this.listContent.y = -this.listContent.parent.height - (item.y - 90);
}
}
}
},
setCurPanel(pos) {
for (let index = 1; index <= 1; index++) {
if (pos == index) {
cc.find(`ToggleGroup/toggle${index}`, this.node).getComponent(cc.Toggle).isChecked = true;
this.panelToggleClicked(null, pos);
} else {
cc.find(`ToggleGroup/toggle${index}`, this.node).getComponent(cc.Toggle).isChecked = false;
}
}
},
showInfo() {
this.curInfo = this.curSelected.getComponent('EquipListItem').iteminfo;
if (!this.curInfo.BaseAttr) {
return;
}
for (let index = 0; index < 1; index++) {
if (cc.find(`ToggleGroup/toggle${index + 1}`, this.node).getComponent(cc.Toggle).isChecked) {
this.panelToggleClicked(null, index + 1);
}
}
this.showPreProperty();
},
showUpgradeInfo() {
this.upgradeNode.getChildByName('EquipItem1').getComponent('EquipItem').loadInfo(this.curInfo);
if (this.nextEquipInfo != null) {
this.upgradeNode.getChildByName('EquipItem2').getComponent('EquipItem').loadInfo(this.nextEquipInfo);
} else {
this.getNextEquipInfo();
}
this.upgradeNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: 10405, count: 1 });
this.upgradeNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[10405] == null ? 0 : GameModel.player.itemList[10405]}/1`;
},
// 顯示材料選擇面板
showRefineInfo() {
this.refineNode.getChildByName('EquipItem').getComponent('EquipItem').loadInfo(this.curInfo);
this.refineNode.getChildByName('tips').getComponent(cc.Label).string = "請先選擇煉化材料";
},
showInlayInfo() {
this.inlayNode.getChildByName('EquipItem').getComponent('EquipItem').loadInfo(this.curInfo);
let gemLevel = Math.floor(this.curInfo.GemCnt / 3) + 1;
this.inlayNode.getChildByName('BagItem').getChildByName('levellab').getComponent(cc.Label).string = `Lv.${gemLevel}`;
let curitemid = EquipUtil.getInlayGemId(this.curInfo.EIndex,this.curInfo.GemCnt);
let curitemcnt = 0;
if (GameModel.player.itemList[curitemid]) curitemcnt = GameModel.player.itemList[curitemid];
this.inlayNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: curitemid, count: curitemcnt });
// if (curitemcnt <= 0) {
// this.inlayNode.getChildByName('BagItem').color = cc.Color.GRAY;
// }
this.inlayNode.getChildByName('gemlist').destroyAllChildren();
let gemX = -(this.curInfo.MaxEmbedGemCnt - 1) * 10;
for (let index = 0; index < this.curInfo.MaxEmbedGemCnt; index++) {
let gem = cc.instantiate(this.inlayNode.getChildByName('gem'));
gem.active = true;
gem.x = gemX + index * 20;
gem.y = 0;
gem.parent = this.inlayNode.getChildByName('gemlist');
if (index < this.curInfo.GemCnt) {
gem.getChildByName(`gem${this.curInfo.EIndex}`).active = true;
}
}
},
showRecastInfo() {
this.recastNode.getChildByName('EquipItem1').getComponent('EquipItem').loadInfo(this.curInfo);
if (this.nextEquipInfo != null) {
this.nextEquipInfo.BaseAttr = {};
this.recastNode.getChildByName('EquipItem2').getComponent('EquipItem').loadInfo(this.nextEquipInfo);
} else {
this.getRecastInfo();
}
// this.recastNode.getChildByName('EquipItem2').getComponent('EquipItem').loadInfo(this.curInfo);
if (this.curInfo.EquipType == 3) {
this.recastNode.getChildByName('itemname').getComponent(cc.Label).string = '悔夢石';
this.recastNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: 10401, count: 1 });
this.recastNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[10401] == null ? 0 : GameModel.player.itemList[10401]}/1`;
}
else {
this.recastNode.getChildByName('itemname').getComponent(cc.Label).string = '盤古精鐵';
this.recastNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: 10405, count: 1 });
this.recastNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[10405] == null ? 0 : GameModel.player.itemList[10405]}/1`;
}
},
showNewProperty(info) {
if (this.refinePreNode.active) {
this.showPropertyInfo(info, this.refinePreNode.getChildByName('new'));
}
else if (this.recastPreNode.active) {
this.showPropertyInfo(info, this.recastPreNode.getChildByName('new'));
}
},
showPreProperty() {
if (this.refinePreNode.active) {
this.showPropertyInfo(this.curInfo.LianhuaAttr, this.refinePreNode.getChildByName('pre'));
}
else if (this.recastPreNode.active) {
this.showPropertyInfo(this.curInfo.BaseAttr, this.recastPreNode.getChildByName('pre'));
}
},
showPropertyInfo(info, node) {
if (!info || info.length == 0) {
info = '{}';
}
node.destroyAllChildren();
this.infoPos = cc.v2(0, 120);
let propertyInfo = JSON.parse(info);
if (Array.isArray(propertyInfo)) {
for (const info of propertyInfo) {
this.addPropertyInfo(info, node);
}
} else {
this.addPropertyInfo(propertyInfo, node);
}
},
addPropertyInfo(propertyInfo, node) {
for (const key in propertyInfo) {
let valuestr = propertyInfo[key]+'';
console.log(valuestr)
if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) {
valuestr = (valuestr > 0 ? '+' : '') + (valuestr / 10).toFixed(1) + '%';
}
else {
valuestr = (valuestr > 0 ? '+' : '') + valuestr;
}
this.addInfoLab(GameUtil.getAttrTypeL1Name(key), valuestr, node);
}
},
addInfoLab(name, value, node) {
let detail = cc.instantiate(this.node.getChildByName('item'));
detail.active = true;
detail.parent = node;
detail.setPosition(this.infoPos);
detail.getChildByName('name').getComponent(cc.Label).string = name;
detail.getChildByName('value').getComponent(cc.Label).string = value;
this.infoPos.y -= 60;
},
equipItemClicked(e, d) {
if (this.curSelected == e.target || !e.target.getComponent('EquipListItem').iteminfo.EName) {
return;
}
this.refineItemId = 0;
if (this.curSelected != null) {
this.curSelected.getComponent('EquipListItem').unSelected();
}
this.curSelected = e.target;
this.curSelected.getComponent('EquipListItem').selected();
this.curInfo = this.curSelected.getComponent('EquipListItem').iteminfo;
this.nextEquipInfo = null;
this.showInfo();
},
/**選擇蓮花材料 */
chooseItemClicked(event, data) {
this.refineNode.getChildByName('itemlist').active = true;
let nameNode = cc.find('itemlist/item1/nameLabel', this.refineNode);
if (nameNode) {
let nameLabel = nameNode.getComponent(cc.Label);
if (nameLabel) {
nameLabel.string = ItemUtil.getItemName(this.itemId1);
}
}
let item1 = cc.find('itemlist/item1/BagItem', this.refineNode);
if (item1) {
let bagItem = item1.getComponent('BagItem');
if (bagItem) {
bagItem.loadInfo({ itemid: this.itemId1, count: 0 });
}
}
let count1 = cc.find('itemlist/item1/countlab', this.refineNode);
if (count1) {
let label = count1.getComponent(cc.Label);
if (label) {
label.string = `擁有${GameModel.player.itemList[this.itemId1] == null ? 0 : GameModel.player.itemList[this.itemId1]}`;
}
}
},
/**材料選擇點擊 */
refineItemClicked(event, data) {
let count = 0;
let list = GameModel.player.itemList;
let temp = list[this.itemId1];
if (temp) {
count = temp;
}
if (count > 2) {
this.refineItemId = this.itemId1;
this.refineNode.getChildByName('BagItem').active = true;
this.refineNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: this.refineItemId, count: 0 });
this.refineNode.getChildByName('BagBtn').active = false;
this.refineNode.getChildByName('tips').getComponent(cc.Label).string = ItemUtil.getItemName(this.refineItemId);
}
this.refineNode.getChildByName('itemlist').active = false;
},
// 點擊選項卡
panelToggleClicked(event, data) {
let type = parseInt(data);
console.log('type:'+type)
if (!this.curInfo) {
return;
}
// 檢查材料是否還有足夠的數量
if (this.refineItemId != 0) {
let count = GameModel.player.itemList[this.refineItemId];
if (count < 1) {
this.refineItemId = 0;
}
}
for (const lab of this.titleNodes) {
lab.active = false;
}
this.titleNodes[type - 1].active = true;
this.upgradeNode.active = false;
this.refineNode.active = false;
this.inlayNode.active = false;
this.recastNode.active = false;
this.tipsNode.active = false;
if (type == 1) {
if (this.curInfo.EquipType == 0) {
this.tipsNode.active = true;
this.tipsNode.getChildByName('tips').active = true;
this.tipsNode.getChildByName('shenbing').active = false;
this.tipsNode.getChildByName('xianqi').active = false;
this.tipsNode.getChildByName('tips').getComponent(cc.Label).string = '該裝備不能煉化哦';
}
else {
this.refineNode.active = true;
this.showRefineInfo();
this.refineNode.getChildByName('BagItem').active = false;
this.refineNode.getChildByName('BagBtn').active = true;
this.refineNode.getChildByName('tips').getComponent(cc.Label).string = "請先選擇煉化材料";
}
}
else if (type == 2) {
if (this.curInfo.EquipType == 0 || this.curInfo.EquipType == 2) {
this.tipsNode.active = true;
this.tipsNode.getChildByName('tips').active = true;
this.tipsNode.getChildByName('shenbing').active = false;
this.tipsNode.getChildByName('xianqi').active = false;
this.tipsNode.getChildByName('tips').getComponent(cc.Label).string = '該裝備不能重鑄哦';
}
else {
this.recastNode.active = true;
this.showRecastInfo();
}
}
},
inlayBtnClicked(e, d) {
if (d == 1 && this.GemCnt >= this.MaxEmbedGemCnt) {
return;
}
GameModel.send('c2s_equip_inlay', {
operation: d,
roleid: GameModel.player.roleid,
equipid: this.curInfo.EquipID
});
},
upgradeBtnClicked(e, d) {
GameModel.send('c2s_equip_upgrade', {
roleid: GameModel.player.roleid,
equipid: this.curInfo.EquipID
});
this.nextEquipInfo = null;
},
refinePreBtnClicked(e, d) {
console.log("recastPreBtnClicked:", this.refinePreNode.getChildByName('needlab').active)
if (this.refineItemId == 0) {
MsgAlert.addMsg("請先選擇煉化材料");
return;
}
this.refinePreNode.active = true;
this.showPropertyInfo(this.curInfo.LianhuaAttr, this.refinePreNode.getChildByName('pre'));
// this.showNewProperty('');
this.refinePreNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: this.refineItemId, count: 0 });
this.refinePreNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[this.refineItemId] == null ? 0 : GameModel.player.itemList[this.refineItemId]}/10`;
},
recastPreBtnClicked(e, d) {
console.log("recastPreBtnClicked:", this.recastPreNode.getChildByName('needlab').active)
this.recastPreNode.active = true;
this.showPropertyInfo(this.curInfo.BaseAttr, this.recastPreNode.getChildByName('pre'));
// this.showNewProperty('');
if (this.curInfo.EquipType == 3) {
this.recastPreNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: 10411, count: 1 });
this.recastPreNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[10411] == null ? 0 : GameModel.player.itemList[10411]}/1`;
}
else {
this.recastPreNode.getChildByName('BagItem').getComponent('BagItem').loadInfo({ itemid: 10405, count: 1 });
this.recastPreNode.getChildByName('needlab').getComponent(cc.Label).string = `${GameModel.player.itemList[10405] == null ? 0 : GameModel.player.itemList[10405]}/1`;
}
},
refineBtnClicked(e, d) {
this.refineData = null;
let level = 0;
if (this.refineItemId == 10404) {
level = 2;
}
if (this.refineItemId == 10411) {
level = 4;
}
GameModel.player.itemList[this.refineItemId] -= 3;
this.refinePreBtnClicked();
GameModel.send('c2s_equip_refine', {
operation: 0,
roleid: GameModel.player.roleid,
level: level,
equipid: this.curInfo.EquipID
});
},
recastBtnClicked(e, d) {
let itemid = 10401;
if (this.curInfo.EquipType == 3) {
itemid = 10411;
} else {
itemid = 10405;
}
let itemnum = GameModel.player.itemList[itemid];
if (itemnum == null || itemnum <= 0) {
MsgAlert.addMsg('材料不足');
return;
}
this.recastData = null;
GameModel.send('c2s_equip_recast', {
operation: 0,
roleid: GameModel.player.roleid,
equipid: this.curInfo.EquipID
});
GameModel.player.itemList[itemid]--;
this.recastPreBtnClicked();
},
refineChangeBtnClicked(e, d) {
this.refineData = null;
GameModel.send('c2s_equip_refine', {
operation: 1,
roleid: GameModel.player.roleid,
level: 0,
equipid: this.curInfo.EquipID
});
},
recastChangeBtnClicked(e, d) {
this.recastData = null;
GameModel.send('c2s_equip_recast', {
operation: 1,
roleid: GameModel.player.roleid,
equipid: this.curInfo.EquipID
});
},
closeRefine() {
this.refinePreNode.active = false;
},
closeRecast() {
this.recastPreNode.active = false;
},
touchBegan(event) {
this.refineNode.getChildByName('itemlist').active = false;
},
onCloseBtnClicked(e, d) {
this.node.destroy();
},
onShenBingUpClicked(e, d) {
let shenbingup = cc.instantiate(this.shenbingUpPre);
shenbingup.parent = cc.find('Canvas');
this.node.destroy();
},
onXianQiUpClicked(e, d) {
let xianqiup = cc.instantiate(this.xianqiUpPre);
xianqiup.parent = cc.find('Canvas');
this.node.destroy();
},
});