import { _decorator, Button, Component, Node } from 'cc'; import { rootMgr } from '../../scene/RootMgr'; import { Board } from '../board/Board'; import { aa } from 'db://assets/scripts/aa'; import { EventType } from '../../util/Enum'; import { Container } from '../container/Container'; import { BoardState } from '../../util/Enum'; const { ccclass, property } = _decorator; @ccclass('ButtomList') export class ButtomList extends Component { @property(Node) swapcolors: Node//交换颜色 @property(Node) withdraw: Node//撤回一步 @property(Node) addbottles: Node//增加空瓶 start() { // this.swapcolors.on(Node.EventType.TOUCH_END, this.swapColors, this); // rootMgr.game.evt.on('openbottlesBtn', this.withdrawBtnActive, this); // rootMgr.game.evt.on('openaddbottlesBtn', this.addbottlesBtnActive, this); // this.withdraw.getComponent(Button).interactable = false; // this.addbottles.getComponent(Button).interactable = false; } // withdrawBtnActive(rebtn: boolean = false) { // // 只有当不在打乱状态时才允许设置按钮状态 // const board = rootMgr.gameCompent.getCompent(Board); // if (board && board.state !== BoardState.SHUFFLING) { // const withdrawButton = this.withdraw.getComponent(Button); // if (withdrawButton) { // withdrawButton.interactable = rebtn; // } // if (rebtn) { // this.withdraw.on(Node.EventType.TOUCH_END, this.withDraw, this); // } // } // } // addbottlesBtnActive(rebtn: boolean = false) { // // 只有当不在打乱状态时才允许设置按钮状态 // const board = rootMgr.gameCompent.getCompent(Board); // if (board && board.state !== BoardState.SHUFFLING) { // const addbottlesButton = this.addbottles.getComponent(Button); // if (addbottlesButton) { // addbottlesButton.interactable = rebtn; // } // if (rebtn) { // this.addbottles.on(Node.EventType.TOUCH_END, this.addBottles, this); // } // } // } // swapColors() { // //aa.eventDispatch.emit(EventType.puase); // aa.sdk.playRewardAd("打乱水的排序").then((ok) => { // if (ok) { // rootMgr.game.evt.emit('swapcolors'); // // 禁用撤回和增加瓶子按钮 // this.setButtonInteractable(this.withdraw, false); // this.setButtonInteractable(this.addbottles, false); // } // aa.eventDispatch.emit(EventType.resume); // const board = rootMgr.gameCompent.getCompent(Board); // if (board) { // board.clearSelect(); // 重置选中状态 // } // }); // } // withDraw() { // // 检查按钮是否可用,不可用时直接返回 // const withdrawButton = this.withdraw.getComponent(Button); // if (!withdrawButton || !withdrawButton.interactable) { // return; // } // // aa.eventDispatch.emit(EventType.puase); // aa.sdk.playRewardAd("撤回一步").then((ok) => { // if (ok) { // rootMgr.game.evt.emit('withdraw'); // } // aa.eventDispatch.emit(EventType.resume); // const board = rootMgr.gameCompent.getCompent(Board); // if (board) { // board.clearSelect(); // 重置选中状态 // } // }); // if (withdrawButton) { // withdrawButton.interactable = false; // } // } // addBottles() { // // 检查按钮是否可用,不可用时直接返回 // const addbottlesButton = this.addbottles.getComponent(Button); // if (!addbottlesButton || !addbottlesButton.interactable) { // return; // } // if (Container.clearFinishedPositions.length <= 0) { // if (addbottlesButton) { // addbottlesButton.interactable = false; // } // return; // } // //aa.eventDispatch.emit(EventType.puase); // aa.sdk.playRewardAd("增加一个空瓶子").then((ok) => { // if (ok) { // rootMgr.game.evt.emit('addbottles'); // } // aa.eventDispatch.emit(EventType.resume); // const board = rootMgr.gameCompent.getCompent(Board); // if (board) { // board.clearSelect(); // 重置选中状态 // } // }); // } // // 设置按钮交互状态的辅助方法 // private setButtonInteractable(buttonNode: Node, interactable: boolean) { // const button = buttonNode.getComponent(Button); // if (button) { // button.interactable = interactable; // } // } // protected onDestroy(): void { // rootMgr.game.evt.off('openbottlesBtn', this.withdrawBtnActive, this); // rootMgr.game.evt.off('openaddbottlesBtn', this.addbottlesBtnActive, this); // } }