feat: 接入激励视频
This commit is contained in:
@@ -340,6 +340,12 @@ export class PageLevel extends BaseView {
|
||||
/** 是否正在解锁提示(防止双击重复触发) */
|
||||
private _isUnlocking: boolean = false;
|
||||
|
||||
/** 是否正在观看加时广告(防止双击重复触发) */
|
||||
private _isAddingTime: boolean = false;
|
||||
|
||||
/** 激励视频广告期间是否暂停了倒计时 */
|
||||
private _isCountdownPausedForRewardAd: boolean = false;
|
||||
|
||||
/** 下一个待解锁的线索序号(2 或 3),超过 3 表示全部已解锁 */
|
||||
private _nextClueIndex: number = 2;
|
||||
|
||||
@@ -1237,8 +1243,11 @@ export class PageLevel extends BaseView {
|
||||
/**
|
||||
* 点击解锁线索(顺序解锁:先线索2,再线索3;全部解锁后切换为查看答案入口)
|
||||
*/
|
||||
private onUnlockClue(): void {
|
||||
// 全部已解锁后,点击"查看答案":自动填入正确答案并走通关流程
|
||||
private async onUnlockClue(): Promise<void> {
|
||||
if (this._isUnlocking) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._nextClueIndex > 3) {
|
||||
if (this._isTransitioning) return;
|
||||
|
||||
@@ -1251,11 +1260,24 @@ export class PageLevel extends BaseView {
|
||||
this.playClickSound();
|
||||
console.log('[PageLevel] 点击查看答案,自动填充答案并触发通关流程');
|
||||
|
||||
// 填充答案到输入格(distributeInputText 内部会用 _isSyncingInputText 阻止 EditBox 事件回调)
|
||||
this.distributeInputText(answer);
|
||||
this._isUnlocking = true;
|
||||
try {
|
||||
const rewarded = await this.showRewardedVideoAd('查看答案');
|
||||
if (!rewarded || this._isTransitioning) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 走提交流程(答案命中 → showSuccess → 通关弹窗)
|
||||
this.onSubmitAnswer();
|
||||
const latestAnswer = this._currentConfig?.answer;
|
||||
if (!latestAnswer) {
|
||||
ToastManager.show('答案暂未配置');
|
||||
return;
|
||||
}
|
||||
|
||||
this.distributeInputText(latestAnswer);
|
||||
this.onSubmitAnswer();
|
||||
} finally {
|
||||
this._isUnlocking = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1269,45 +1291,116 @@ export class PageLevel extends BaseView {
|
||||
}
|
||||
|
||||
this.playClickSound();
|
||||
this.setClue(index, clueContent);
|
||||
this._isUnlocking = true;
|
||||
try {
|
||||
const rewarded = await this.showRewardedVideoAd('查看线索');
|
||||
if (!rewarded || this._isTransitioning || this._nextClueIndex !== index) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 解锁线索后播放"出现"动画,让内容刷新不突兀
|
||||
const tipsItem = this.getTipsItem(index);
|
||||
if (tipsItem) {
|
||||
this.playClueAppearAnimation(tipsItem);
|
||||
const latestClueContent = index === 2 ? this._currentConfig?.clue2 : this._currentConfig?.clue3;
|
||||
if (!latestClueContent) {
|
||||
ToastManager.show('该提示暂未配置');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setClue(index, latestClueContent);
|
||||
|
||||
const tipsItem = this.getTipsItem(index);
|
||||
if (tipsItem) {
|
||||
this.playClueAppearAnimation(tipsItem);
|
||||
}
|
||||
|
||||
this._nextClueIndex++;
|
||||
|
||||
if (this._nextClueIndex > 3) {
|
||||
this.setUnlockButtonText(PageLevel.UNLOCK_BUTTON_ANSWER_TEXT);
|
||||
}
|
||||
|
||||
console.log(`[PageLevel] 解锁线索${index}`);
|
||||
} finally {
|
||||
this._isUnlocking = false;
|
||||
}
|
||||
|
||||
// 推进到下一条待解锁线索
|
||||
this._nextClueIndex++;
|
||||
|
||||
// 全部解锁完毕后不隐藏按钮,改为查看答案入口
|
||||
if (this._nextClueIndex > 3) {
|
||||
this.setUnlockButtonText(PageLevel.UNLOCK_BUTTON_ANSWER_TEXT);
|
||||
}
|
||||
|
||||
console.log(`[PageLevel] 解锁线索${index}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击增加时间按钮(倒计时增加 60 秒)
|
||||
*/
|
||||
private onAddTime(): void {
|
||||
private async onAddTime(): Promise<void> {
|
||||
if (this._isAddingTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isTimeUp) {
|
||||
ToastManager.show('时间已结束,无法增加');
|
||||
return;
|
||||
}
|
||||
|
||||
this.playClickSound();
|
||||
this._isAddingTime = true;
|
||||
try {
|
||||
const rewarded = await this.showRewardedVideoAd('加时');
|
||||
if (!rewarded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isTimeUp) {
|
||||
ToastManager.show('时间已结束,无法增加');
|
||||
return;
|
||||
}
|
||||
|
||||
this.addCountdownTime();
|
||||
} finally {
|
||||
this._isAddingTime = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async showRewardedVideoAd(rewardName: string): Promise<boolean> {
|
||||
this.pauseLevelForRewardedVideoAd();
|
||||
try {
|
||||
const rewarded = await WxSDK.showRewardedVideoAd();
|
||||
if (!rewarded) {
|
||||
ToastManager.show(`${rewardName}需要看完广告`);
|
||||
}
|
||||
return rewarded;
|
||||
} finally {
|
||||
this.resumeLevelAfterRewardedVideoAd();
|
||||
}
|
||||
}
|
||||
|
||||
private pauseLevelForRewardedVideoAd(): void {
|
||||
this._isCountdownPausedForRewardAd = false;
|
||||
if (!this._isTimeUp && !this._isTransitioning && this._countdown > 0) {
|
||||
this.stopCountdown();
|
||||
this._isCountdownPausedForRewardAd = true;
|
||||
}
|
||||
|
||||
AudioManager.instance.pausePlayingAudioSources();
|
||||
}
|
||||
|
||||
private resumeLevelAfterRewardedVideoAd(): void {
|
||||
AudioManager.instance.resumePausedAudioSources();
|
||||
|
||||
if (!this._isCountdownPausedForRewardAd) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isCountdownPausedForRewardAd = false;
|
||||
if (this.node?.isValid && !this._isTimeUp && !this._isTransitioning && this._countdown > 0) {
|
||||
this.schedule(this.onCountdownTick, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private addCountdownTime(): void {
|
||||
const wasUrgent = this._countdown <= PageLevel.CLOCK_URGENT_THRESHOLD;
|
||||
this._countdown += 60;
|
||||
|
||||
// 从紧迫态跳回安全区:停掉残留脉冲并复位 scale(updateClockLabel 会负责把颜色改回)
|
||||
if (wasUrgent && this._countdown > PageLevel.CLOCK_URGENT_THRESHOLD && this.clockLabel) {
|
||||
Tween.stopAllByTarget(this.clockLabel.node);
|
||||
this.clockLabel.node.setScale(1, 1, 1);
|
||||
}
|
||||
|
||||
this.updateClockLabel();
|
||||
this.playClickSound();
|
||||
ToastManager.show('已成功增加60秒!');
|
||||
console.log(`[PageLevel] 增加60秒倒计时,当前剩余: ${this._countdown}s`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user