feat: 接入通关弹窗

This commit is contained in:
richarjiang
2026-04-26 16:20:37 +08:00
parent f5732b46a5
commit 5074706115
52 changed files with 8064 additions and 540 deletions

View File

@@ -1,5 +1,5 @@
import { _decorator, Node, Label, AudioClip, AudioSource, view, UITransform, Size } from 'cc';
import { BaseView } from 'db://assets/scripts/core/BaseView';
import { _decorator, Node, Label, AudioClip, AudioSource, view, UITransform, Size, ProgressBar } from 'cc';
import { BaseModal } from 'db://assets/scripts/core/BaseModal';
import { WxSDK } from 'db://assets/scripts/utils/WxSDK';
const { ccclass, property } = _decorator;
@@ -13,12 +13,23 @@ export interface PassModalCallbacks {
onShare?: () => void;
}
export interface PassModalTitleInfo {
titleText?: string;
nextTitleProgress?: number;
progressText?: string;
}
interface PassModalParams {
levelIndex?: number;
titleInfo?: PassModalTitleInfo;
}
/**
* 通关弹窗组件
* 继承 BaseView,显示通关成功弹窗,提供"下一关"和"分享给好友"两个按钮
* 继承 BaseModal,显示通关成功弹窗,提供"下一关"和"分享给好友"两个按钮
*/
@ccclass('PassModal')
export class PassModal extends BaseView {
export class PassModal extends BaseModal {
/** 静态常量:弹窗层级 */
public static readonly MODAL_Z_INDEX = 999;
@@ -30,9 +41,17 @@ export class PassModal extends BaseView {
@property(Node)
shareButton: Node | null = null;
/** 提示Label如 恭喜通关) */
/** 称号文字 */
@property(Label)
tipLabel: Label | null = null;
titleLevelLabel: Label | null = null;
/** 距离下一个称号的进度 */
@property(ProgressBar)
titleProgressBar: ProgressBar | null = null;
/** 进度提示文案 */
@property(Label)
progressLabel: Label | null = null;
/** 通关音效 */
@property(AudioClip)
@@ -44,6 +63,21 @@ export class PassModal extends BaseView {
/** 缓存的屏幕尺寸 */
private _screenSize: Size | null = null;
/** 称号展示数据 */
private _titleInfo: PassModalTitleInfo = {
titleText: '冷场小白1级',
nextTitleProgress: 0,
progressText: '还差3题获得冷场小白2级'
};
setParams(params: PassModalParams): void {
super.setParams(params);
if (params?.titleInfo) {
this.setTitleInfo(params.titleInfo);
}
}
/**
* 设置回调函数
*/
@@ -51,6 +85,17 @@ export class PassModal extends BaseView {
this._callbacks = callbacks;
}
/**
* 设置称号体系展示数据
*/
setTitleInfo(titleInfo: PassModalTitleInfo): void {
this._titleInfo = {
...this._titleInfo,
...titleInfo
};
this._updateTitleInfo();
}
/**
* 页面首次加载时调用
*/
@@ -63,7 +108,9 @@ export class PassModal extends BaseView {
* 页面每次显示时调用
*/
onViewShow(): void {
super.onViewShow();
this._updateWidget();
this._updateTitleInfo();
this._playSuccessSound();
}
@@ -129,6 +176,34 @@ export class PassModal extends BaseView {
}
}
/**
* 更新称号体系核心变量
*/
private _updateTitleInfo(): void {
if (this.titleLevelLabel && this._titleInfo.titleText !== undefined) {
this.titleLevelLabel.string = this._titleInfo.titleText;
}
if (this.titleProgressBar && this._titleInfo.nextTitleProgress !== undefined) {
this.titleProgressBar.progress = this._normalizeProgress(this._titleInfo.nextTitleProgress);
}
if (this.progressLabel && this._titleInfo.progressText !== undefined) {
this.progressLabel.string = this._titleInfo.progressText;
}
}
/**
* 规范化进度值
*/
private _normalizeProgress(progress: number): number {
if (!Number.isFinite(progress)) {
return 0;
}
return Math.max(0, Math.min(1, progress));
}
/**
* 下一关按钮点击
*/