feat: 优化分享模式通关判定逻辑
This commit is contained in:
@@ -11,12 +11,15 @@ export interface TimeoutModalCallbacks {
|
||||
onShare?: () => void;
|
||||
/** 点击再次挑战回调 */
|
||||
onRestart?: () => void;
|
||||
/** 点击下一题回调 */
|
||||
onNext?: () => void;
|
||||
/** 点击返回主页 / 关闭按钮回调 */
|
||||
onHome?: () => void;
|
||||
}
|
||||
|
||||
interface TimeoutModalParams {
|
||||
levelIndex?: number;
|
||||
shareMode?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,10 @@ export class TimeoutModal extends BaseModal {
|
||||
@property(Node)
|
||||
buttonRestart: Node | null = null;
|
||||
|
||||
/** 下一题按钮(分享挑战超时时显示) */
|
||||
@property(Node)
|
||||
buttonNext: Node | null = null;
|
||||
|
||||
/** 返回主页按钮 */
|
||||
@property(Node)
|
||||
buttonHome: Node | null = null;
|
||||
@@ -62,7 +69,9 @@ export class TimeoutModal extends BaseModal {
|
||||
*/
|
||||
onViewLoad(): void {
|
||||
console.log('[TimeoutModal] onViewLoad');
|
||||
this._resolveNodes();
|
||||
this._bindButtonEvents();
|
||||
this._refreshModeButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +80,7 @@ export class TimeoutModal extends BaseModal {
|
||||
onViewShow(): void {
|
||||
super.onViewShow();
|
||||
this._updateWidget();
|
||||
this._refreshModeButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,6 +117,9 @@ export class TimeoutModal extends BaseModal {
|
||||
if (this.buttonRestart) {
|
||||
this.buttonRestart.on(Node.EventType.TOUCH_END, this._onRestartClick, this);
|
||||
}
|
||||
if (this.buttonNext) {
|
||||
this.buttonNext.on(Node.EventType.TOUCH_END, this._onNextClick, this);
|
||||
}
|
||||
if (this.buttonHome) {
|
||||
this.buttonHome.on(Node.EventType.TOUCH_END, this._onHomeClick, this);
|
||||
}
|
||||
@@ -125,11 +138,32 @@ export class TimeoutModal extends BaseModal {
|
||||
if (this.buttonRestart && this.buttonRestart.isValid) {
|
||||
this.buttonRestart.off(Node.EventType.TOUCH_END, this._onRestartClick, this);
|
||||
}
|
||||
if (this.buttonNext && this.buttonNext.isValid) {
|
||||
this.buttonNext.off(Node.EventType.TOUCH_END, this._onNextClick, this);
|
||||
}
|
||||
if (this.buttonHome && this.buttonHome.isValid) {
|
||||
this.buttonHome.off(Node.EventType.TOUCH_END, this._onHomeClick, this);
|
||||
}
|
||||
}
|
||||
|
||||
private _resolveNodes(): void {
|
||||
this.closeBtn = this.closeBtn ?? this._findChild(this.node, 'closeBtn');
|
||||
this.buttonShare = this.buttonShare ?? this._findChild(this.node, 'ButtonShare');
|
||||
this.buttonRestart = this.buttonRestart ?? this._findChild(this.node, 'ButtonRestart');
|
||||
this.buttonNext = this.buttonNext ?? this._findChild(this.node, 'ButtonNext');
|
||||
this.buttonHome = this.buttonHome ?? this._findChild(this.node, 'ButtonHome');
|
||||
}
|
||||
|
||||
private _refreshModeButtons(): void {
|
||||
const isShareMode = this._params?.shareMode === true;
|
||||
if (this.buttonRestart) {
|
||||
this.buttonRestart.active = !isShareMode;
|
||||
}
|
||||
if (this.buttonNext) {
|
||||
this.buttonNext.active = isShareMode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 求助好友按钮点击
|
||||
*/
|
||||
@@ -152,6 +186,14 @@ export class TimeoutModal extends BaseModal {
|
||||
this._callbacks.onRestart?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下一题按钮点击
|
||||
*/
|
||||
private _onNextClick(): void {
|
||||
console.log('[TimeoutModal] 点击下一题');
|
||||
this._callbacks.onNext?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主页 / 关闭按钮点击
|
||||
*/
|
||||
@@ -159,4 +201,19 @@ export class TimeoutModal extends BaseModal {
|
||||
console.log('[TimeoutModal] 点击返回主页');
|
||||
this._callbacks.onHome?.();
|
||||
}
|
||||
|
||||
private _findChild(root: Node, nodeName: string): Node | null {
|
||||
if (root.name === nodeName) {
|
||||
return root;
|
||||
}
|
||||
|
||||
for (const child of root.children) {
|
||||
const found = this._findChild(child, nodeName);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user