// import CSSettingsV3 from "../../../FormTable/CSSettingsV3"; const { ccclass, requireComponent, menu, property } = cc._decorator; /** 有冷卻功能的按鈕 */ @ccclass @menu("Plug-in/Button/ButtonClickCD") @requireComponent(cc.Button) export default class ButtonClickCD extends cc.Component { //#region property @property() public CDTime: number = 3; //#endregion //#region public public Msg: string; //#endregion //#region private private _nowCDTime: number = 0; //#endregion //#region Lifecycle protected onLoad(): void { this.loadMsg(); } private async loadMsg(): Promise { let CSSettingsV3: any = (await (import("../../../FormTable/CSSettingsV3"))).default; this.Msg = CSSettingsV3.prototype.CommonString(1514); } protected update(dt: number): void { if (this._nowCDTime > 0) { this._nowCDTime -= dt; if (this._nowCDTime <= 0) { this._nowCDTime = 0; this.getComponent(cc.Button).interactable = true; } } } protected onEnable(): void { this.node.on("click", this._onClick, this); this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); } protected onDisable(): void { this.node.off("click", this._onClick, this); this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); } //#endregion //#region Custom private _onClick(event: cc.Button, customEventData: any): void { // if (this._nowCDTime > 0) { // CSMessage.CreateYesMsg(String.Format(this.Msg, this._nowCDTime.toFixed(0))); // return; // } this.getComponent(cc.Button).interactable = false; this._nowCDTime = this.CDTime; } private async _onTouchStart(event: cc.Event.EventTouch): Promise { if (this._nowCDTime > 0) { let CSMessage: any = (await (import("../../../Common/Message/CSMessage"))).default; CSMessage.CreateYesMsg(String.Format(this.Msg, this._nowCDTime.toFixed(0))); } } //#endregion }