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.
82 lines
2.3 KiB
82 lines
2.3 KiB
|
1 week ago
|
//*********************
|
||
|
|
// create by 流云
|
||
|
|
// time: Sun Sep 20 2026
|
||
|
|
// desc: 金币不足确认弹窗(确定需先看广告)
|
||
|
|
//*********************
|
||
|
|
import { _decorator, Label } from 'cc';
|
||
|
|
import { Auto_PopCoinToast } from './Auto_PopCoinToast';
|
||
|
|
const { ccclass } = _decorator;
|
||
|
|
|
||
|
|
/** 金币不足弹窗参数 */
|
||
|
|
export type PopCoinToastParam = {
|
||
|
|
/** 描述 */
|
||
|
|
desc?: string;
|
||
|
|
/** 广告成功后的确定回调 */
|
||
|
|
onOk?: () => void;
|
||
|
|
/** 取消回调 */
|
||
|
|
onCancel?: () => void;
|
||
|
|
};
|
||
|
|
|
||
|
|
@ccclass('UIPopCoinToast')
|
||
|
|
export class UIPopCoinToast extends Auto_PopCoinToast {
|
||
|
|
|
||
|
|
private _desc = '';
|
||
|
|
private _onOk: (() => void) | null = null;
|
||
|
|
private _onCancel: (() => void) | null = null;
|
||
|
|
private _busy = false;
|
||
|
|
|
||
|
|
onInit(): void {
|
||
|
|
this._busy = false;
|
||
|
|
const p = (this.prema ?? {}) as PopCoinToastParam;
|
||
|
|
this._desc = String(p.desc ?? '');
|
||
|
|
this._onOk = typeof p.onOk === 'function' ? p.onOk : null;
|
||
|
|
this._onCancel = typeof p.onCancel === 'function' ? p.onCancel : null;
|
||
|
|
|
||
|
|
this._applyDesc(this._desc);
|
||
|
|
this.showOpenCenterEff();
|
||
|
|
this.showOpenMaskEff(2);
|
||
|
|
}
|
||
|
|
|
||
|
|
private _applyDesc(text: string): void {
|
||
|
|
const descNode = this.ui_center?.getChildByName('desc');
|
||
|
|
const lb = descNode?.getComponent(Label);
|
||
|
|
if (lb) lb.string = text;
|
||
|
|
}
|
||
|
|
|
||
|
|
click_btnOk(): void {
|
||
|
|
if (this._busy) return;
|
||
|
|
this._busy = true;
|
||
|
|
gg.sdk.showVideoAd(this._onCoinAdClosed);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 看广告结果 */
|
||
|
|
private readonly _onCoinAdClosed = (res: boolean): void => {
|
||
|
|
if (!this.isValid) return;
|
||
|
|
if (!res) {
|
||
|
|
this._busy = false;
|
||
|
|
gg.ui.showToast('观看视频失败', false);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const cb = this._onOk;
|
||
|
|
this._onOk = null;
|
||
|
|
this._onCancel = null;
|
||
|
|
void this.close(2).then(this._afterCoinAdClose.bind(this, cb));
|
||
|
|
};
|
||
|
|
|
||
|
|
/** 关窗后再回调,避免弹窗叠层 */
|
||
|
|
private _afterCoinAdClose(cb: (() => void) | null): void {
|
||
|
|
cb?.();
|
||
|
|
}
|
||
|
|
|
||
|
|
click_btnCancel(): void {
|
||
|
|
if (this._busy) return;
|
||
|
|
const cb = this._onCancel;
|
||
|
|
this._onOk = null;
|
||
|
|
this._onCancel = null;
|
||
|
|
void this.close(2).then(this._afterCoinAdClose.bind(this, cb));
|
||
|
|
}
|
||
|
|
|
||
|
|
click_bgMask(): void {
|
||
|
|
}
|
||
|
|
}
|