You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
4.0 KiB
127 lines
4.0 KiB
|
3 weeks ago
|
import { _decorator, Component, Label, Node, Tween, tween } from 'cc';
|
||
|
|
import { MapObstacle } from '../MapObstacle';
|
||
|
|
import { TableNames } from '../../../game/ConfigTableData';
|
||
|
|
import { ChapterNewPlayTypeEnum } from '../../../game/ChapterPlayTypes';
|
||
|
|
import { UIID } from '../../../game/ConfigRes';
|
||
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
||
|
|
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
/**招财猫 */
|
||
|
|
@ccclass('luckyCat')
|
||
|
|
export class luckyCat extends Component {
|
||
|
|
mapObstacleCom: MapObstacle;
|
||
|
|
addMoney = 1
|
||
|
|
moneyLab: Label = null
|
||
|
|
isXiufuFinish = true //是否修复完成
|
||
|
|
priceNum = 0
|
||
|
|
config: Record<string, unknown> = null;
|
||
|
|
zawConfig: Record<string, unknown> = 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()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
addMoneySchdule() {
|
||
|
|
//加钱
|
||
|
|
if (!gg.game.CurentBattle.canUpdateFrame()) return;
|
||
|
|
GEvent.Ins.emit(GEvent.UpdateGameCoinNum)
|
||
|
|
gg.game.CurentBattle.CurentCoinNum += this.addMoney
|
||
|
|
|
||
|
|
this.moneyLab.node.active = true
|
||
|
|
|
||
|
|
Tween.stopAllByTarget(this.moneyLab.node)
|
||
|
|
this.moneyLab.node.setPosition(10, 30)
|
||
|
|
tween(this.moneyLab.node)
|
||
|
|
.to(0.7, { y: 60 })
|
||
|
|
.call(() => {
|
||
|
|
this.moneyLab.node.setPosition(10, 30)
|
||
|
|
this.moneyLab.node.active = false
|
||
|
|
})
|
||
|
|
.start()
|
||
|
|
}
|
||
|
|
|
||
|
|
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() {
|
||
|
|
this.moneyLab = this.node.getChildByName('lab').getComponent(Label)
|
||
|
|
this.config = null;
|
||
|
|
this.zawConfig = null;
|
||
|
|
this.moneyLab.string = '+' + this.addMoney.toString()
|
||
|
|
|
||
|
|
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
|
||
|
|
this.schedule(this.addMoneySchdule, 1)
|
||
|
|
} else {
|
||
|
|
this.node.getChildByName('破损').active = true
|
||
|
|
this.node.getChildByName('修复').active = false
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
// update(deltaTime: number) {
|
||
|
|
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
|
||
|
|
|