MatchMaster/assets/shop/script/buyActivate.ts

66 lines
2.1 KiB
TypeScript
Raw Permalink 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;
private callback: Function = null;
private rewardOffset: number = 0;
start() {
}
init(callback: Function, timeStr: string, tier: number = 0) {
// 初始化回调函数
this.callback = callback;
// 添加按钮事件监听
this.qiutBtn.node.on('click', this.onQuitBtnClick, this);
const vip = cc.find('activate/activateNode/vip/buyBtn', this.node);
const svip = cc.find('activate/activateNode/svip/buyBtn', this.node);
vip.parent.opacity = tier === 0 ? 255 : 150;
vip.active = tier === 0;
vip.getComponent(cc.Button).interactable = tier === 0;
svip.getChildByName('30yuan').active = tier === 0;
svip.getChildByName('12yuan').active = tier === 18;
for (const name of ['reward', 'add']) {
const node = svip.parent.getChildByName(name);
if (node) node.active = tier !== 18;
}
const offset = tier === 18 ? 100 : 0;
for (const name of ['reward1', 'reward2', 'reward3', 'reward4', 'reward5']) {
const node = svip.parent.getChildByName(name);
if (node) node.y += offset - this.rewardOffset;
}
this.rewardOffset = offset;
vip.on('click', () => { if (tier === 0) this.onBuyBtnClick('battlepass'); }, this);
svip.on('click', () => this.onBuyBtnClick(tier === 18 ? 'battlepass_12' : 'battlepass_30'), this);
// this.countdown.string = timeStr;
}
// updateCountdown(str: string) {
// this.countdown.string = str;
// }
onQuitBtnClick() {
// 移除界面
this.node.destroy();
}
onBuyBtnClick(product: string = 'battlepass') {
// 调用回调函数,触发passCheck中的购买逻辑
if (this.callback && typeof this.callback === 'function') {
this.callback(product);
}
// 移除界面
this.node.destroy();
}
}