cb/assets/shop/script/buyActivate.ts
2025-11-11 10:35:05 +08:00

49 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { ccclass, property } = cc._decorator;
@ccclass
export default class buyActivate extends cc.Component {
@property(cc.Button)
qiutBtn: cc.Button = null;
@property(cc.Button)
buyBtn: cc.Button = null;
@property(cc.Label)
countdown: cc.Label = null;
private callback: Function = null;
start() {
}
init(callback: Function, timeStr: string) {
// 初始化回调函数
this.callback = callback;
// 添加按钮事件监听
this.qiutBtn.node.on('click', this.onQuitBtnClick, this);
this.buyBtn.node.on('click', this.onBuyBtnClick, this);
this.countdown.string = timeStr;
}
// updateCountdown(str: string) {
// this.countdown.string = str;
// }
onQuitBtnClick() {
// 移除界面
this.node.destroy();
}
onBuyBtnClick() {
// 调用回调函数触发passCheck中的购买逻辑
if (this.callback && typeof this.callback === 'function') {
this.callback();
}
// 移除界面
this.node.destroy();
}
}