import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import GameModel from "../ts/core/GameModel"; import GameUtil from "../ts/core/GameUtil"; import ItemUtil from "../ts/core/ItemUtil"; let schemeArgs = require('./SchemeArgs'); cc.Class({ extends: cc.Component, properties: { bgNode: cc.Node, itemIcon: cc.Sprite, typeLab: cc.Label, nameLab: cc.Label, infoLab: cc.Node, operationNode: cc.Node, useNode: cc.Node, unloadNode: cc.Node, tipsNode: cc.Node, }, onLoad() { this.operationNode.active = false; this.height = cc.find('Canvas').height; this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this)); this.indexarr = ['武器', '項鍊', '衣服', '頭盔', '鞋子','翅膀']; this.sexarr = ['男', '女']; this.racearr = ['人', '仙', '魔', '鬼', '龍']; }, loadInfo(info) { let schemePanel = cc.find('Canvas/MainUI/SchemePanel'); if(schemePanel){ let equipsNode = schemePanel.getChildByName('schemeNode').getChildByName('EquipsNode'); let equipsLogic = equipsNode.getComponent('SchemeEquipsPanel'); if(equipsLogic){ this.onUse = equipsLogic.checkEquipsOnUse(info.EquipID); } } this.attr1 = GameModel.player.gameData.attr1; this.iteminfo = info; if (!info.BaseAttr) { GameModel.send('c2s_equip_info', { roleid: GameModel.player.roleid, equipid: info.EquipID }); return; } this.itemIcon.spriteFrame = ItemUtil.getItemIconBy(info); this.typeLab.string = info.EDesc; this.nameLab.string = info.EName; this.infoPos = this.infoLab.getPosition(); this.addInfoLab(info.Detail); this.addInfoLab(`【裝備部位】${this.indexarr[info.EIndex - 1]}`); if (info.Sex == 9 || info.Race == 9) { this.addInfoLab(`【裝備適用】通用`); } else if (info.OwnerRoleId && info.OwnerRoleId > 0) { if (info.OwnerRoleId != GameModel.player.resid) { this.addInfoLab(`【裝備適用】${GameUtil.roleName[info.OwnerRoleId]}`, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(`【裝備適用】${GameUtil.roleName[info.OwnerRoleId]}`); } } else { if (info.Sex != GameModel.player.sex || info.Race != GameModel.player.race) { this.addInfoLab(`【裝備適用】${this.sexarr[info.Sex - 1]}${this.racearr[info.Race - 1]}`, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(`【裝備適用】${this.sexarr[info.Sex - 1]}${this.racearr[info.Race - 1]}`); } } let levelstr = '【等級要求】'; if (info.NeedGrade) { if(info.NeedRei<4){ levelstr += `${info.NeedRei}轉`; }else{ levelstr += `飛升`; } levelstr += `${info.NeedGrade}級`; if (info.NeedGrade > GameModel.player.level || info.NeedRei > GameModel.player.relive) { this.addInfoLab(levelstr, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(levelstr); } } if (info.Shuxingxuqiu && info.Shuxingxuqiu.length > 0) { let xuqiuInfo = JSON.parse(info.Shuxingxuqiu); let xuqiustr = ''; for (const key in xuqiuInfo) { xuqiustr = `【${GameUtil.getAttrTypeL2Name(key)}需求】${xuqiuInfo[key]}`; if (this.attr1[key] < xuqiuInfo[key]) { this.addInfoLab(xuqiustr, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(xuqiustr); } break; } } this.addInfoLab(`【裝備耐久】${info.MaxEndure}/${info.MaxEndure}`); if (!info.BaseAttr) { info.BaseAttr = '{}'; } let baseInfo=null; try{ baseInfo=JSON.parse(info.BaseAttr); }catch(error){ cc.warn(`$警告:裝備基礎屬性JSON解析異常${error}`); } if(baseInfo){ for (let key in baseInfo) { this.addInfoLab(GameUtil.getAttrTypeL1Name(key), this.infoPos, false, new cc.color(141, 135, 103)); let valuestr = baseInfo[key]; if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) { valuestr = (valuestr > 0 ? '+' : '') + (valuestr / 10).toFixed(1) + '%'; } else { valuestr = (valuestr > 0 ? '+' : '') + valuestr; } this.addInfoLab(valuestr, SKUIUtil.add(this.infoPos, cc.v2(120, 0)), true, new cc.color(141, 135, 103)); } } if (!info.LianhuaAttr) { info.LianhuaAttr = '{}'; } let lianhuaInfo = JSON.parse(info.LianhuaAttr); if (Array.isArray(lianhuaInfo)) { for (const info of lianhuaInfo) { for (const key in info) { cc.log(info, key, info[key]); this.addInfoLab(GameUtil.getAttrTypeL1Name(key), this.infoPos, false, new cc.color(46, 143, 9)); let valuestr = info[key]; if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) { valuestr = (valuestr > 0 ? '+' : '') + (valuestr / 10).toFixed(1) + '%'; } else { valuestr = (valuestr > 0 ? '+' : '') + valuestr; } this.addInfoLab(valuestr, SKUIUtil.add(this.infoPos, cc.v2(120, 0)), true, new cc.color(46, 143, 9)); break; } } } if(this.onUse){ this.unloadNode.active = true; this.useNode.active = false; this.tipsNode.active = true; } else { this.unloadNode.active = false; this.useNode.active = true; this.tipsNode.active = false; } this.showGemInfo(info.GemCnt, info.EIndex); }, showGemInfo() { let gemX = this.bgNode.getChildByName('gem').x; let gemY = this.bgNode.getChildByName('gem').y; for (let index = 0; index < this.iteminfo.MaxEmbedGemCnt; index++) { let gem = cc.instantiate(this.bgNode.getChildByName('gem')); gem.active = true; gem.x = gemX + index * 15; gem.y = gemY; gem.parent = this.bgNode; if (index < this.iteminfo.GemCnt) { gem.getChildByName(`gem${this.iteminfo.EIndex}`).active = true; } } }, showOperation(onUse) { this.operationNode.active = true; }, addInfoLab(info, pos, newline = true, color = cc.Color.WHITE) {//, color){ if (!pos && pos == null) { pos = this.infoPos; } let detail = cc.instantiate(this.infoLab); detail.active = true; detail.parent = this.bgNode; detail.setPosition(pos); detail.color = color; detail.getComponent(cc.Label).string = info; if (newline) { this.infoPos.y -= (detail.height + 4); } if (-this.infoPos.y > this.bgNode.height) { this.bgNode.height = -this.infoPos.y; if (this.bgNode.y + this.infoPos.y < -this.height / 2) { this.bgNode.y = -this.height / 2 - this.infoPos.y; } } }, useBtnClicked() { GameModel.send('c2s_scheme_updateEquip', { roleId: GameModel.player.roleid, schemeId: schemeArgs.schemeId, equipId: this.iteminfo.EquipID, type: 0 }); this.node.destroy(); }, unloadBtnClicked() { GameModel.send('c2s_scheme_updateEquip', { roleId: GameModel.player.roleid, schemeId: schemeArgs.schemeId, equipId: this.iteminfo.EquipID, type:1 }); this.node.destroy(); }, touchBegan(event) { if (this.bgNode.getBoundingBoxToWorld().contains(event.getLocation())) { return; } this.node.runAction(cc.sequence(cc.fadeOut(0.1), cc.removeSelf())); }, });