feat: 优化通关效果
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { _decorator, Node, Button, Sprite, Label, Toggle, ScrollView, EditBox, instantiate, UITransform, Vec2, EventTouch, EffectAsset } from 'cc';
|
||||
import { _decorator, Node, Button, Sprite, Label, Toggle, ScrollView, EditBox, instantiate, UITransform, Vec2, EventTouch, EffectAsset, Prefab } from 'cc';
|
||||
import { BaseView } from 'db://assets/scripts/core/BaseView';
|
||||
import { ViewManager } from 'db://assets/scripts/core/ViewManager';
|
||||
import { CommonModal } from 'db://assets/prefabs/CommonModal';
|
||||
import { CompletedLevelsManager } from 'db://assets/scripts/utils/CompletedLevelsManager';
|
||||
import { ToastManager } from 'db://assets/scripts/utils/ToastManager';
|
||||
import { ShareManager } from 'db://assets/scripts/utils/ShareManager';
|
||||
@@ -30,6 +31,7 @@ const LAYOUT_CONFIG = {
|
||||
CENTER_ROWS: 2,
|
||||
VIEW_WIDTH: 900,
|
||||
VIEW_HEIGHT: 1300,
|
||||
LIST_BOTTOM_GAP_TO_TITLE: 54,
|
||||
};
|
||||
|
||||
/** 必须选择的关卡数量 */
|
||||
@@ -67,6 +69,9 @@ export class PageWriteLevels extends BaseView {
|
||||
@property({ type: EffectAsset, tooltip: '关卡封面圆角材质 EffectAsset' })
|
||||
roundedSpriteEffect: EffectAsset | null = null;
|
||||
|
||||
@property({ type: Prefab, tooltip: '通用弹窗预制体' })
|
||||
commonModalPrefab: Prefab | null = null;
|
||||
|
||||
@property({ tooltip: '关卡封面圆角半径比例(相对于短边,0-0.5)' })
|
||||
coverCornerRadius: number = 0.1;
|
||||
|
||||
@@ -86,6 +91,7 @@ export class PageWriteLevels extends BaseView {
|
||||
console.log('[PageWriteLevels] onViewLoad');
|
||||
this._initButtons();
|
||||
this._initScrollView();
|
||||
this._resizeScrollViewport();
|
||||
this._updateSelectionUI();
|
||||
}
|
||||
|
||||
@@ -132,12 +138,51 @@ export class PageWriteLevels extends BaseView {
|
||||
|
||||
onViewShow(): void {
|
||||
console.log('[PageWriteLevels] onViewShow');
|
||||
this._resizeScrollViewport();
|
||||
this._updateContentSize();
|
||||
|
||||
// 仅首次初始化列表,从预览页返回时保留选中状态
|
||||
if (this._itemNodes.length === 0) {
|
||||
void this._initLevelList();
|
||||
}
|
||||
}
|
||||
|
||||
private _resizeScrollViewport(): void {
|
||||
if (!this.scrollView || !this._viewTransform || !this.shareTitleEditBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rootTransform = this.node.getComponent(UITransform);
|
||||
const scrollTransform = this.scrollView.getComponent(UITransform);
|
||||
const scrollWidget = this.scrollView.getComponent('cc.Widget') as any;
|
||||
const shareTitleTransform = this.shareTitleEditBox.getComponent(UITransform);
|
||||
const shareTitleWidget = this.shareTitleEditBox.getComponent('cc.Widget') as any;
|
||||
const bottomMaskNode = this.scrollView.getChildByName('ScrolViewMask');
|
||||
|
||||
if (!rootTransform || !scrollTransform || !shareTitleTransform || !scrollWidget || !shareTitleWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
const topInset = Number(scrollWidget.top ?? 0);
|
||||
const shareBottomInset = Number(shareTitleWidget.bottom ?? 0);
|
||||
const shareTitleHeight = shareTitleTransform.height * Math.abs(this.shareTitleEditBox.scale.y);
|
||||
const nextHeight = Math.max(
|
||||
LAYOUT_CONFIG.VIEW_HEIGHT,
|
||||
rootTransform.height - topInset - shareBottomInset - shareTitleHeight - LAYOUT_CONFIG.LIST_BOTTOM_GAP_TO_TITLE,
|
||||
);
|
||||
|
||||
scrollTransform.setContentSize(scrollTransform.width, nextHeight);
|
||||
this._viewTransform.setContentSize(this._viewTransform.width, nextHeight);
|
||||
|
||||
if (bottomMaskNode) {
|
||||
bottomMaskNode.setPosition(
|
||||
bottomMaskNode.position.x,
|
||||
-(nextHeight / 2) + 30,
|
||||
bottomMaskNode.position.z,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async _initLevelList(): Promise<void> {
|
||||
this._clearList();
|
||||
|
||||
@@ -474,11 +519,11 @@ export class PageWriteLevels extends BaseView {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 CompleteButton 和 PreviewButton 的可用状态
|
||||
// 预览与分享数量不足时也要允许点击,统一弹出提示弹窗。
|
||||
if (this.completeBtn) {
|
||||
const btn = this.completeBtn.getComponent(Button);
|
||||
if (btn) {
|
||||
btn.interactable = isFull;
|
||||
btn.interactable = true;
|
||||
}
|
||||
}
|
||||
if (this.previewBtn) {
|
||||
@@ -501,18 +546,31 @@ export class PageWriteLevels extends BaseView {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否已选满关卡,未满则 Toast 提示
|
||||
* 校验是否已选满关卡,未满则弹出统一提示弹窗
|
||||
* @returns true 表示校验通过
|
||||
*/
|
||||
private _validateSelection(): boolean {
|
||||
if (this._selectedIndices.size < MAX_SELECTION) {
|
||||
const remaining = MAX_SELECTION - this._selectedIndices.size;
|
||||
ToastManager.instance.show(`还需选择${remaining}个关卡`);
|
||||
this._showSelectionRequiredModal();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private _showSelectionRequiredModal(): void {
|
||||
if (!this.commonModalPrefab) {
|
||||
console.warn('[PageWriteLevels] commonModalPrefab 未设置,回退为 Toast 提示');
|
||||
ToastManager.instance.show(`请选择${MAX_SELECTION}个关卡后再预览或分享`);
|
||||
return;
|
||||
}
|
||||
|
||||
CommonModal.show(this.commonModalPrefab, {
|
||||
title: '提示',
|
||||
content: `要选择${MAX_SELECTION}个关卡才能分享和预览`,
|
||||
buttonConfirm: '知道了',
|
||||
});
|
||||
}
|
||||
|
||||
private _onPreviewClick(): void {
|
||||
AudioManager.instance.playButtonClick();
|
||||
if (!this._validateSelection()) return;
|
||||
|
||||
Reference in New Issue
Block a user