feat: 优化关卡;支持加时

This commit is contained in:
richarjiang
2026-04-10 23:08:28 +08:00
parent 9cf499a5e1
commit 2f74f260b7
6 changed files with 1233 additions and 871 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -53,10 +53,10 @@ export class PageLevel extends BaseView {
tipsItem3: Node | null = null;
@property(Node)
unLockItem2: Node | null = null;
unLockTipsBtn: Node | null = null;
@property(Node)
unLockItem3: Node | null = null;
addTimeBtn: Node | null = null;
@property(Label)
clockLabel: Label | null = null;
@@ -91,6 +91,9 @@ export class PageLevel extends BaseView {
/** 倒计时剩余秒数 */
private _countdown: number = 60;
/** 关卡开始时间戳ms用于准确计算耗时 */
private _levelStartTime: number = 0;
/** 倒计时是否结束 */
private _isTimeUp: boolean = false;
@@ -103,6 +106,9 @@ export class PageLevel extends BaseView {
/** 是否正在解锁提示(防止双击重复触发) */
private _isUnlocking: boolean = false;
/** 下一个待解锁的线索序号2 或 3超过 3 表示全部已解锁 */
private _nextClueIndex: number = 2;
/** 通关弹窗实例 */
private _passModalNode: Node | null = null;
@@ -170,8 +176,8 @@ export class PageLevel extends BaseView {
// 清理事件监听
this.iconSetting?.off(Node.EventType.TOUCH_END, this.onIconSettingClick, this);
this.unLockItem2?.off(Node.EventType.TOUCH_END);
this.unLockItem3?.off(Node.EventType.TOUCH_END);
this.unLockTipsBtn?.off(Node.EventType.TOUCH_END);
this.addTimeBtn?.off(Node.EventType.TOUCH_END);
this.submitButton?.off(Node.EventType.TOUCH_END, this.onSubmitAnswer, this);
}
@@ -270,13 +276,15 @@ export class PageLevel extends BaseView {
this.setClue(1, config.clue1);
}
// 隐藏线索2、3
this.hideClue(2);
this.hideClue(3);
// 重置线索解锁进度
this._nextClueIndex = 2;
// 显示解锁按钮2、3
this.showUnlockButton(2);
this.showUnlockButton(3);
// 线索2、3 保持显示,写入"待解锁"占位文案
this.setClue(2, '待解锁');
this.setClue(3, '待解锁');
// 显示解锁按钮(单个统一按钮)
this.showUnlockButton();
// 根据答案长度创建单个输入框
if (config.answer) {
@@ -513,22 +521,20 @@ export class PageLevel extends BaseView {
/**
* 显示解锁按钮
*/
private showUnlockButton(index: number): void {
const unlockItem = index === 2 ? this.unLockItem2 : this.unLockItem3;
if (unlockItem) {
unlockItem.active = true;
console.log(`[PageLevel] 显示解锁按钮${index}`);
private showUnlockButton(_index?: number): void {
if (this.unLockTipsBtn) {
this.unLockTipsBtn.active = true;
console.log('[PageLevel] 显示解锁按钮');
}
}
/**
* 隐藏解锁按钮
*/
private hideUnlockButton(index: number): void {
const unlockItem = index === 2 ? this.unLockItem2 : this.unLockItem3;
if (unlockItem) {
unlockItem.active = false;
console.log(`[PageLevel] 隐藏解锁按钮${index}`);
private hideUnlockButton(_index?: number): void {
if (this.unLockTipsBtn) {
this.unLockTipsBtn.active = false;
console.log('[PageLevel] 隐藏解锁按钮');
}
}
@@ -536,14 +542,12 @@ export class PageLevel extends BaseView {
* 初始化解锁按钮事件
*/
private initUnlockButtons(): void {
// 解锁按钮2
if (this.unLockItem2) {
this.unLockItem2.on(Node.EventType.TOUCH_END, () => this.onUnlockClue(2), this);
if (this.unLockTipsBtn) {
this.unLockTipsBtn.on(Node.EventType.TOUCH_END, this.onUnlockClue, this);
}
// 解锁按钮3
if (this.unLockItem3) {
this.unLockItem3.on(Node.EventType.TOUCH_END, () => this.onUnlockClue(3), this);
if (this.addTimeBtn) {
this.addTimeBtn.on(Node.EventType.TOUCH_END, this.onAddTime, this);
}
console.log('[PageLevel] 解锁按钮事件已绑定');
@@ -563,41 +567,52 @@ export class PageLevel extends BaseView {
}
/**
* 点击解锁线索(观看激励视频广告后解锁
* 点击解锁线索(顺序解锁先线索2再线索3全部解锁后提示已解锁完毕
*/
private async onUnlockClue(index: number): Promise<void> {
// 防止双击重复触发
if (this._isUnlocking) return;
this._isUnlocking = true;
try {
// 检查线索是否存在
if (!this._currentConfig) return;
const clueContent = index === 2 ? this._currentConfig.clue2 : this._currentConfig.clue3;
if (!clueContent) {
ToastManager.show('该提示暂未配置');
return;
}
// 调用微信激励视频广告
ToastManager.show('观看视频即可解锁提示');
const adWatched = await WxSDK.showRewardedVideoAd();
if (!adWatched) {
ToastManager.show('需要看完视频才能解锁提示哦');
return;
}
this.playClickSound();
this.hideUnlockButton(index);
this.showClue(index);
this.setClue(index, clueContent);
console.log(`[PageLevel] 通过观看广告解锁线索${index}`);
} finally {
this._isUnlocking = false;
private onUnlockClue(): void {
// 全部已解锁,提示用户
if (this._nextClueIndex > 3) {
ToastManager.show('已解锁完毕');
return;
}
if (!this._currentConfig) return;
const index = this._nextClueIndex;
const clueContent = index === 2 ? this._currentConfig.clue2 : this._currentConfig.clue3;
if (!clueContent) {
ToastManager.show('该提示暂未配置');
return;
}
this.playClickSound();
this.setClue(index, clueContent);
// 推进到下一条待解锁线索
this._nextClueIndex++;
// 全部解锁完毕则隐藏按钮
if (this._nextClueIndex > 3) {
this.hideUnlockButton();
}
console.log(`[PageLevel] 解锁线索${index}`);
}
/**
* 点击增加时间按钮(倒计时增加 60 秒)
*/
private onAddTime(): void {
if (this._isTimeUp) {
ToastManager.show('时间已结束,无法增加');
return;
}
this._countdown += 60;
this.updateClockLabel();
this.playClickSound();
ToastManager.show('已成功增加60秒');
console.log(`[PageLevel] 增加60秒倒计时当前剩余: ${this._countdown}s`);
}
// ========== 主图相关方法 ==========
@@ -655,6 +670,7 @@ export class PageLevel extends BaseView {
private startCountdown(): void {
this._countdown = 60;
this._isTimeUp = false;
this._levelStartTime = Date.now();
this.updateClockLabel();
this.schedule(this.onCountdownTick, 1);
console.log('[PageLevel] 开始倒计时 60 秒');
@@ -804,7 +820,7 @@ export class PageLevel extends BaseView {
this.playSuccessSound();
const levelId = this._currentConfig?.id ?? '';
const timeSpent = 60 - this._countdown;
const timeSpent = Math.max(0, Math.round((Date.now() - this._levelStartTime) / 1000));
if (!this._isShareMode) {
// 上报通关耗时

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6@6c48a",
"displayName": "BuyButtonBg",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6@f9941",
"displayName": "BuyButtonBg",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 326,
"height": 143,
"rawWidth": 326,
"rawHeight": 143,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-163,
-71.5,
0,
163,
-71.5,
0,
-163,
71.5,
0,
163,
71.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
143,
326,
143,
0,
0,
326,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-163,
-71.5,
0
],
"maxPos": [
163,
71.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": true,
"redirect": "39c1c6c3-43dd-4fa1-bbc2-fb394d8cf6d6@6c48a"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "f7f6c133-9b56-4ed6-9a53-6d71252990c3",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "f7f6c133-9b56-4ed6-9a53-6d71252990c3@6c48a",
"displayName": "GetButtonBg",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "f7f6c133-9b56-4ed6-9a53-6d71252990c3",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "f7f6c133-9b56-4ed6-9a53-6d71252990c3@f9941",
"displayName": "GetButtonBg",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 326,
"height": 143,
"rawWidth": 326,
"rawHeight": 143,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-163,
-71.5,
0,
163,
-71.5,
0,
-163,
71.5,
0,
163,
71.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
143,
326,
143,
0,
0,
326,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-163,
-71.5,
0
],
"maxPos": [
163,
71.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "f7f6c133-9b56-4ed6-9a53-6d71252990c3@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": true,
"redirect": "f7f6c133-9b56-4ed6-9a53-6d71252990c3@6c48a"
}
}