import { _decorator, Component, Label, Node, Tween, tween } from 'cc'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { ChapterNewPlayTypeEnum } from '../../../game/ChapterPlayTypes'; import { UIID } from '../../../game/ConfigRes'; import { TableNames } from '../../../game/ConfigTableData'; import { BattleDataManager } from '../BattleDataManager'; import { MapObstacle } from '../MapObstacle'; const { ccclass, property } = _decorator; /**防护水晶 */ @ccclass('protectiveCrystal') export class protectiveCrystal extends Component { mapObstacleCom: MapObstacle; isXiufuFinish = true //是否修复完成 priceNum = 0 config:ITablePlaymode=null; zawConfig:ITableObstacle=null; protected onEnable(): void { //注册按钮监听 this.node.on(Node.EventType.TOUCH_END, this.onClickEnd, this); //监听修复完成 GEvent.Ins.on(GEvent.XiufuFinish, this.onXiufuFinish, this); } onXiufuFinish(xiufuNode){ if(xiufuNode == this.node){ this.mapObstacleCom.Grid.isBroken = false //不是破损 this.isXiufuFinish = true // this.refreshBtn() } } onClickEnd(){ if(this.mapObstacleCom){ if(this.mapObstacleCom.Grid.isBroken){ gg.ui.openPanel(UIID.xiufuBox, {data:{ priceNum:this.priceNum, xiufuNode:this.node, config: this.config, zawConfig: this.zawConfig, mapObstacle: this.mapObstacleCom, }}); }else{ //修复状态,点击无反应 return } } } protected onDisable(): void { //移除按钮监听 this.node.off(Node.EventType.TOUCH_END, this.onClickEnd, this); //移除修复完成监听 GEvent.Ins.off(GEvent.XiufuFinish, this.onXiufuFinish, this); } start() { let id = ChapterNewPlayTypeEnum.PlaceShieldProp // this.config = gg.data.table.getTableList(TableNames.Playmode).find(x => x.id == id) // this.zawConfig = gg.data.table.getTableList(TableNames.Obstacle).find(x => x.id == this.config.obstacle) // if(this.config){ // this.priceNum = this.zawConfig.price // } // if(this.node.parent){ // let mapObstacleCom = this.node.parent.getComponent(MapObstacle); // if(mapObstacleCom){ // this.mapObstacleCom = mapObstacleCom; // console.log('获取当前的mapObstacleCom组件成功'); // if (gg.data.project.getGridIsRepair(gg.game.CurentBattle.MapId, this.mapObstacleCom.Grid.Index) == 1) { // this.mapObstacleCom.Grid.isBroken = false; // } // this.isXiufuFinish = !this.mapObstacleCom.Grid.isBroken; // this.refreshBtn() // } // }else{ // this.isXiufuFinish = true // this.refreshBtn() // } //console.log(this.node,'招财猫节点'); } refreshBtn(){ if(this.isXiufuFinish){ this.node.getChildByName('破损').active = false this.node.getChildByName('修复').active = true gg.game.CurentBattle.IsOpenProtectiveCrystal = true }else{ this.node.getChildByName('破损').active = true this.node.getChildByName('修复').active = false } } }