chore: freeze v1.1.3 filing submission build (60 levels, full-screen safe layout)
This commit is contained in:
commit
96c19dca82
174 files changed
+37935
No files matched your search
@@ -0,0 +1,815 @@
|
||||
import { Component, Graphics, Label, Node, Sprite, SpriteFrame, _decorator } from 'cc';
|
||||
import {
|
||||
ANT_DIARIES,
|
||||
AtelierService,
|
||||
IDLE_MAX_THREADS,
|
||||
POSTER_FRAMES,
|
||||
POSTER_QUOTES,
|
||||
PosterFrameId,
|
||||
} from '../core/AtelierService';
|
||||
import { CHAPTERS, CHAPTER_UNLOCK_STARS, formatLength, LEVELS } from '../core/LevelData';
|
||||
import { SoundService } from '../core/SoundService';
|
||||
import { StorageService } from '../core/StorageService';
|
||||
import { EmbroideryRenderer } from '../render/EmbroideryRenderer';
|
||||
import {
|
||||
createArtSprite,
|
||||
createButton,
|
||||
createLabel,
|
||||
createPanel,
|
||||
createUINode,
|
||||
drawPadlockIcon,
|
||||
drawRoundedBox,
|
||||
hex,
|
||||
stretchToParent,
|
||||
StyledButton,
|
||||
} from './UiBuilder';
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
export type AtelierTab = 'workshop' | 'gallery' | 'letters';
|
||||
|
||||
const CHAPTER_SHORT_ZH = ['繁花', '灵禽', '萌宠', '山水', '筑影', '甜物'];
|
||||
const CHAPTER_SHORT_EN = ['Flora', 'Birds', 'Pets', 'Hills', 'Villas', 'Sweets'];
|
||||
|
||||
@ccclass('AtelierModal')
|
||||
export class AtelierModal extends Component {
|
||||
private storage!: StorageService;
|
||||
private sound!: SoundService;
|
||||
private atelier!: AtelierService;
|
||||
private renderer!: EmbroideryRenderer;
|
||||
private getThumbnail!: (levelIndex: number) => SpriteFrame;
|
||||
private onChanged?: () => void;
|
||||
|
||||
private activeTab: AtelierTab = 'workshop';
|
||||
private tabBtns: Record<AtelierTab, StyledButton> = {} as any;
|
||||
private tabGroups: Record<AtelierTab, Node> = {} as any;
|
||||
private closeBtn!: StyledButton;
|
||||
|
||||
// Tab 1: 蚂蚁工坊
|
||||
private wsThreadsLabel!: Label;
|
||||
private wsPendingLabel!: Label;
|
||||
private wsStageSprite!: Sprite;
|
||||
private wsCollectBtn!: StyledButton;
|
||||
private wsDiaryHeaderLabel!: Label;
|
||||
private wsDiaryMoodLabel!: Label;
|
||||
private wsDiaryMoodBg!: Graphics;
|
||||
private wsDiaryBodyLabel!: Label;
|
||||
private wsToastLabel!: Label;
|
||||
private diaryIndex = 0;
|
||||
private workshopTimeMs = 0;
|
||||
|
||||
// Tab 2: 绣品展柜
|
||||
private galEmptyNode!: Node;
|
||||
private galContentNode!: Node;
|
||||
private galPreviewCardBg!: Graphics;
|
||||
private galPreviewSprite!: Sprite;
|
||||
private galPreviewTitle!: Label;
|
||||
private galPreviewMeta!: Label;
|
||||
private galCounterLabel!: Label;
|
||||
private galThreadsLabel!: Label;
|
||||
private galFrameBtns: { id: PosterFrameId; btn: StyledButton }[] = [];
|
||||
private galQuoteBtn!: StyledButton;
|
||||
private galQuotePreview!: Label;
|
||||
private galExportBtn!: StyledButton;
|
||||
private galToastLabel!: Label;
|
||||
private galleryCursor = 0;
|
||||
|
||||
// Tab 3: 委托信箱
|
||||
private letterChapter = 0;
|
||||
private letterTabs: { btn: StyledButton; lockNode: Node }[] = [];
|
||||
private letterReqHeader!: Label;
|
||||
private letterReqBody!: Label;
|
||||
private letterReplyBg!: Graphics;
|
||||
private letterReplyLockNode!: Node;
|
||||
private letterReplyHeader!: Label;
|
||||
private letterReplyBody!: Label;
|
||||
|
||||
public init(
|
||||
storage: StorageService,
|
||||
sound: SoundService,
|
||||
atelier: AtelierService,
|
||||
renderer: EmbroideryRenderer,
|
||||
getThumbnail: (levelIndex: number) => SpriteFrame,
|
||||
onChanged?: () => void,
|
||||
): void {
|
||||
this.storage = storage;
|
||||
this.sound = sound;
|
||||
this.atelier = atelier;
|
||||
this.renderer = renderer;
|
||||
this.getThumbnail = getThumbnail;
|
||||
this.onChanged = onChanged;
|
||||
this.buildUI();
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
private isEn(): boolean {
|
||||
return this.storage.readLanguage() === 'en';
|
||||
}
|
||||
|
||||
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;
|
||||
return this.getTotalStars() >= (CHAPTER_UNLOCK_STARS[idx] ?? 0);
|
||||
}
|
||||
|
||||
public open(tab: AtelierTab, chapterIndex = 0, focusLevelIndex?: number): void {
|
||||
this.atelier.settleIdle(Date.now());
|
||||
this.atelier.syncFromLegacyRecords(lv => this.storage.getRecord(lv));
|
||||
this.activeTab = tab;
|
||||
this.letterChapter = this.isChapterUnlocked(chapterIndex) ? chapterIndex : 0;
|
||||
const diaries = this.atelier.getUnlockedDiaries();
|
||||
this.diaryIndex = Math.max(0, diaries.length - 1);
|
||||
const gallery = this.atelier.getState().gallery;
|
||||
if (focusLevelIndex !== undefined) {
|
||||
const idx = gallery.findIndex(item => item.levelIndex === focusLevelIndex);
|
||||
if (idx >= 0) this.galleryCursor = idx;
|
||||
}
|
||||
if (this.galleryCursor >= gallery.length) {
|
||||
this.galleryCursor = Math.max(0, gallery.length - 1);
|
||||
}
|
||||
this.wsToastLabel.string = '';
|
||||
this.galToastLabel.string = '';
|
||||
this.node.active = true;
|
||||
this.refreshUI();
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
this.node.active = false;
|
||||
this.onChanged?.();
|
||||
}
|
||||
|
||||
public refreshCurrentTab(): void {
|
||||
if (!this.node.active) return;
|
||||
this.refreshUI();
|
||||
}
|
||||
|
||||
private buildUI(): void {
|
||||
const scrim = createPanel('AtelierScrim', 3200, 3200, { fill: '#18120cc4', radius: 0 }, this.node);
|
||||
|
||||
const frame = createArtSprite('AtelierLinenFrame', 'ui/ui_linen_modal', 688, 790, scrim.node);
|
||||
frame.node.setPosition(0, 6, 0);
|
||||
|
||||
// 顶部三页签切换栏(位于雕花拱顶下方留白区,避免与木雕花叶重叠)
|
||||
const tabsBar = createUINode('AtelierTabs', 536, 40, frame.node);
|
||||
tabsBar.setPosition(0, 146, 0);
|
||||
const tabDefs: { id: AtelierTab; zh: string; x: number }[] = [
|
||||
{ id: 'workshop', zh: '蚂蚁工坊', x: -178 },
|
||||
{ id: 'gallery', zh: '绣品展柜', x: 0 },
|
||||
{ id: 'letters', zh: '委托信箱', x: 178 },
|
||||
];
|
||||
for (const def of tabDefs) {
|
||||
const btn = createButton({
|
||||
name: `Tab_${def.id}`,
|
||||
text: def.zh,
|
||||
w: 168,
|
||||
h: 38,
|
||||
radius: 19,
|
||||
fill: '#ead9b8',
|
||||
stroke: '#c8ab77',
|
||||
depth: 3,
|
||||
depthColor: '#b5945e',
|
||||
textColor: '#4e371e',
|
||||
fontSize: 18,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
this.activeTab = def.id;
|
||||
this.wsToastLabel.string = '';
|
||||
this.galToastLabel.string = '';
|
||||
this.refreshUI();
|
||||
},
|
||||
}, tabsBar);
|
||||
btn.node.setPosition(def.x, 0, 0);
|
||||
this.tabBtns[def.id] = btn;
|
||||
}
|
||||
|
||||
// 三个子页容器(上移留足底部提示与返回按钮的舒适间距)
|
||||
this.tabGroups.workshop = createUINode('WorkshopGroup', 540, 360, frame.node);
|
||||
this.tabGroups.workshop.setPosition(0, -40, 0);
|
||||
this.buildWorkshopTab(this.tabGroups.workshop);
|
||||
|
||||
this.tabGroups.gallery = createUINode('GalleryGroup', 540, 360, frame.node);
|
||||
this.tabGroups.gallery.setPosition(0, -40, 0);
|
||||
this.buildGalleryTab(this.tabGroups.gallery);
|
||||
|
||||
this.tabGroups.letters = createUINode('LettersGroup', 540, 360, frame.node);
|
||||
this.tabGroups.letters.setPosition(0, -40, 0);
|
||||
this.buildLettersTab(this.tabGroups.letters);
|
||||
|
||||
this.closeBtn = createButton({
|
||||
name: 'AtelierCloseBtn',
|
||||
text: '返 回',
|
||||
w: 220,
|
||||
h: 48,
|
||||
radius: 22,
|
||||
fill: '#4d6f49',
|
||||
stroke: '#8ab084',
|
||||
depth: 4,
|
||||
depthColor: '#2e472b',
|
||||
textColor: '#fff9e8',
|
||||
fontSize: 21,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
this.close();
|
||||
},
|
||||
}, frame.node);
|
||||
this.closeBtn.node.setPosition(0, -296, 0);
|
||||
}
|
||||
|
||||
private buildWorkshopTab(parent: Node): void {
|
||||
// 顶部状态条:当前持有线头 + 待领线头
|
||||
const leftStat = createPanel('OwnedThreadsPill', 236, 34, {
|
||||
fill: '#4b311c', stroke: '#d6ae63', strokeWidth: 1.6, radius: 17,
|
||||
}, parent);
|
||||
leftStat.node.setPosition(-128, 146, 0);
|
||||
this.wsThreadsLabel = createLabel('Text', '柔丝线头:15 束', 220, 28, {
|
||||
size: 16, color: '#fff4d6', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, leftStat.node);
|
||||
|
||||
const rightStat = createPanel('PendingThreadsPill', 246, 34, {
|
||||
fill: '#3c5938', stroke: '#9cc286', strokeWidth: 1.6, radius: 17,
|
||||
}, parent);
|
||||
rightStat.node.setPosition(124, 146, 0);
|
||||
this.wsPendingLabel = createLabel('Text', '待领:+4 束(最多8h)', 232, 28, {
|
||||
size: 15, color: '#e9f9d8', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, rightStat.node);
|
||||
|
||||
// 实时动态小蚂蚁工作舞台
|
||||
const stageNode = createUINode('AntWorkshopStage', 492, 152, parent);
|
||||
stageNode.setPosition(0, 48, 0);
|
||||
this.wsStageSprite = stageNode.addComponent(Sprite);
|
||||
this.wsStageSprite.sizeMode = Sprite.SizeMode.CUSTOM;
|
||||
this.wsStageSprite.spriteFrame = this.renderer.getWorkshopSpriteFrame();
|
||||
|
||||
// 收下线头按钮
|
||||
this.wsCollectBtn = createButton({
|
||||
name: 'CollectThreadsBtn',
|
||||
text: '收下线头 (+4 束)',
|
||||
w: 292,
|
||||
h: 44,
|
||||
radius: 22,
|
||||
fill: '#df9c34',
|
||||
stroke: '#fae09e',
|
||||
depth: 4,
|
||||
depthColor: '#996012',
|
||||
textColor: '#3f2207',
|
||||
fontSize: 19,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
const res = this.atelier.collectPending(Date.now());
|
||||
if (res.threads > 0) {
|
||||
this.sound.bonus();
|
||||
const diaries = this.atelier.getUnlockedDiaries();
|
||||
if (res.newDiary) {
|
||||
this.diaryIndex = Math.max(0, diaries.length - 1);
|
||||
const title = this.isEn() ? res.newDiary.titleEn : res.newDiary.titleZh;
|
||||
this.wsToastLabel.string = this.isEn()
|
||||
? `Collected +${res.threads} threads & new diary: ${title}!`
|
||||
: `收下 +${res.threads} 束线头!小蚂蚁带回新日记《${title}》`;
|
||||
} else {
|
||||
this.wsToastLabel.string = this.isEn()
|
||||
? `Collected +${res.threads} threads! Use them in the Gallery.`
|
||||
: `已收下 +${res.threads} 束线头,可去「绣品展柜」换装裱与落款!`;
|
||||
}
|
||||
this.refreshUI();
|
||||
this.onChanged?.();
|
||||
} else {
|
||||
const mins = this.atelier.getNextThreadMinutes(Date.now());
|
||||
this.wsToastLabel.string = this.isEn()
|
||||
? `Ants are spinning... next thread in ~${mins} min.`
|
||||
: `小蚂蚁正在勤快理线,约 ${mins} 分钟后产出新线头~`;
|
||||
}
|
||||
},
|
||||
}, parent);
|
||||
this.wsCollectBtn.node.setPosition(0, -56, 0);
|
||||
|
||||
// 底部:蚂蚁日记明信片
|
||||
const diaryCard = createPanel('AntDiaryCard', 504, 102, {
|
||||
fill: '#f7edd7', stroke: '#d2b682', strokeWidth: 1.8, radius: 16, stitchColor: '#d7be9099', stitchInset: 6,
|
||||
}, parent);
|
||||
diaryCard.node.setPosition(0, -138, 0);
|
||||
|
||||
this.wsDiaryHeaderLabel = createLabel('DiaryHeader', '蚂蚁日记 1/12 · 第一缕晨光', 310, 26, {
|
||||
size: 16, color: '#472f18', bold: true, align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, diaryCard.node);
|
||||
this.wsDiaryHeaderLabel.node.setPosition(-74, 28, 0);
|
||||
|
||||
const moodPill = createPanel('DiaryMood', 78, 24, {
|
||||
fill: '#c87e2d', radius: 12,
|
||||
}, diaryCard.node);
|
||||
moodPill.node.setPosition(116, 28, 0);
|
||||
this.wsDiaryMoodBg = moodPill.graphics;
|
||||
this.wsDiaryMoodLabel = createLabel('Text', '搬线中', 70, 22, {
|
||||
size: 13, color: '#fff9ec', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, moodPill.node);
|
||||
|
||||
const prevDiary = createButton({
|
||||
name: 'PrevDiaryBtn',
|
||||
text: '‹',
|
||||
w: 30,
|
||||
h: 28,
|
||||
radius: 14,
|
||||
fill: '#e7d5b0',
|
||||
stroke: '#c6a76e',
|
||||
textColor: '#4c341a',
|
||||
fontSize: 20,
|
||||
onClick: () => {
|
||||
const list = this.atelier.getUnlockedDiaries();
|
||||
if (list.length <= 1) return;
|
||||
this.diaryIndex = (this.diaryIndex - 1 + list.length) % list.length;
|
||||
this.refreshWorkshop();
|
||||
},
|
||||
}, diaryCard.node);
|
||||
prevDiary.node.setPosition(186, 28, 0);
|
||||
|
||||
const nextDiary = createButton({
|
||||
name: 'NextDiaryBtn',
|
||||
text: '›',
|
||||
w: 30,
|
||||
h: 28,
|
||||
radius: 14,
|
||||
fill: '#e7d5b0',
|
||||
stroke: '#c6a76e',
|
||||
textColor: '#4c341a',
|
||||
fontSize: 20,
|
||||
onClick: () => {
|
||||
const list = this.atelier.getUnlockedDiaries();
|
||||
if (list.length <= 1) return;
|
||||
this.diaryIndex = (this.diaryIndex + 1) % list.length;
|
||||
this.refreshWorkshop();
|
||||
},
|
||||
}, diaryCard.node);
|
||||
nextDiary.node.setPosition(222, 28, 0);
|
||||
|
||||
this.wsDiaryBodyLabel = createLabel('DiaryBody', '', 462, 54, {
|
||||
size: 15, color: '#5d472b', align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, diaryCard.node);
|
||||
this.wsDiaryBodyLabel.node.setPosition(0, -14, 0);
|
||||
|
||||
this.wsToastLabel = createLabel('WorkshopToast', '', 504, 24, {
|
||||
size: 14, color: '#7a4f1b', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, parent);
|
||||
this.wsToastLabel.node.setPosition(0, -200, 0);
|
||||
}
|
||||
|
||||
private buildGalleryTab(parent: Node): void {
|
||||
// 空展柜状态
|
||||
this.galEmptyNode = createPanel('GalleryEmpty', 488, 220, {
|
||||
fill: '#f4e8ce', stroke: '#d4b988', strokeWidth: 1.8, radius: 20,
|
||||
}, parent).node;
|
||||
this.galEmptyNode.setPosition(0, 10, 0);
|
||||
createLabel('EmptyText', '绣成任意一幅作品后\n你的手绣藏品会自动陈列于此,并可换装裱导出海报。', 440, 90, {
|
||||
size: 19, color: '#614a2c', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, this.galEmptyNode);
|
||||
|
||||
// 展柜主视图
|
||||
this.galContentNode = createUINode('GalleryContent', 520, 356, parent);
|
||||
|
||||
// 左侧:装裱预览画框
|
||||
const previewCard = createPanel('PosterPreviewCard', 222, 256, {
|
||||
fill: '#627052', stroke: '#efe0bd', strokeWidth: 2.2, radius: 18, shadow: 4,
|
||||
}, this.galContentNode);
|
||||
previewCard.node.setPosition(-136, 30, 0);
|
||||
this.galPreviewCardBg = previewCard.graphics;
|
||||
|
||||
const thumbNode = createUINode('GalleryThumb', 176, 176, previewCard.node);
|
||||
thumbNode.setPosition(0, 22, 0);
|
||||
this.galPreviewSprite = thumbNode.addComponent(Sprite);
|
||||
this.galPreviewSprite.sizeMode = Sprite.SizeMode.CUSTOM;
|
||||
|
||||
this.galPreviewTitle = createLabel('ThumbTitle', '《金色向日葵》', 198, 26, {
|
||||
size: 16, color: '#fff7e0', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, previewCard.node);
|
||||
this.galPreviewTitle.node.setPosition(0, -82, 0);
|
||||
|
||||
this.galPreviewMeta = createLabel('ThumbMeta', '★★★ · 3.4 cm', 198, 22, {
|
||||
size: 14, color: '#f4dc9e', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, previewCard.node);
|
||||
this.galPreviewMeta.node.setPosition(0, -106, 0);
|
||||
|
||||
// 左侧底部翻页
|
||||
const prevGal = createButton({
|
||||
name: 'PrevGalleryBtn',
|
||||
text: '‹',
|
||||
w: 44,
|
||||
h: 34,
|
||||
radius: 17,
|
||||
fill: '#e6d3ad',
|
||||
stroke: '#c6a66c',
|
||||
depth: 2,
|
||||
depthColor: '#ad8d55',
|
||||
textColor: '#483018',
|
||||
fontSize: 24,
|
||||
onClick: () => {
|
||||
const list = this.atelier.getState().gallery;
|
||||
if (list.length <= 1) return;
|
||||
this.galleryCursor = (this.galleryCursor - 1 + list.length) % list.length;
|
||||
this.refreshGallery();
|
||||
},
|
||||
}, this.galContentNode);
|
||||
prevGal.node.setPosition(-208, -124, 0);
|
||||
|
||||
this.galCounterLabel = createLabel('GalCounter', '1 / 1', 90, 28, {
|
||||
size: 16, color: '#4d361d', bold: true,
|
||||
}, this.galContentNode);
|
||||
this.galCounterLabel.node.setPosition(-136, -124, 0);
|
||||
|
||||
const nextGal = createButton({
|
||||
name: 'NextGalleryBtn',
|
||||
text: '›',
|
||||
w: 44,
|
||||
h: 34,
|
||||
radius: 17,
|
||||
fill: '#e6d3ad',
|
||||
stroke: '#c6a66c',
|
||||
depth: 2,
|
||||
depthColor: '#ad8d55',
|
||||
textColor: '#483018',
|
||||
fontSize: 24,
|
||||
onClick: () => {
|
||||
const list = this.atelier.getState().gallery;
|
||||
if (list.length <= 1) return;
|
||||
this.galleryCursor = (this.galleryCursor + 1) % list.length;
|
||||
this.refreshGallery();
|
||||
},
|
||||
}, this.galContentNode);
|
||||
nextGal.node.setPosition(-64, -124, 0);
|
||||
|
||||
// 右侧:定制装裱 + 落款 + 导出按钮
|
||||
const threadPill = createPanel('GalThreadPill', 250, 32, {
|
||||
fill: '#4b311c', stroke: '#d6ae63', strokeWidth: 1.5, radius: 16,
|
||||
}, this.galContentNode);
|
||||
threadPill.node.setPosition(122, 138, 0);
|
||||
this.galThreadsLabel = createLabel('Text', '柔丝线头:15 束', 236, 26, {
|
||||
size: 15, color: '#fff3d4', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, threadPill.node);
|
||||
|
||||
createLabel('FrameHeading', '装裱风格', 248, 22, {
|
||||
size: 15, color: '#584126', bold: true, align: Label.HorizontalAlign.LEFT,
|
||||
}, this.galContentNode).node.setPosition(122, 104, 0);
|
||||
|
||||
this.galFrameBtns = POSTER_FRAMES.map((f, idx) => {
|
||||
const col = idx % 2;
|
||||
const row = Math.floor(idx / 2);
|
||||
const btn = createButton({
|
||||
name: `Frame_${f.id}`,
|
||||
text: f.nameZh,
|
||||
w: 120,
|
||||
h: 38,
|
||||
radius: 14,
|
||||
fill: '#ead8b6',
|
||||
stroke: '#c8ab77',
|
||||
depth: 3,
|
||||
depthColor: '#ad8e59',
|
||||
textColor: '#4a321a',
|
||||
fontSize: 15,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
const res = this.atelier.selectOrUnlockFrame(f.id);
|
||||
if (res.ok) {
|
||||
this.sound.bonus();
|
||||
this.galToastLabel.string = res.unlockedNow
|
||||
? `已用 ${f.cost} 束线头解锁「${f.nameZh}」装裱!`
|
||||
: `已切换为「${f.nameZh}」装裱风格`;
|
||||
this.refreshGallery();
|
||||
} else {
|
||||
this.sound.block();
|
||||
this.galToastLabel.string = `还差 ${res.need} 束线头(去「蚂蚁工坊」收线头或通关获取)`;
|
||||
}
|
||||
},
|
||||
}, this.galContentNode);
|
||||
btn.node.setPosition(58 + col * 128, 66 - row * 46, 0);
|
||||
return { id: f.id, btn };
|
||||
});
|
||||
|
||||
createLabel('QuoteHeading', '藏品落款(点击切换 / 解锁)', 248, 22, {
|
||||
size: 14, color: '#584126', bold: true, align: Label.HorizontalAlign.LEFT,
|
||||
}, this.galContentNode).node.setPosition(122, -16, 0);
|
||||
|
||||
this.galQuoteBtn = createButton({
|
||||
name: 'QuoteCycleBtn',
|
||||
text: '一针一线 · 慢享手作好时光',
|
||||
w: 250,
|
||||
h: 44,
|
||||
radius: 14,
|
||||
fill: '#f5ead2',
|
||||
stroke: '#cca96e',
|
||||
depth: 3,
|
||||
depthColor: '#b3915a',
|
||||
textColor: '#4c3318',
|
||||
fontSize: 14,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
const state = this.atelier.getState();
|
||||
const curIdx = POSTER_QUOTES.findIndex(q => q.id === state.activeQuote);
|
||||
const nextQuote = POSTER_QUOTES[(curIdx + 1) % POSTER_QUOTES.length];
|
||||
const res = this.atelier.selectOrUnlockQuote(nextQuote.id);
|
||||
if (res.ok) {
|
||||
this.sound.bonus();
|
||||
this.galToastLabel.string = res.unlockedNow
|
||||
? `已用 ${nextQuote.cost} 束线头解锁新落款!`
|
||||
: `已切换落款:「${nextQuote.zh}」`;
|
||||
this.refreshGallery();
|
||||
} else {
|
||||
// 线头不够解锁下一条时,轮换已解锁落款并提示
|
||||
const unlocked = state.unlockedQuotes;
|
||||
const nextUnlocked = unlocked[(unlocked.indexOf(state.activeQuote) + 1) % unlocked.length];
|
||||
this.atelier.selectOrUnlockQuote(nextUnlocked);
|
||||
this.galToastLabel.string = `下条落款需 ${nextQuote.cost} 束线头(还差 ${res.need} 束)`;
|
||||
this.refreshGallery();
|
||||
}
|
||||
},
|
||||
}, this.galContentNode);
|
||||
this.galQuoteBtn.node.setPosition(122, -56, 0);
|
||||
this.galQuotePreview = this.galQuoteBtn.label;
|
||||
|
||||
this.galExportBtn = createButton({
|
||||
name: 'ExportGalleryBtn',
|
||||
text: '导出藏品海报',
|
||||
w: 250,
|
||||
h: 46,
|
||||
radius: 22,
|
||||
fill: '#4d7247',
|
||||
stroke: '#8ab082',
|
||||
depth: 4,
|
||||
depthColor: '#2d4729',
|
||||
textColor: '#fff9e8',
|
||||
fontSize: 19,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
const list = this.atelier.getState().gallery;
|
||||
const item = list[this.galleryCursor];
|
||||
if (!item) return;
|
||||
const lv = LEVELS[item.levelIndex];
|
||||
const chName = CHAPTERS[lv.chapter]?.name ?? '蚂蚁织画';
|
||||
const qDef = this.atelier.getQuoteDef();
|
||||
this.renderer.exportGalleryArtwork(
|
||||
lv,
|
||||
{
|
||||
stars: item.stars,
|
||||
lengthText: formatLength(item.length),
|
||||
chapterName: chName,
|
||||
levelNumber: item.levelIndex + 1,
|
||||
frame: this.atelier.getFrameDef(),
|
||||
quoteText: this.isEn() ? qDef.en : qDef.zh,
|
||||
},
|
||||
msg => {
|
||||
this.galToastLabel.string = msg;
|
||||
},
|
||||
);
|
||||
},
|
||||
}, this.galContentNode);
|
||||
this.galExportBtn.node.setPosition(122, -118, 0);
|
||||
|
||||
this.galToastLabel = createLabel('GalleryToast', '', 504, 24, {
|
||||
size: 14, color: '#7a4f1b', bold: true, overflow: Label.Overflow.SHRINK,
|
||||
}, parent);
|
||||
this.galToastLabel.node.setPosition(0, -196, 0);
|
||||
}
|
||||
|
||||
private buildLettersTab(parent: Node): void {
|
||||
// 顶部 6 章信件切换条
|
||||
const strip = createUINode('LetterChapterStrip', 516, 34, parent);
|
||||
strip.setPosition(0, 142, 0);
|
||||
this.letterTabs = CHAPTERS.map((_, idx) => {
|
||||
const btn = createButton({
|
||||
name: `LetterCh_${idx + 1}`,
|
||||
text: CHAPTER_SHORT_ZH[idx],
|
||||
w: 80,
|
||||
h: 32,
|
||||
radius: 16,
|
||||
fill: '#ead8b6',
|
||||
stroke: '#c8ab77',
|
||||
depth: 2,
|
||||
depthColor: '#b0915c',
|
||||
textColor: '#4c3318',
|
||||
fontSize: 14,
|
||||
onClick: () => {
|
||||
this.sound.unlock();
|
||||
if (!this.isChapterUnlocked(idx)) {
|
||||
this.sound.block();
|
||||
return;
|
||||
}
|
||||
this.letterChapter = idx;
|
||||
this.refreshLetters();
|
||||
},
|
||||
}, strip);
|
||||
btn.node.setPosition((idx - 2.5) * 86, 0, 0);
|
||||
const lockNode = createUINode('Lock', 16, 16, btn.node);
|
||||
lockNode.setPosition(-21, 0, 0);
|
||||
drawPadlockIcon(lockNode.addComponent(Graphics), 0.78, '#b89b6a', '#d7bd8e', '#46311f');
|
||||
lockNode.active = false;
|
||||
return { btn, lockNode };
|
||||
});
|
||||
|
||||
// 上半卡:客人委托来信(舒朗间距)
|
||||
const reqCard = createPanel('RequestLetterCard', 506, 138, {
|
||||
fill: '#f9f0dc', stroke: '#d2b47d', strokeWidth: 1.8, radius: 18, stitchColor: '#d9bf8e99', stitchInset: 7,
|
||||
}, parent);
|
||||
reqCard.node.setPosition(0, 42, 0);
|
||||
|
||||
const waxDot = createPanel('ReqWax', 18, 18, { fill: '#c85450', stroke: '#f4d39c', strokeWidth: 1.5, radius: 9 }, reqCard.node);
|
||||
waxDot.node.setPosition(-224, 42, 0);
|
||||
|
||||
this.letterReqHeader = createLabel('ReqHeader', '', 436, 28, {
|
||||
size: 17, color: '#452c15', bold: true, align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, reqCard.node);
|
||||
this.letterReqHeader.node.setPosition(10, 42, 0);
|
||||
|
||||
this.letterReqBody = createLabel('ReqBody', '', 462, 80, {
|
||||
size: 16, color: '#5c462b', align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, reqCard.node);
|
||||
this.letterReqBody.node.setPosition(0, -14, 0);
|
||||
|
||||
// 下半卡:成画回信(与委托卡保持舒适留白)
|
||||
const replyCard = createPanel('ReplyLetterCard', 506, 138, {
|
||||
fill: '#eaf1e1', stroke: '#9ab785', strokeWidth: 1.8, radius: 18, stitchColor: '#9ab78588', stitchInset: 7,
|
||||
}, parent);
|
||||
replyCard.node.setPosition(0, -118, 0);
|
||||
this.letterReplyBg = replyCard.graphics;
|
||||
|
||||
this.letterReplyLockNode = createUINode('ReplyLock', 28, 28, replyCard.node);
|
||||
this.letterReplyLockNode.setPosition(0, 32, 0);
|
||||
drawPadlockIcon(this.letterReplyLockNode.addComponent(Graphics), 1.35, '#bfa06a', '#e3ca97', '#4a321b');
|
||||
|
||||
this.letterReplyHeader = createLabel('ReplyHeader', '', 450, 28, {
|
||||
size: 17, color: '#33542d', bold: true, align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, replyCard.node);
|
||||
this.letterReplyHeader.node.setPosition(0, 42, 0);
|
||||
|
||||
this.letterReplyBody = createLabel('ReplyBody', '', 462, 80, {
|
||||
size: 16, color: '#43583c', align: Label.HorizontalAlign.LEFT, overflow: Label.Overflow.SHRINK,
|
||||
}, replyCard.node);
|
||||
this.letterReplyBody.node.setPosition(0, -14, 0);
|
||||
}
|
||||
|
||||
private refreshUI(): void {
|
||||
const en = this.isEn();
|
||||
this.tabBtns.workshop.label.string = en ? 'Ant Craft' : '蚂蚁工坊';
|
||||
this.tabBtns.gallery.label.string = en ? 'Gallery' : '绣品展柜';
|
||||
this.tabBtns.letters.label.string = en ? 'Letters' : '委托信箱';
|
||||
this.closeBtn.label.string = en ? 'Back' : '返 回';
|
||||
|
||||
(['workshop', 'gallery', 'letters'] as AtelierTab[]).forEach(tab => {
|
||||
const active = tab === this.activeTab;
|
||||
this.tabGroups[tab].active = active;
|
||||
this.tabBtns[tab].setStyle(
|
||||
active ? '#c85b56' : '#ead9b8',
|
||||
active ? '#f7d58b' : '#c8ab77',
|
||||
active ? '#fff9eb' : '#4e371e',
|
||||
active ? '#823430' : '#b5945e',
|
||||
);
|
||||
});
|
||||
|
||||
if (this.activeTab === 'workshop') this.refreshWorkshop();
|
||||
else if (this.activeTab === 'gallery') this.refreshGallery();
|
||||
else this.refreshLetters();
|
||||
}
|
||||
|
||||
private refreshWorkshop(): void {
|
||||
const en = this.isEn();
|
||||
const st = this.atelier.getState();
|
||||
this.wsThreadsLabel.string = en ? `Threads: ${st.yarnThreads}` : `柔丝线头:${st.yarnThreads} 束`;
|
||||
this.wsPendingLabel.string = en
|
||||
? `Ready: +${st.pendingThreads}/${IDLE_MAX_THREADS}`
|
||||
: `待领:+${st.pendingThreads} 束(8h封顶)`;
|
||||
|
||||
if (st.pendingThreads > 0) {
|
||||
this.wsCollectBtn.label.string = en
|
||||
? `Collect Threads (+${st.pendingThreads})`
|
||||
: `收下线头 (+${st.pendingThreads} 束)`;
|
||||
this.wsCollectBtn.setStyle('#df9c34', '#fae09e', '#3f2207', '#996012');
|
||||
} else {
|
||||
const mins = this.atelier.getNextThreadMinutes(Date.now());
|
||||
this.wsCollectBtn.label.string = en
|
||||
? `Spinning... +1 in ${mins}m`
|
||||
: `工坊织线中 · ${mins} 分钟后 +1`;
|
||||
this.wsCollectBtn.setStyle('#d9c8a5', '#bca479', '#6c573c', '#a89066');
|
||||
}
|
||||
|
||||
const diaries = this.atelier.getUnlockedDiaries();
|
||||
const idx = Math.min(this.diaryIndex, Math.max(0, diaries.length - 1));
|
||||
const diary = diaries[idx] ?? ANT_DIARIES[0];
|
||||
this.wsDiaryHeaderLabel.string = en
|
||||
? `Diary ${idx + 1}/${ANT_DIARIES.length} · ${diary.titleEn}`
|
||||
: `蚂蚁日记 ${idx + 1}/${ANT_DIARIES.length} · ${diary.titleZh}`;
|
||||
this.wsDiaryMoodLabel.string = en ? diary.moodEn : diary.moodZh;
|
||||
drawRoundedBox(this.wsDiaryMoodBg, 78, 24, { fill: diary.accentColor, radius: 12 });
|
||||
this.wsDiaryBodyLabel.string = en ? diary.bodyEn : diary.bodyZh;
|
||||
|
||||
this.renderer.renderWorkshopFrame(this.workshopTimeMs, st.pendingThreads);
|
||||
}
|
||||
|
||||
private refreshGallery(): void {
|
||||
const en = this.isEn();
|
||||
const st = this.atelier.getState();
|
||||
const hasItems = st.gallery.length > 0;
|
||||
this.galEmptyNode.active = !hasItems;
|
||||
this.galContentNode.active = hasItems;
|
||||
if (!hasItems) return;
|
||||
|
||||
if (this.galleryCursor >= st.gallery.length) this.galleryCursor = st.gallery.length - 1;
|
||||
const item = st.gallery[this.galleryCursor];
|
||||
const lv = LEVELS[item.levelIndex];
|
||||
const frameDef = this.atelier.getFrameDef();
|
||||
const quoteDef = this.atelier.getQuoteDef();
|
||||
|
||||
drawRoundedBox(this.galPreviewCardBg, 222, 256, {
|
||||
fill: frameDef.bgTop,
|
||||
stroke: frameDef.accent,
|
||||
strokeWidth: 2.4,
|
||||
radius: 18,
|
||||
shadow: 4,
|
||||
});
|
||||
this.galPreviewSprite.spriteFrame = this.getThumbnail(item.levelIndex);
|
||||
this.galPreviewTitle.string = en ? lv.name : `《${lv.name}》`;
|
||||
this.galPreviewTitle.color = hex(frameDef.accent);
|
||||
this.galPreviewMeta.string = `${'★'.repeat(item.stars)}${'☆'.repeat(3 - item.stars)} · ${formatLength(item.length)}`;
|
||||
this.galCounterLabel.string = `${this.galleryCursor + 1} / ${st.gallery.length}`;
|
||||
this.galThreadsLabel.string = en ? `Threads: ${st.yarnThreads}` : `柔丝线头:${st.yarnThreads} 束`;
|
||||
|
||||
for (const entry of this.galFrameBtns) {
|
||||
const def = POSTER_FRAMES.find(f => f.id === entry.id)!;
|
||||
const unlocked = st.unlockedFrames.includes(entry.id);
|
||||
const active = st.activeFrame === entry.id;
|
||||
const baseName = en ? def.nameEn : def.nameZh;
|
||||
entry.btn.label.string = unlocked ? baseName : `${baseName}(${def.cost})`;
|
||||
entry.btn.setStyle(
|
||||
active ? '#c85b56' : unlocked ? '#ead8b6' : '#ddd0b7',
|
||||
active ? '#f7d58b' : unlocked ? '#c8ab77' : '#b2a184',
|
||||
active ? '#fff9eb' : unlocked ? '#4a321a' : '#7b684e',
|
||||
active ? '#823430' : '#ad8e59',
|
||||
);
|
||||
}
|
||||
|
||||
this.galQuotePreview.string = en ? quoteDef.en : quoteDef.zh;
|
||||
this.galExportBtn.label.string = en ? 'Export Poster' : '导出藏品海报';
|
||||
}
|
||||
|
||||
private refreshLetters(): void {
|
||||
const en = this.isEn();
|
||||
const shortList = en ? CHAPTER_SHORT_EN : CHAPTER_SHORT_ZH;
|
||||
this.letterTabs.forEach((tab, idx) => {
|
||||
const unlocked = this.isChapterUnlocked(idx);
|
||||
const active = idx === this.letterChapter;
|
||||
tab.btn.label.string = shortList[idx];
|
||||
tab.lockNode.active = !unlocked;
|
||||
tab.btn.label.node.setPosition(unlocked ? 0 : 8, 1, 0);
|
||||
tab.btn.setStyle(
|
||||
active ? '#c85b56' : unlocked ? '#ead8b6' : '#d6cab4',
|
||||
active ? '#f7d58b' : unlocked ? '#c8ab77' : '#aea08a',
|
||||
active ? '#fff9eb' : unlocked ? '#4c3318' : '#857763',
|
||||
active ? '#823430' : '#ad8e59',
|
||||
);
|
||||
});
|
||||
|
||||
const letter = this.atelier.getLetter(this.letterChapter);
|
||||
this.letterReqHeader.string = en
|
||||
? `${letter.senderEn} · ${letter.titleEn}`
|
||||
: `委托人:${letter.senderZh} · 《${letter.titleZh}》`;
|
||||
this.letterReqBody.string = en ? letter.requestEn : letter.requestZh;
|
||||
|
||||
const replyUnlocked = this.atelier.isChapterReplyUnlocked(this.letterChapter, lv => this.storage.getRecord(lv));
|
||||
const ch = CHAPTERS[this.letterChapter];
|
||||
const chStars = LEVELS.slice(ch.startIndex, ch.startIndex + ch.count).reduce(
|
||||
(sum, lv) => sum + (this.storage.getRecord(lv)?.stars ?? 0),
|
||||
0,
|
||||
);
|
||||
|
||||
this.letterReplyLockNode.active = !replyUnlocked;
|
||||
if (replyUnlocked) {
|
||||
drawRoundedBox(this.letterReplyBg, 506, 138, {
|
||||
fill: '#eaf1e1', stroke: '#8fb27a', strokeWidth: 1.8, radius: 18, stitchColor: '#8fb27a88', stitchInset: 7,
|
||||
});
|
||||
this.letterReplyHeader.node.active = true;
|
||||
this.letterReplyHeader.string = en ? `✦ ${letter.replyTitleEn}` : `✦ ${letter.replyTitleZh}`;
|
||||
this.letterReplyBody.color = hex('#3a5433');
|
||||
this.letterReplyBody.horizontalAlign = Label.HorizontalAlign.LEFT;
|
||||
this.letterReplyBody.node.setPosition(0, -14, 0);
|
||||
this.letterReplyBody.string = en ? letter.replyEn : letter.replyZh;
|
||||
} else {
|
||||
drawRoundedBox(this.letterReplyBg, 506, 138, {
|
||||
fill: '#efe5d0', stroke: '#cbb48a', strokeWidth: 1.6, radius: 18, stitchColor: '#cbb48a80', stitchInset: 7,
|
||||
});
|
||||
this.letterReplyHeader.node.active = false;
|
||||
this.letterReplyBody.color = hex('#755f42');
|
||||
this.letterReplyBody.horizontalAlign = Label.HorizontalAlign.CENTER;
|
||||
this.letterReplyBody.node.setPosition(0, -16, 0);
|
||||
this.letterReplyBody.string = this.letterChapter === 0
|
||||
? (en
|
||||
? 'Finish Stage 1 (Golden Sunflower) to read Grandma Lin’s reply!'
|
||||
: '绣完第 1 关《金色向日葵》,即可立刻拆阅林阿婆的暖心回信!')
|
||||
: (en
|
||||
? `Clear Chapter Boss or earn 15 ★ in this chapter to open the reply (${chStars} / 15 ★).`
|
||||
: `通关本章终考关,或本章集满 15 ★ 即可拆阅客人回信\n(当前本章已获 ${chStars} / 15 ★)`);
|
||||
}
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
if (!this.node.active || this.activeTab !== 'workshop') return;
|
||||
this.workshopTimeMs += Math.min(50, Math.max(0, dt * 1000));
|
||||
this.renderer.renderWorkshopFrame(this.workshopTimeMs, this.atelier.getState().pendingThreads);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user