Files

1234 lines
46 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Button, Component, Graphics, Label, Node, Sprite, SpriteFrame, Vec3, _decorator } from 'cc';
import { AtelierService } from '../core/AtelierService';
import { CHAPTERS, CHAPTER_UNLOCK_STARS, formatLength, LEVELS } from '../core/LevelData';
import { SoundService } from '../core/SoundService';
import { AppLang, StorageService } from '../core/StorageService';
import { EmbroideryRenderer } from '../render/EmbroideryRenderer';
import { AtelierModal, AtelierTab } from './AtelierModal';
import { applyCoverBackground, applySafeContentTransform, ScreenMetrics } from './ScreenAdapter';
import {
ArtButton,
createArtButton,
createArtSprite,
createBackdropSprite,
createButton,
createLabel,
createLobbyDeskSpriteFrame,
createPanel,
createUINode,
drawEnvelopeIcon,
drawGalleryFrameIcon,
drawPadlockIcon,
drawRoundedBox,
drawSpoolIcon,
hex,
stretchToParent,
StyledButton,
} from './UiBuilder';
const { ccclass } = _decorator;
interface TrailNodeWidgets {
root: Node;
halo: Node;
clearedRing: Graphics;
clearedRingNode: Node;
unplayedVeil: Node;
checkBadge: Node;
checkBg: Graphics;
nodeSprite: Sprite;
numBg: Graphics;
numLabel: Label;
starsLabel: Label;
levelIndex: number;
}
const CHAPTER_SHORT_ZH = ['繁花', '灵禽', '萌宠', '山水', '筑影', '甜物'];
const CHAPTER_SHORT_EN = ['Flora', 'Birds', 'Pets', 'Hills', 'Villas', 'Sweets'];
// 10 关蛇形金线针迹局部坐标(以 trailLayer 中心 y=0 对称分布,方便随屏高动态拉宽上下间距)
const TRAIL_POSITIONS: [number, number][] = [
[-256, 102],
[-128, 84],
[0, 100],
[128, 82],
[256, 102],
[-256, -84],
[-128, -102],
[0, -86],
[128, -104],
[256, -84],
];
type SettingsPage = 'main' | 'guide' | 'privacy';
@ccclass('LobbyView')
export class LobbyView extends Component {
private storage!: StorageService;
private sound!: SoundService;
private atelier!: AtelierService;
private renderer!: EmbroideryRenderer;
private onSelectLevel!: (index: number) => void;
private brandTitleLabel!: Label;
private totalStarsLabel!: Label;
private settingsBtn!: ArtButton;
private easelThumbSprite!: Sprite;
private sealNode!: Node;
private sealCaptionLabel!: Label;
private sealValueLabel!: Label;
private letterCaptionLabel!: Label;
private letterReplyDot!: Node;
private workshopCaptionLabel!: Label;
private workshopBadgeNode!: Node;
private workshopBadgeLabel!: Label;
private galleryCaptionLabel!: Label;
private atelierModal!: AtelierModal;
private bgArtNode!: Node;
private safeRoot!: Node;
private topBarNode!: Node;
private easelRootNode!: Node;
private chapterRibbonNode!: Node;
private chapterStripNode!: Node;
private trailLayerNode!: Node;
private selectedInfoNode!: Node;
private workshopBtnNode!: Node;
private workshopTagNode!: Node;
private galleryBtnNode!: Node;
private galleryTagNode!: Node;
private prevChCaption!: Label;
private nextChCaption!: Label;
private chapterRibbonTitle!: Label;
private chapterRibbonSub!: Label;
private chapterPills: { btn: StyledButton; lockNode: Node }[] = [];
private trailGraphics!: Graphics;
private trailNodes: TrailNodeWidgets[] = [];
private selectedInfoLabel!: Label;
private playBtn!: ArtButton;
// 章节未解锁提示弹窗(严格集星解锁,不提供跳关)
private gateModal!: Node;
private gateTitleLabel!: Label;
private gateDescLabel!: Label;
private gateConfirmBtn!: StyledButton;
// 设置总面板(背景音乐 / 音效 / 语言 / 玩法说明 / 隐私政策 / 关于版本号)
private settingsModal!: Node;
private settingsTitleLabel!: Label;
private settingsMainGroup!: Node;
private settingsGuideGroup!: Node;
private settingsPrivacyGroup!: Node;
private bgmToggleBtn!: StyledButton;
private sfxToggleBtn!: StyledButton;
private langToggleBtn!: StyledButton;
private guideEntryBtn!: StyledButton;
private privacyEntryBtn!: StyledButton;
private aboutLabel!: Label;
private settingsCloseBtn!: StyledButton;
private settingsBackBtn!: StyledButton;
private activeChapter = 0;
private selectedLevelIndex = 0;
private initializedState = false;
private readonly thumbCache = new Map<string, SpriteFrame>();
public init(
storage: StorageService,
sound: SoundService,
atelier: AtelierService,
renderer: EmbroideryRenderer,
onSelectLevel: (index: number) => void,
): void {
this.storage = storage;
this.sound = sound;
this.atelier = atelier;
this.renderer = renderer;
this.onSelectLevel = onSelectLevel;
this.buildUI();
this.renderer.onArtworkReady(() => {
this.thumbCache.clear();
if (this.node.active) this.refreshView();
if (this.atelierModal?.node.active) this.atelierModal.refreshCurrentTab();
});
this.refresh();
}
private isEn(): boolean {
return this.storage.readLanguage() === 'en';
}
private buildUI(): void {
stretchToParent(this.node);
// 0. 宽屏/超长屏外延暖暗原木桌底
createPanel('OuterDeskSurround', 3200, 3200, { fill: '#35261a', radius: 0 }, this.node);
// 1. 底层程序化兜底 + Meowa 手绘阳光绣坊原木桌面全屏背景(按屏占比 Cover 铺满,消除全面屏黑边)
createBackdropSprite('FallbackBg', createLobbyDeskSpriteFrame(), this.node);
const bgArt = createArtSprite('MeowaLobbyBg', 'ui/bg_lobby_atelier', 750, 1334, this.node);
this.bgArtNode = bgArt.node;
// 安全区主内容容器(自动避让微信右上角胶囊、灵动岛与底部 Home 手势条)
this.safeRoot = createUINode('LobbySafeRoot', 750, 1334, this.node);
// 2. 顶部木雕招牌 + 集星徽章 + 齿轮「设置」圆钮(清爽收敛全部设置项)
const topBar = createUINode('TopBar', 710, 100, this.safeRoot);
topBar.setPosition(0, 613, 0);
this.topBarNode = topBar;
const crest = createArtSprite('BrandWoodPlaque', 'ui/ui_wood_plaque', 348, 96, topBar);
crest.node.setPosition(-146, 0, 0);
this.brandTitleLabel = createLabel('BrandTitle', '蚂蚁织画', 260, 52, {
size: 35, color: '#fff4d4', bold: true, overflow: Label.Overflow.SHRINK,
}, crest.node);
const starPill = createPanel('StarTreasury', 162, 48, {
fill: '#472f1ccc',
stroke: '#dfb464',
strokeWidth: 2.2,
radius: 24,
depth: 4,
depthColor: '#2a1a0e',
shadow: 4,
}, topBar);
starPill.node.setPosition(168, 2, 0);
const starOrb = createPanel('StarOrb', 40, 40, {
fill: '#e6a638', stroke: '#fff0be', strokeWidth: 2, radius: 20,
}, starPill.node);
starOrb.node.setPosition(-62, 0, 0);
createLabel('StarGlyph', '★', 38, 38, { size: 23, color: '#fff9e6', bold: true }, starOrb.node);
this.totalStarsLabel = createLabel('Text', '0 / 180', 110, 38, {
size: 20, color: '#fff5d8', bold: true, overflow: Label.Overflow.SHRINK,
}, starPill.node);
this.totalStarsLabel.node.setPosition(16, 0, 0);
this.settingsBtn = createArtButton({
name: 'SettingsBtn',
resourcePath: 'ui/ui_wood_round',
text: '⚙',
w: 64,
h: 64,
textColor: '#fff5d8',
fontSize: 32,
onClick: () => {
this.sound.unlock();
this.openSettings('main');
},
}, topBar);
this.settingsBtn.node.setPosition(306, 2, 0);
// 3. 中央主角:巨幅实景绣绷画架(严格跟随当前选中关)
const easelRoot = createUINode('HeroHoopEasel', 710, 420, this.safeRoot);
easelRoot.setPosition(0, 339, 0);
this.easelRootNode = easelRoot;
const hoopShadow = createPanel('HoopTableShadow', 408, 408, {
fill: '#2b190b4a', radius: 204,
}, easelRoot);
hoopShadow.node.setPosition(4, -10, 0);
const hoopPreviewNode = createUINode('HoopPreview', 392, 392, easelRoot);
this.easelThumbSprite = hoopPreviewNode.addComponent(Sprite);
this.easelThumbSprite.sizeMode = Sprite.SizeMode.CUSTOM;
// 左上角章节「委托信」木质封缄钮(与右上火漆印章对称)
const letterBtn = createArtButton({
name: 'ChapterLetterBtn',
resourcePath: 'ui/ui_wood_round',
text: '',
w: 66,
h: 66,
onClick: () => {
this.sound.unlock();
this.atelierModal.open('letters', this.activeChapter);
},
}, easelRoot);
letterBtn.node.setPosition(-172, 140, 0);
const letterIcon = createUINode('LetterIcon', 36, 36, letterBtn.node);
drawEnvelopeIcon(letterIcon.addComponent(Graphics), 1.05, '#fff3d2', '#d45a52');
this.letterReplyDot = createPanel('LetterReplyDot', 16, 16, {
fill: '#5ba852', stroke: '#fff5d4', strokeWidth: 1.8, radius: 8,
}, letterBtn.node).node;
this.letterReplyDot.setPosition(22, 22, 0);
this.letterReplyDot.active = false;
const letterTag = createPanel('LetterTag', 68, 22, {
fill: '#3d2514d9', stroke: '#d2a85f', strokeWidth: 1.2, radius: 11,
}, easelRoot);
letterTag.node.setPosition(-172, 96, 0);
this.letterCaptionLabel = createLabel('Text', '委托信', 62, 20, {
size: 12, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
}, letterTag.node);
// 右上角山茶红火漆印章:明确双行标出「难度 / 基础」或「已成画」,消除歧义
const waxSeal = createArtSprite('WaxSealBadge', 'ui/ui_wax_seal', 102, 98, easelRoot);
waxSeal.node.setPosition(168, 134, 0);
this.sealNode = waxSeal.node;
this.sealCaptionLabel = createLabel('SealCaption', '难度', 76, 18, {
size: 13, color: '#ffe4b8', bold: true, overflow: Label.Overflow.SHRINK,
}, waxSeal.node);
this.sealCaptionLabel.node.setPosition(0, 15, 0);
this.sealValueLabel = createLabel('SealText', '基础', 80, 30, {
size: 20, color: '#fff8ec', bold: true, overflow: Label.Overflow.SHRINK,
}, waxSeal.node);
this.sealValueLabel.node.setPosition(0, -8, 0);
// 左右切章木质圆钮 + 清晰「上一章 / 下一章」微标,避免被误解成切难度
const prevChBtn = createArtButton({
name: 'PrevChapterBtn',
resourcePath: 'ui/ui_wood_round',
text: '‹',
w: 76,
h: 76,
textColor: '#fff4d4',
fontSize: 40,
textOffsetY: 3,
onClick: () => {
this.sound.unlock();
const prev = (this.activeChapter - 1 + CHAPTERS.length) % CHAPTERS.length;
this.trySelectChapter(prev);
},
}, easelRoot);
prevChBtn.node.setPosition(-270, 6, 0);
const prevTag = createPanel('PrevChTag', 74, 24, {
fill: '#3d2514d9', stroke: '#d2a85f', strokeWidth: 1.3, radius: 12,
}, easelRoot);
prevTag.node.setPosition(-270, -46, 0);
this.prevChCaption = createLabel('Text', '上一章', 68, 22, {
size: 13, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
}, prevTag.node);
const nextChBtn = createArtButton({
name: 'NextChapterBtn',
resourcePath: 'ui/ui_wood_round',
text: '›',
w: 76,
h: 76,
textColor: '#fff4d4',
fontSize: 40,
textOffsetY: 3,
onClick: () => {
this.sound.unlock();
const next = (this.activeChapter + 1) % CHAPTERS.length;
this.trySelectChapter(next);
},
}, easelRoot);
nextChBtn.node.setPosition(270, 6, 0);
const nextTag = createPanel('NextChTag', 74, 24, {
fill: '#3d2514d9', stroke: '#d2a85f', strokeWidth: 1.3, radius: 12,
}, easelRoot);
nextTag.node.setPosition(270, -46, 0);
this.nextChCaption = createLabel('Text', '下一章', 68, 22, {
size: 13, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
}, nextTag.node);
// 4. 绣绷下沿:Meowa 青瓷刺绣绸带章节铭牌(双行文字精准垂直居中于绸带拱形绿布带内)
const ribbon = createArtSprite('ChapterSilkRibbon', 'ui/ui_silk_ribbon', 432, 142, this.safeRoot);
ribbon.node.setPosition(0, 117, 0);
this.chapterRibbonNode = ribbon.node;
this.chapterRibbonTitle = createLabel('RibbonTitle', '第一章 繁花集', 268, 32, {
size: 24, color: '#fff8e2', bold: true, overflow: Label.Overflow.SHRINK,
}, ribbon.node);
this.chapterRibbonTitle.node.setPosition(0, 38, 0);
this.chapterRibbonSub = createLabel('RibbonSub', '★ 0 / 30', 228, 24, {
size: 16, color: '#f7e5ad', bold: true, overflow: Label.Overflow.SHRINK,
}, ribbon.node);
this.chapterRibbonSub.node.setPosition(0, 12, 0);
// 6 枚精巧单排章节丝签(未解锁章节使用精致金属小锁图标,替代「锁」字)
const pillRow = createUINode('ChapterQuickStrip', 696, 40, this.safeRoot);
pillRow.setPosition(0, 21, 0);
this.chapterStripNode = pillRow;
const pillW = 104;
const pillGap = 12;
this.chapterPills = CHAPTERS.map((_, idx) => {
const x = (idx - 2.5) * (pillW + pillGap);
const pill = createButton({
name: `ChapterPill_${idx + 1}`,
text: CHAPTER_SHORT_ZH[idx],
w: pillW,
h: 34,
radius: 17,
fill: '#5a3b22cc',
stroke: '#c9a15d',
depth: 3,
depthColor: '#362111',
shadow: 2,
textColor: '#f8ebd0',
fontSize: 16,
onClick: () => {
this.sound.unlock();
this.trySelectChapter(idx);
},
}, pillRow);
pill.node.setPosition(x, 0, 0);
const lockNode = createUINode('LockIcon', 20, 20, pill.node);
lockNode.setPosition(-27, 0, 0);
const lockGfx = lockNode.addComponent(Graphics);
drawPadlockIcon(lockGfx, 0.94, '#d6b67d', '#ebd2a3', '#422e1d');
lockNode.active = false;
return { btn: pill, lockNode };
});
// 5. 蛇形金线针迹 10 关地图(已通关璀璨金环+绿勾+实金丝线,未通关柔和素布浅灰态,一眼分明)
const trailLayer = createUINode('StitchTrailMap', 710, 360, this.safeRoot);
trailLayer.setPosition(0, -225, 0);
this.trailLayerNode = trailLayer;
const threadNode = createUINode('GoldenStitchPath', 710, 360, trailLayer);
this.trailGraphics = threadNode.addComponent(Graphics);
this.drawGoldenStitchTrail(this.trailGraphics, 0);
this.trailNodes = TRAIL_POSITIONS.map(([px, py], slot) => {
const root = createUINode(`StageNode_${slot + 1}`, 106, 128, trailLayer);
root.setPosition(px, py, 0);
// 已通关外环(满星璨金 / 已成画翠绿)
const clearedRing = createPanel('ClearedRing', 106, 106, {
fill: '#ffd96628', stroke: '#f5c449', strokeWidth: 3.6, radius: 53,
}, root);
clearedRing.node.setPosition(0, 10, 0);
clearedRing.node.active = false;
// 当前选中关的暖金聚焦光环
const halo = createPanel('ActiveHalo', 114, 114, {
fill: '#ffde7d44', stroke: '#ffd666', strokeWidth: 3.8, radius: 57,
}, root);
halo.node.setPosition(0, 10, 0);
halo.node.active = false;
const art = createArtSprite('FloralButton', 'ui/ui_floral_node', 96, 98, root);
art.node.setPosition(0, 10, 0);
// 未通关柔暗素纱蒙层(与已通关亮彩绣花形成鲜明对比)
const unplayedVeil = createPanel('UnplayedVeil', 88, 88, {
fill: '#3d2c1d52', radius: 44,
}, root);
unplayedVeil.node.setPosition(0, 10, 0);
unplayedVeil.node.active = false;
// 已通关右上角「✓」成画小印章
const checkBadge = createPanel('ClearedCheck', 28, 28, {
fill: '#3b7b41', stroke: '#ffe499', strokeWidth: 2, radius: 14, shadow: 2,
}, root);
checkBadge.node.setPosition(34, 44, 0);
createLabel('CheckGlyph', '✓', 26, 26, { size: 17, color: '#fffdf2', bold: true }, checkBadge.node);
checkBadge.node.active = false;
const numBadge = createPanel('NumBadge', 44, 24, {
fill: '#4c321d', stroke: '#dfba6f', strokeWidth: 1.6, radius: 12,
}, root);
numBadge.node.setPosition(0, -34, 0);
const numLabel = createLabel('NumText', String(slot + 1), 40, 22, {
size: 15, color: '#fff6de', bold: true,
}, numBadge.node);
const starsLabel = createLabel('Stars', '☆☆☆', 96, 22, {
size: 16, color: '#f7c143', bold: true,
}, root);
starsLabel.node.setPosition(0, -56, 0);
const widget: TrailNodeWidgets = {
root,
halo: halo.node,
clearedRing: clearedRing.graphics,
clearedRingNode: clearedRing.node,
unplayedVeil: unplayedVeil.node,
checkBadge: checkBadge.node,
checkBg: checkBadge.graphics,
nodeSprite: art.sprite,
numBg: numBadge.graphics,
numLabel,
starsLabel,
levelIndex: slot,
};
const btn = root.addComponent(Button);
btn.transition = Button.Transition.SCALE;
btn.zoomScale = 0.92;
root.on(Button.EventType.CLICK, () => {
this.sound.unlock();
if (widget.levelIndex >= LEVELS.length) return;
if (this.selectedLevelIndex === widget.levelIndex) {
this.onSelectLevel(widget.levelIndex);
} else {
this.selectedLevelIndex = widget.levelIndex;
this.refreshView();
}
});
return widget;
});
// 6. 当前选中关卡简明信息签(统一「用线」语义)+ 底部主按钮明确标出关卡号
const infoRibbon = createPanel('SelectedInfoBar', 540, 42, {
fill: '#3c2615cc',
stroke: '#d6ae63',
strokeWidth: 1.8,
radius: 21,
shadow: 3,
}, this.safeRoot);
infoRibbon.node.setPosition(0, -473, 0);
this.selectedInfoNode = infoRibbon.node;
this.selectedInfoLabel = createLabel('InfoText', '第 1 关 金色向日葵 入门引导 · 完成即可满星 ★', 514, 34, {
size: 19, color: '#fff4d8', bold: true, overflow: Label.Overflow.SHRINK,
}, infoRibbon.node);
this.playBtn = createArtButton({
name: 'PlayMainBtn',
resourcePath: 'ui/ui_gold_btn',
text: '开始织画 · 第 1 关',
w: 400,
h: 126,
textColor: '#452408',
fontSize: 29,
textOffsetY: 3,
onClick: () => {
this.sound.unlock();
this.onSelectLevel(this.selectedLevelIndex);
},
}, this.safeRoot);
this.playBtn.node.setPosition(0, -587, 0);
// 底部左右双木雕圆钮:左「工坊」(蚂蚁工坊 + 线头提示)、右「展柜」(藏品与定制海报)
const workshopBtn = createArtButton({
name: 'WorkshopBtn',
resourcePath: 'ui/ui_wood_round',
text: '',
w: 76,
h: 76,
onClick: () => {
this.sound.unlock();
this.atelierModal.open('workshop', this.activeChapter);
},
}, this.safeRoot);
workshopBtn.node.setPosition(-270, -579, 0);
this.workshopBtnNode = workshopBtn.node;
const spoolIcon = createUINode('SpoolIcon', 40, 40, workshopBtn.node);
drawSpoolIcon(spoolIcon.addComponent(Graphics), 1.15, '#f5d896', '#91c272');
const wsBadge = createPanel('WorkshopPendingBadge', 34, 22, {
fill: '#d97822', stroke: '#fff2c2', strokeWidth: 1.6, radius: 11, shadow: 2,
}, workshopBtn.node);
wsBadge.node.setPosition(26, 26, 0);
this.workshopBadgeNode = wsBadge.node;
this.workshopBadgeLabel = createLabel('Text', '+4', 30, 20, {
size: 12, color: '#fffdf2', bold: true, overflow: Label.Overflow.SHRINK,
}, wsBadge.node);
const wsTag = createPanel('WorkshopTag', 68, 24, {
fill: '#3d2514e0', stroke: '#d2a85f', strokeWidth: 1.3, radius: 12,
}, this.safeRoot);
wsTag.node.setPosition(-270, -627, 0);
this.workshopTagNode = wsTag.node;
this.workshopCaptionLabel = createLabel('Text', '工坊', 62, 22, {
size: 13, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
}, wsTag.node);
const galleryBtn = createArtButton({
name: 'GalleryBtn',
resourcePath: 'ui/ui_wood_round',
text: '',
w: 76,
h: 76,
onClick: () => {
this.sound.unlock();
this.atelierModal.open('gallery', this.activeChapter);
},
}, this.safeRoot);
galleryBtn.node.setPosition(270, -579, 0);
this.galleryBtnNode = galleryBtn.node;
const galIcon = createUINode('GalleryIcon', 40, 40, galleryBtn.node);
drawGalleryFrameIcon(galIcon.addComponent(Graphics), 1.1, '#fff2cf', '#f0b84b');
const galTag = createPanel('GalleryTag', 68, 24, {
fill: '#3d2514e0', stroke: '#d2a85f', strokeWidth: 1.3, radius: 12,
}, this.safeRoot);
galTag.node.setPosition(270, -627, 0);
this.galleryTagNode = galTag.node;
this.galleryCaptionLabel = createLabel('Text', '展柜', 62, 22, {
size: 13, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
}, galTag.node);
// 7. 章节集星解锁弹板(无跳关,引导玩家在已解锁章节集星)
const modalRoot = createPanel('ChapterGateModal', 3200, 3200, { fill: '#1a140daa', radius: 0 }, this.safeRoot);
const gateFrame = createArtSprite('GateLinenModal', 'ui/ui_linen_modal', 590, 588, modalRoot.node);
gateFrame.node.setPosition(0, 20, 0);
const gateLockBadge = createPanel('GateLockBadge', 64, 64, {
fill: '#55371e', stroke: '#e2bc72', strokeWidth: 2.6, radius: 32, depth: 3, depthColor: '#2d1c0d', shadow: 3,
}, gateFrame.node);
gateLockBadge.node.setPosition(0, 126, 0);
const gateLockIcon = createUINode('GateLockIcon', 44, 44, gateLockBadge.node);
drawPadlockIcon(gateLockIcon.addComponent(Graphics), 1.95, '#f2cc78', '#fff0c4', '#472d16');
this.gateTitleLabel = createLabel('GateTitle', '章节未解锁', 450, 42, {
size: 29, color: '#3b2814', bold: true, overflow: Label.Overflow.SHRINK,
}, gateFrame.node);
this.gateTitleLabel.node.setPosition(0, 58, 0);
this.gateDescLabel = createLabel('GateDesc', '', 446, 126, {
size: 21, color: '#5b462a', overflow: Label.Overflow.SHRINK,
}, gateFrame.node);
this.gateDescLabel.node.setPosition(0, -34, 0);
this.gateConfirmBtn = createButton({
name: 'GateConfirmBtn',
text: '我知道了',
w: 246,
h: 58,
radius: 24,
fill: '#4d6f49',
stroke: '#8ab084',
depth: 5,
depthColor: '#2e472b',
textColor: '#fff9e8',
fontSize: 23,
onClick: () => {
this.gateModal.active = false;
},
}, gateFrame.node);
this.gateConfirmBtn.node.setPosition(0, -158, 0);
this.gateModal = modalRoot.node;
this.gateModal.active = false;
// 8. 齿轮「设置」总弹窗(背景音乐 / 音效 / 语言 / 图文玩法说明 / 隐私政策 / 版本关于)
this.buildSettingsModal();
// 9. 「我的绣坊」统一三页签弹窗(蚂蚁工坊 / 绣品展柜 / 委托信箱)
const atelierNode = createUINode('AtelierModalRoot', 750, 1334, this.safeRoot);
this.atelierModal = atelierNode.addComponent(AtelierModal);
this.atelierModal.init(
this.storage,
this.sound,
this.atelier,
this.renderer,
idx => this.getThumbnail(idx, true),
() => this.refreshView(),
);
}
public applyScreenMetrics(m: ScreenMetrics): void {
if (this.bgArtNode) applyCoverBackground(this.bgArtNode, m);
if (this.safeRoot) applySafeContentTransform(this.safeRoot, m);
if (!this.topBarNode) return;
// 全面屏动态贴顶/贴底锚定并均匀拉宽各板块间距,消除上下大片空白与中间拥挤
const h = m.safeHalfH;
const e = m.extraH;
const topBarY = h - 54;
const easelY = topBarY - 274 - e * 0.14;
const ribbonY = easelY - 222;
const stripY = ribbonY - 96 - e * 0.10;
const playY = -h + 80;
const infoY = playY + 114 + e * 0.14;
const stripBottom = stripY - 19;
const infoTop = infoY + 21;
const trailCenterY = (stripBottom + infoTop) / 2 - 4;
this.topBarNode.setPosition(0, topBarY, 0);
this.easelRootNode.setPosition(0, easelY, 0);
this.chapterRibbonNode.setPosition(0, ribbonY, 0);
this.chapterStripNode.setPosition(0, stripY, 0);
this.trailLayerNode.setPosition(0, trailCenterY, 0);
this.selectedInfoNode.setPosition(0, infoY, 0);
this.playBtn.node.setPosition(0, playY, 0);
this.workshopBtnNode.setPosition(-270, playY + 8, 0);
this.workshopTagNode.setPosition(-270, playY - 40, 0);
this.galleryBtnNode.setPosition(270, playY + 8, 0);
this.galleryTagNode.setPosition(270, playY - 40, 0);
}
private buildSettingsModal(): void {
const scrim = createPanel('SettingsModalScrim', 3200, 3200, { fill: '#18120cb8', radius: 0 }, this.safeRoot);
this.settingsModal = scrim.node;
const frame = createArtSprite('SettingsLinenFrame', 'ui/ui_linen_modal', 646, 680, scrim.node);
frame.node.setPosition(0, 10, 0);
this.settingsTitleLabel = createLabel('SettingsTitle', '设 置', 440, 44, {
size: 31, color: '#3b2713', bold: true,
}, frame.node);
this.settingsTitleLabel.node.setPosition(0, 136, 0);
// ===== 子页 1:设置主面板 =====
this.settingsMainGroup = createUINode('SettingsMainGroup', 520, 410, frame.node);
this.settingsMainGroup.setPosition(0, -68, 0);
this.bgmToggleBtn = createButton({
name: 'BgmToggleBtn',
text: '背景音乐:开',
w: 228,
h: 62,
radius: 20,
fill: '#e5efd9',
stroke: '#8ab078',
depth: 5,
depthColor: '#547347',
textColor: '#2d4623',
fontSize: 21,
onClick: () => {
this.sound.toggleBgm();
this.syncSettingsState();
},
}, this.settingsMainGroup);
this.bgmToggleBtn.node.setPosition(-122, 132, 0);
this.sfxToggleBtn = createButton({
name: 'SfxToggleBtn',
text: '游戏音效:开',
w: 228,
h: 62,
radius: 20,
fill: '#e5efd9',
stroke: '#8ab078',
depth: 5,
depthColor: '#547347',
textColor: '#2d4623',
fontSize: 21,
onClick: () => {
this.sound.toggle();
this.syncSettingsState();
},
}, this.settingsMainGroup);
this.sfxToggleBtn.node.setPosition(122, 132, 0);
this.langToggleBtn = createButton({
name: 'LangToggleBtn',
text: '语言:简体中文',
w: 472,
h: 58,
radius: 20,
fill: '#f6ead0',
stroke: '#d3b277',
depth: 4,
depthColor: '#a6864d',
textColor: '#4c3416',
fontSize: 21,
onClick: () => {
const next: AppLang = this.isEn() ? 'zh' : 'en';
this.storage.saveLanguage(next);
this.refreshView();
this.syncSettingsState();
},
}, this.settingsMainGroup);
this.langToggleBtn.node.setPosition(0, 52, 0);
this.guideEntryBtn = createButton({
name: 'GuideEntryBtn',
text: '玩法说明(图文)',
w: 228,
h: 62,
radius: 20,
fill: '#faedd0',
stroke: '#dbb368',
depth: 5,
depthColor: '#a47d38',
textColor: '#533510',
fontSize: 20,
onClick: () => {
this.openSettings('guide');
},
}, this.settingsMainGroup);
this.guideEntryBtn.node.setPosition(-122, -26, 0);
this.privacyEntryBtn = createButton({
name: 'PrivacyEntryBtn',
text: '隐私政策',
w: 228,
h: 62,
radius: 20,
fill: '#faedd0',
stroke: '#dbb368',
depth: 5,
depthColor: '#a47d38',
textColor: '#533510',
fontSize: 20,
onClick: () => {
this.openSettings('privacy');
},
}, this.settingsMainGroup);
this.privacyEntryBtn.node.setPosition(122, -26, 0);
const aboutPill = createPanel('AboutPill', 472, 42, {
fill: '#ece0c3', stroke: '#d2be96', strokeWidth: 1.4, radius: 14,
}, this.settingsMainGroup);
aboutPill.node.setPosition(0, -96, 0);
this.aboutLabel = createLabel('AboutText', '关于 · 蚂蚁织画 v1.0.0(纯单机手作版)', 452, 34, {
size: 17, color: '#6b5538', bold: true, overflow: Label.Overflow.SHRINK,
}, aboutPill.node);
this.settingsCloseBtn = createButton({
name: 'SettingsCloseBtn',
text: '关 闭',
w: 236,
h: 58,
radius: 22,
fill: '#567547',
stroke: '#8ab07a',
depth: 5,
depthColor: '#344c29',
textColor: '#fff9e8',
fontSize: 23,
onClick: () => {
this.settingsModal.active = false;
},
}, this.settingsMainGroup);
this.settingsCloseBtn.node.setPosition(0, -168, 0);
// ===== 子页 2:图文玩法说明 =====
this.settingsGuideGroup = createUINode('SettingsGuideGroup', 500, 410, frame.node);
this.settingsGuideGroup.setPosition(0, -68, 0);
const steps: { num: string; color: string; title: string; desc: string; y: number }[] = [
{
num: '1',
color: '#d9932c',
title: '按住蚁巢,起手拖线',
desc: '按住绣布下方发光的「蚁巢」拖出毛线,或在桌面空白处滑动遥控。',
y: 120,
},
{
num: '2',
color: '#5a804b',
title: '串同色球,送进花瓣',
desc: '每只蚂蚁最多串 2 颗同色毛线球,依次穿过呼吸闪烁的同色目标针位。',
y: 26,
},
{
num: '3',
color: '#c45b58',
title: '用线越短,星级越高',
desc: '右上「用线」进度条标有 3★ / 2★ 刻度线;注意绕开水洼与不交叉规则。',
y: -68,
},
];
for (const st of steps) {
const card = createPanel(`GuideStep_${st.num}`, 476, 82, {
fill: '#f7ecd4', stroke: '#d6be92', strokeWidth: 1.6, radius: 18,
}, this.settingsGuideGroup);
card.node.setPosition(0, st.y, 0);
const orb = createPanel('Orb', 46, 46, { fill: st.color, radius: 23 }, card.node);
orb.node.setPosition(-196, 0, 0);
createLabel('Num', st.num, 42, 42, { size: 22, color: '#fff9eb', bold: true }, orb.node);
const titleL = createLabel('StepTitle', st.title, 386, 28, {
size: 19, color: '#3b2713', bold: true, align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
}, card.node);
titleL.node.setPosition(34, 18, 0);
const descL = createLabel('StepDesc', st.desc, 386, 42, {
size: 15, lineHeight: 20, color: '#614d33', align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
}, card.node);
descL.node.setPosition(34, -14, 0);
}
// ===== 子页 3:隐私政策(合规静态展示页) =====
this.settingsPrivacyGroup = createUINode('SettingsPrivacyGroup', 500, 410, frame.node);
this.settingsPrivacyGroup.setPosition(0, -68, 0);
const policyBox = createPanel('PrivacyBox', 476, 276, {
fill: '#f8efda', stroke: '#d4bc90', strokeWidth: 1.6, radius: 18,
}, this.settingsPrivacyGroup);
policyBox.node.setPosition(0, 26, 0);
createLabel(
'PrivacyBody',
'《蚂蚁织画》隐私保护指引(v1.0.0)\n\n' +
'1. 本游戏为纯单机版本,不收集、不存储、不上传任何个人身份信息、手机号、地理位置或设备隐私数据。\n' +
'2. 关卡星级、用线记录及音效/语言偏好仅保存于本机缓存,卸载或清理缓存即可移除。\n' +
'3.「保存绣画」仅在您主动点击时生成本地图片,不上传服务器。\n' +
'4. 后续如新增好友排行等联网能力,将在使用前通过微信官方隐私授权弹窗征得同意。',
442,
250,
{ size: 15, lineHeight: 23, color: '#4d3b24', align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK },
policyBox.node,
);
// 子页共用「返回设置」按钮
this.settingsBackBtn = createButton({
name: 'SettingsBackBtn',
text: '返回设置',
w: 236,
h: 56,
radius: 22,
fill: '#e3a23a',
stroke: '#f7cf7d',
depth: 5,
depthColor: '#9e6616',
textColor: '#3d2207',
fontSize: 22,
onClick: () => {
this.openSettings('main');
},
}, frame.node);
this.settingsBackBtn.node.setPosition(0, -236, 0);
this.settingsModal.active = false;
}
private openSettings(page: SettingsPage): void {
const en = this.isEn();
this.settingsModal.active = true;
this.settingsMainGroup.active = page === 'main';
this.settingsGuideGroup.active = page === 'guide';
this.settingsPrivacyGroup.active = page === 'privacy';
this.settingsBackBtn.node.active = page !== 'main';
if (page === 'main') this.settingsTitleLabel.string = en ? 'Settings' : '设 置';
else if (page === 'guide') this.settingsTitleLabel.string = en ? 'How to Play' : '玩法说明';
else this.settingsTitleLabel.string = en ? 'Privacy Policy' : '隐私政策';
this.syncSettingsState();
}
private syncSettingsState(): void {
const en = this.isEn();
const bgmOn = this.sound.isBgmEnabled();
const sfxOn = this.sound.isEnabled();
this.bgmToggleBtn.label.string = en
? `Music: ${bgmOn ? 'ON' : 'OFF'}`
: `背景音乐:${bgmOn ? '开' : '关'}`;
this.bgmToggleBtn.setStyle(
bgmOn ? '#e5efd9' : '#ebe3d3',
bgmOn ? '#8ab078' : '#c6baa3',
bgmOn ? '#2d4623' : '#736552',
bgmOn ? '#547347' : '#9c8f78',
);
this.sfxToggleBtn.label.string = en
? `SFX: ${sfxOn ? 'ON' : 'OFF'}`
: `游戏音效:${sfxOn ? '开' : '关'}`;
this.sfxToggleBtn.setStyle(
sfxOn ? '#e5efd9' : '#ebe3d3',
sfxOn ? '#8ab078' : '#c6baa3',
sfxOn ? '#2d4623' : '#736552',
sfxOn ? '#547347' : '#9c8f78',
);
this.langToggleBtn.label.string = en ? 'Language: English' : '界面语言:简体中文';
this.guideEntryBtn.label.string = en ? 'How to Play' : '玩法说明(图文)';
this.privacyEntryBtn.label.string = en ? 'Privacy Policy' : '隐私政策';
this.aboutLabel.string = en ? 'About · Ant Stitch v1.0.0 (Offline Edition)' : '关于 · 蚂蚁织画 v1.0.0(纯单机手作版)';
this.settingsCloseBtn.label.string = en ? 'Close' : '关 闭';
this.settingsBackBtn.label.string = en ? 'Back' : '返回设置';
}
/** 绘制串联 10 枚刺绣花扣的进度丝线:已通关区段为璀璨实金线,未通关区段为素雅虚针线 */
private drawGoldenStitchTrail(g: Graphics, clearedSlots: number): void {
g.clear();
// 9 段相邻关卡连线(第 4->5 段包含右拐折返路径)
const chains: [number, number][][] = [
[[TRAIL_POSITIONS[0][0], TRAIL_POSITIONS[0][1] + 10], [TRAIL_POSITIONS[1][0], TRAIL_POSITIONS[1][1] + 10]],
[[TRAIL_POSITIONS[1][0], TRAIL_POSITIONS[1][1] + 10], [TRAIL_POSITIONS[2][0], TRAIL_POSITIONS[2][1] + 10]],
[[TRAIL_POSITIONS[2][0], TRAIL_POSITIONS[2][1] + 10], [TRAIL_POSITIONS[3][0], TRAIL_POSITIONS[3][1] + 10]],
[[TRAIL_POSITIONS[3][0], TRAIL_POSITIONS[3][1] + 10], [TRAIL_POSITIONS[4][0], TRAIL_POSITIONS[4][1] + 10]],
[
[TRAIL_POSITIONS[4][0], TRAIL_POSITIONS[4][1] + 10],
[318, -158],
[304, -220],
[-304, -220],
[-318, -258],
[TRAIL_POSITIONS[5][0], TRAIL_POSITIONS[5][1] + 10],
],
[[TRAIL_POSITIONS[5][0], TRAIL_POSITIONS[5][1] + 10], [TRAIL_POSITIONS[6][0], TRAIL_POSITIONS[6][1] + 10]],
[[TRAIL_POSITIONS[6][0], TRAIL_POSITIONS[6][1] + 10], [TRAIL_POSITIONS[7][0], TRAIL_POSITIONS[7][1] + 10]],
[[TRAIL_POSITIONS[7][0], TRAIL_POSITIONS[7][1] + 10], [TRAIL_POSITIONS[8][0], TRAIL_POSITIONS[8][1] + 10]],
[[TRAIL_POSITIONS[8][0], TRAIL_POSITIONS[8][1] + 10], [TRAIL_POSITIONS[9][0], TRAIL_POSITIONS[9][1] + 10]],
];
const drawChain = (pts: [number, number][], solidGold: boolean) => {
if (solidGold) {
g.strokeColor = hex('#2e1a0c78');
g.lineWidth = 6.2;
g.moveTo(pts[0][0], pts[0][1] - 2);
for (let i = 1; i < pts.length; i++) g.lineTo(pts[i][0], pts[i][1] - 2);
g.stroke();
g.strokeColor = hex('#ffd966');
g.lineWidth = 4.2;
g.moveTo(pts[0][0], pts[0][1]);
for (let i = 1; i < pts.length; i++) g.lineTo(pts[i][0], pts[i][1]);
g.stroke();
return;
}
// 未通关:素雅虚针线
g.strokeColor = hex('#d9bc8c80');
g.lineWidth = 2.6;
const dash = 10;
const gap = 9;
for (let i = 0; i < pts.length - 1; i++) {
const [x1, y1] = pts[i];
const [x2, y2] = pts[i + 1];
const dist = Math.hypot(x2 - x1, y2 - y1);
const ux = (x2 - x1) / dist;
const uy = (y2 - y1) / dist;
let pos = 0;
while (pos < dist) {
const end = Math.min(dist, pos + dash);
g.moveTo(x1 + ux * pos, y1 + uy * pos);
g.lineTo(x1 + ux * end, y1 + uy * end);
pos = end + gap;
}
}
g.stroke();
};
chains.forEach((pts, idx) => {
drawChain(pts, idx < clearedSlots);
});
}
private getTotalStars(): number {
return LEVELS.reduce((sum, entry) => sum + (this.storage.getRecord(entry)?.stars ?? 0), 0);
}
private isChapterUnlocked(idx: number): boolean {
if (idx <= 0) return true;
const req = CHAPTER_UNLOCK_STARS[idx] ?? 0;
return this.getTotalStars() >= req;
}
private switchToChapter(idx: number): void {
this.activeChapter = idx;
const ch = CHAPTERS[idx] ?? CHAPTERS[0];
let pick = ch.startIndex;
for (let s = 0; s < ch.count; s++) {
const lvIdx = ch.startIndex + s;
if (!(this.storage.getRecord(LEVELS[lvIdx])?.stars)) {
pick = lvIdx;
break;
}
}
this.selectedLevelIndex = pick;
this.refreshView();
}
private trySelectChapter(idx: number): void {
if (this.isChapterUnlocked(idx)) {
this.switchToChapter(idx);
return;
}
const en = this.isEn();
const ch = CHAPTERS[idx];
const req = CHAPTER_UNLOCK_STARS[idx] ?? 0;
const cur = this.getTotalStars();
const need = Math.max(1, req - cur);
this.gateTitleLabel.string = ch.name;
this.gateDescLabel.string = en
? `Collect ${req} ★ to unlock this chapter.\nCurrent: ${cur} ★ (${need} ★ more needed)`
: `需集齐 ${req} ★ 解锁本章\n当前已获得 ${cur} ★,还差 ${need} ★\n在前面章节争取更多星星吧!`;
this.gateConfirmBtn.label.string = en ? 'Got It' : '我知道了';
this.gateModal.active = true;
}
private findRecommendedIndex(): number {
const unplayed = LEVELS.findIndex(
entry => this.isChapterUnlocked(entry.chapter) && !(this.storage.getRecord(entry)?.stars),
);
if (unplayed !== -1) return unplayed;
const underThree = LEVELS.findIndex(
entry => this.isChapterUnlocked(entry.chapter) && (this.storage.getRecord(entry)?.stars ?? 0) < 3,
);
return underThree !== -1 ? underThree : 0;
}
public syncSoundButton(): void {
this.syncSettingsState();
}
public openAtelier(tab: AtelierTab, chapterIndex: number, focusLevelIndex?: number): void {
this.atelierModal?.open(tab, chapterIndex, focusLevelIndex);
}
private getThumbnail(levelIndex: number, completed: boolean): SpriteFrame {
const entry = LEVELS[levelIndex];
const key = `${entry.id}:${completed ? '1' : '0'}:420`;
let frame = this.thumbCache.get(key);
if (!frame) {
frame = this.renderer.createThumbnailSpriteFrame(entry, completed, 420);
this.thumbCache.set(key, frame);
}
return frame;
}
private refreshView(): void {
const en = this.isEn();
const totalEarned = this.getTotalStars();
const maxStars = LEVELS.length * 3;
this.brandTitleLabel.string = en ? 'Ant Stitch' : '蚂蚁织画';
this.prevChCaption.string = en ? 'Prev Ch' : '上一章';
this.nextChCaption.string = en ? 'Next Ch' : '下一章';
this.letterCaptionLabel.string = en ? 'Letter' : '委托信';
this.workshopCaptionLabel.string = en ? 'Craft' : '工坊';
this.galleryCaptionLabel.string = en ? 'Gallery' : '展柜';
this.letterReplyDot.active = this.atelier.isChapterReplyUnlocked(
this.activeChapter,
lv => this.storage.getRecord(lv),
);
const pending = this.atelier.getState().pendingThreads;
this.workshopBadgeNode.active = pending > 0;
if (pending > 0) this.workshopBadgeLabel.string = `+${pending}`;
this.totalStarsLabel.string = `${totalEarned} / ${maxStars}`;
const chapter = CHAPTERS[this.activeChapter] ?? CHAPTERS[0];
const chLevels = LEVELS.slice(chapter.startIndex, chapter.startIndex + chapter.count);
const chEarned = chLevels.reduce((sum, entry) => sum + (this.storage.getRecord(entry)?.stars ?? 0), 0);
this.chapterRibbonTitle.string = chapter.name.replace(' · ', ' ');
this.chapterRibbonSub.string = `★ ${chEarned} / ${chapter.count * 3} ${chapter.subtitle.split('·')[0].trim()}`;
const shortList = en ? CHAPTER_SHORT_EN : CHAPTER_SHORT_ZH;
CHAPTERS.forEach((_, idx) => {
const unlocked = this.isChapterUnlocked(idx);
const active = idx === this.activeChapter;
const { btn, lockNode } = this.chapterPills[idx];
btn.label.string = shortList[idx];
lockNode.active = !unlocked;
btn.label.node.setPosition(unlocked ? 0 : 10, 1, 0);
btn.setStyle(
active ? '#c85b56' : (unlocked ? '#593b23dd' : '#4a3a2dcc'),
active ? '#f7d58b' : (unlocked ? '#cfa663' : '#8d7a62'),
active ? '#fff8e6' : (unlocked ? '#f8ebd0' : '#cbbca9'),
active ? '#823430' : '#331f10',
);
});
// 中央绣绷严格跟随当前选中关
const selected = LEVELS[this.selectedLevelIndex] ?? LEVELS[0];
const selRec = this.storage.getRecord(selected);
const selStars = selRec?.stars ?? 0;
this.easelThumbSprite.spriteFrame = this.getThumbnail(this.selectedLevelIndex, selStars > 0);
// 火漆印章双行语义清晰:「难度 / 基础」或「状态 / 满星」
const isBoss = selected.difficulty.includes('Boss') || selected.difficulty.includes('宗师');
if (selStars === 3) {
this.sealCaptionLabel.string = en ? 'Status' : '已完成';
this.sealValueLabel.string = en ? '3★ Max' : '满星';
} else if (selStars > 0) {
this.sealCaptionLabel.string = en ? 'Status' : '已完成';
this.sealValueLabel.string = en ? 'Done' : '已成画';
} else {
this.sealCaptionLabel.string = en ? 'Level' : '难度';
this.sealValueLabel.string = isBoss ? (en ? 'Boss' : '终考') : selected.difficulty;
}
this.sealNode.active = true;
// 统一叫「用线」,并让底部按钮与中央预览严格对齐到同一关
const lvNum = this.selectedLevelIndex + 1;
const metricText = selRec
? `${en ? 'Best Yarn' : '最佳用线'} ${formatLength(selRec.length)}`
: selected.id === 'first-stitch'
? (en ? 'Tutorial · Clear for 3★' : '入门引导 · 完成即可满星 ★')
: `${en ? '3★ Yarn' : '三星用线'} ≤ ${formatLength(selected.threeStar)}`;
this.selectedInfoLabel.string = en
? `Stage ${lvNum} ${selected.name} ${metricText}`
: `第 ${lvNum} 关 ${selected.name} ${metricText}`;
if (this.playBtn.label) {
this.playBtn.label.string = en
? `${selStars > 0 ? 'Replay' : 'Stitch'} · Lv.${lvNum}`
: `${selStars > 0 ? '重温' : '开始织画'} · 第 ${lvNum} 关`;
}
// 计算本章已连续通关进度,点亮对应实金丝线
let clearedTrailCount = 0;
for (let s = 0; s < chapter.count; s++) {
const rec = this.storage.getRecord(LEVELS[chapter.startIndex + s]);
if (rec && rec.stars > 0) clearedTrailCount = s + 1;
}
this.drawGoldenStitchTrail(this.trailGraphics, clearedTrailCount);
this.trailNodes.forEach((node, slot) => {
const lvIdx = chapter.startIndex + slot;
if (lvIdx >= LEVELS.length || slot >= chapter.count) {
node.root.active = false;
return;
}
node.root.active = true;
node.levelIndex = lvIdx;
const entry = LEVELS[lvIdx];
const rec = this.storage.getRecord(entry);
const stars = rec?.stars ?? 0;
const cleared = stars > 0;
const isSelected = lvIdx === this.selectedLevelIndex;
// 三态强烈视觉层级:已通关(璀璨金/绿环 + ✓ 印章 + 满彩)| 当前选关(1.16× 聚焦金环 + 山茶红号牌)| 未通关(素纱柔暗待绣态)
node.halo.active = isSelected;
node.clearedRingNode.active = cleared && !isSelected;
if (cleared && !isSelected) {
drawRoundedBox(node.clearedRing, 106, 106, {
fill: stars === 3 ? '#ffd9662e' : '#7ec26224',
stroke: stars === 3 ? '#f5c449' : '#74b85b',
strokeWidth: 3.6,
radius: 53,
});
}
node.checkBadge.active = cleared;
if (cleared) {
drawRoundedBox(node.checkBg, 28, 28, {
fill: stars === 3 ? '#d88e1d' : '#3b7b41',
stroke: '#fff0b8',
strokeWidth: 2,
radius: 14,
shadow: 2,
});
}
node.unplayedVeil.active = !cleared && !isSelected;
const sc = isSelected ? 1.16 : cleared ? 1.03 : 0.94;
node.root.setScale(new Vec3(sc, sc, 1));
node.nodeSprite.color = cleared || isSelected ? hex('#ffffff') : hex('#b6a793');
drawRoundedBox(node.numBg, 44, 24, {
fill: isSelected ? '#c85450' : cleared ? '#3c7640' : '#3a2819',
stroke: isSelected ? '#ffe499' : cleared ? '#f2cf78' : '#8c7252',
strokeWidth: isSelected ? 2 : 1.5,
radius: 12,
});
node.numLabel.string = String(lvIdx + 1);
node.numLabel.color = hex(cleared || isSelected ? '#fff9e6' : '#c8b8a2');
node.starsLabel.string = '★'.repeat(stars) + '☆'.repeat(3 - stars);
node.starsLabel.color = hex(cleared ? '#ffd052' : '#d6c2a552');
});
}
public refresh(): void {
const recIdx = this.findRecommendedIndex();
if (!this.initializedState) {
this.selectedLevelIndex = recIdx;
this.activeChapter = LEVELS[recIdx]?.chapter ?? 0;
this.initializedState = true;
} else {
if (!this.isChapterUnlocked(this.activeChapter)) {
this.selectedLevelIndex = recIdx;
this.activeChapter = LEVELS[recIdx]?.chapter ?? 0;
} else {
const curRec = this.storage.getRecord(LEVELS[this.selectedLevelIndex]);
if (curRec && curRec.stars > 0 && this.selectedLevelIndex + 1 < LEVELS.length) {
const nextLv = LEVELS[this.selectedLevelIndex + 1];
if (nextLv.chapter === this.activeChapter) {
this.selectedLevelIndex++;
}
}
}
}
this.refreshView();
}
}