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.
 
 
 
 
AdLike2048/assets/script/ui/PopToast/UIPopToast.ts

78 lines
2.0 KiB

//*********************
// create by 流云
// time: Sat Aug 15 2026
// desc: 公用确认弹窗(描述 + 类型标题 + 确定/取消)
//*********************
import { _decorator, Label } from 'cc';
import { Auto_PopToast } from './Auto_PopToast';
const { ccclass } = _decorator;
/** 弹窗类型:决定显示哪张标题图 ui_titleN */
export enum PopToastType {
/** 删除道具提示 → ui_title1 */
DeleteItem = 1,
}
export type PopToastParam = {
desc?: string;
type?: PopToastType;
onOk?: () => void;
onCancel?: () => void;
};
@ccclass('UIPopToast')
export class UIPopToast extends Auto_PopToast {
private _desc = '';
private _type = PopToastType.DeleteItem;
private _onOk: (() => void) | null = null;
private _onCancel: (() => void) | null = null;
onInit(): void {
const p = (this.prema ?? {}) as PopToastParam;
this._desc = String(p.desc ?? '');
this._type = Number(p.type) || PopToastType.DeleteItem;
this._onOk = typeof p.onOk === 'function' ? p.onOk : null;
this._onCancel = typeof p.onCancel === 'function' ? p.onCancel : null;
this._applyTitle(this._type);
this._applyDesc(this._desc);
this.showOpenCenterEff();
this.showOpenMaskEff(2);
}
private _applyTitle(type: PopToastType): void {
if (this.ui_title1?.isValid) {
this.ui_title1.active = type === PopToastType.DeleteItem;
}
}
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 {
const cb = this._onOk;
this._onOk = null;
this._onCancel = null;
void this.close(2).then(() => {
cb?.();
});
}
click_btnCancel(): void {
const cb = this._onCancel;
this._onOk = null;
this._onCancel = null;
void this.close(2).then(() => {
cb?.();
});
}
click_bgMask(): void {
}
}