chore: freeze v1.1.3 filing submission build (60 levels, full-screen safe layout)

This commit is contained in:
fannyxl committed 2026-11-25 23:14:45 +08:00
commit 96c19dca82
174 files changed
+37935

No files matched your search

+815
View File
@@ -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);
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "9dc539ef-2450-466e-a081-e730151809b3",
"files": [],
"subMetas": {},
"userData": {}
}
File diff suppressed because it is too large. Load diff
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "80a6df9c-75ae-44b3-b21e-b0f999a50a37",
"files": [],
"subMetas": {},
"userData": {}
}
File diff suppressed because it is too large. Load diff
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a0eaa4b4-714c-4e00-9412-68230ed12d7e",
"files": [],
"subMetas": {},
"userData": {}
}
+179
View File
@@ -0,0 +1,179 @@
import { Node, ResolutionPolicy, screen, UITransform, Vec3, view } from 'cc';
declare const wx: any;
export const DESIGN_W = 750;
export const DESIGN_H = 1334;
export interface ScreenMetrics {
visibleW: number;
visibleH: number;
/** 顶部安全区高度(含刘海/灵动岛,设计坐标) */
topInset: number;
/** 微信右上角胶囊下沿距屏幕顶部的安全距离(设计坐标) */
capsuleBottom: number;
/** 底部安全区高度(含 iPhone Home 手势条,设计坐标) */
bottomInset: number;
/** 安全区实际可用高度(safeRoot 局部坐标系中 >= 1334,全面屏自动舒展消除上下大空白) */
safeHeight: number;
/** 安全区半高:safeRoot 内顶安全边 = +safeHalfH,底安全边 = -safeHalfH */
safeHalfH: number;
/** 超出 1334 基准的额外垂直空间(用于均匀拉宽中间板块间距) */
extraH: number;
/** 主内容区整体缩放系数(仅超短屏 + 胶囊时自动收拢防裁切) */
contentScale: number;
/** safeRoot 中心在屏幕中的 Y 偏移 */
contentOffsetY: number;
/** 背景图全屏铺满(cover)所需缩放系数 */
bgCoverScale: number;
isWeChat: boolean;
/** 浏览器预览调试参数 ?wxsim=iphone15 / ?wxsim=iphonese 时的模拟胶囊信息 */
mockCapsule?: { top: number; height: number; width: number; right: number };
}
function getWeChatSimMode(): 'iphone15' | 'iphonese' | null {
try {
if (typeof window === 'undefined' || !window.location?.search) return null;
const params = new URLSearchParams(window.location.search);
const val = (params.get('wxsim') || '').toLowerCase();
if (val === 'iphone15' || val === '15') return 'iphone15';
if (val === 'iphonese' || val === 'se') return 'iphonese';
} catch {
// Ignore non-browser environments.
}
return null;
}
/**
* 自适应分辨率策略:
* - 竖屏手机(比例 <= 9:16,如 16:9 / 19.5:9 / 20:9)使用 FIXED_WIDTH,消除全面屏上下黑边;
* - 平板 / 折叠屏展开 / 桌面横屏预览(比例 > 9:16)使用 FIXED_HEIGHT,确保上下完整不裁切。
*/
export function applyResponsivePolicy(): void {
const frame = screen.windowSize;
if (!frame || frame.width <= 0 || frame.height <= 0) return;
const aspect = frame.width / frame.height;
const designAspect = DESIGN_W / DESIGN_H;
const policy = aspect <= designAspect + 0.005 ? ResolutionPolicy.FIXED_WIDTH : ResolutionPolicy.FIXED_HEIGHT;
view.setDesignResolutionSize(DESIGN_W, DESIGN_H, policy);
}
/**
* 统一读取微信小游戏胶囊按钮(getMenuButtonBoundingClientRect)与安全区(getWindowInfo / getSystemInfoSync),
* 并换算为 Cocos 设计分辨率坐标系。
*/
export function computeScreenMetrics(): ScreenMetrics {
const vis = view.getVisibleSize();
const visibleW = Math.max(DESIGN_W, vis.width || DESIGN_W);
const visibleH = Math.max(DESIGN_H, vis.height || DESIGN_H);
let topInset = 0;
let capsuleBottom = 0;
let bottomInset = 0;
let isWeChat = false;
let mockCapsule: ScreenMetrics['mockCapsule'];
if (typeof wx !== 'undefined') {
isWeChat = true;
try {
const winInfo =
typeof wx.getWindowInfo === 'function'
? wx.getWindowInfo()
: typeof wx.getSystemInfoSync === 'function'
? wx.getSystemInfoSync()
: null;
const winH = Number(winInfo?.windowHeight) || Number(winInfo?.screenHeight) || 0;
const scaleY = winH > 0 ? visibleH / winH : visibleW / (Number(winInfo?.windowWidth) || 375);
const safe = winInfo?.safeArea;
if (safe && winH > 0) {
topInset = Math.max(0, Number(safe.top) || 0) * scaleY;
const rawBottom = winH - (Number(safe.bottom) || winH);
bottomInset = Math.max(0, rawBottom) * scaleY;
} else if (winInfo?.statusBarHeight) {
topInset = Math.max(0, Number(winInfo.statusBarHeight) || 0) * scaleY;
}
if (typeof wx.getMenuButtonBoundingClientRect === 'function') {
const menu = wx.getMenuButtonBoundingClientRect();
if (menu && Number(menu.bottom) > 0) {
// 紧贴胶囊下沿留 10px 轻呼吸距,避免顶部出现大块空白
capsuleBottom = Number(menu.bottom) * scaleY + 10;
}
}
if (capsuleBottom <= 0) {
capsuleBottom = Math.max(topInset + 76, 108);
}
} catch {
capsuleBottom = 112;
bottomInset = 32;
}
} else {
const sim = getWeChatSimMode();
if (sim === 'iphone15') {
isWeChat = true;
topInset = 98;
capsuleBottom = 172;
bottomInset = 52;
mockCapsule = { top: 98, height: 62, width: 168, right: 20 };
} else if (sim === 'iphonese') {
isWeChat = true;
topInset = 38;
capsuleBottom = 112;
bottomInset = 0;
mockCapsule = { top: 38, height: 64, width: 174, right: 18 };
}
}
const effectiveTop = Math.max(topInset, capsuleBottom);
// 底部手势条只保留必要安全高度(上限 54px),避免底部产生大块空木板
const effectiveBottom = Math.min(54, Math.max(0, bottomInset));
const availableH = Math.max(640, visibleH - effectiveTop - effectiveBottom);
const contentScale = availableH < DESIGN_H ? Math.max(0.78, availableH / DESIGN_H) : 1;
const safeHeight = availableH >= DESIGN_H ? Math.min(1560, availableH) : DESIGN_H;
const safeHalfH = safeHeight / 2;
const extraH = Math.max(0, safeHeight - DESIGN_H);
const safeTopY = visibleH / 2 - effectiveTop;
const safeBottomY = -visibleH / 2 + effectiveBottom;
const contentOffsetY = (safeTopY + safeBottomY) / 2;
const bgCoverScale = Math.max(visibleW / DESIGN_W, visibleH / DESIGN_H);
return {
visibleW,
visibleH,
topInset,
capsuleBottom,
bottomInset,
safeHeight,
safeHalfH,
extraH,
contentScale,
contentOffsetY,
bgCoverScale,
isWeChat,
mockCapsule,
};
}
/** 将主内容容器精准居中并缩放到安全区(避开微信胶囊 + 刘海 + 底部手势条) */
export function applySafeContentTransform(contentRoot: Node, m: ScreenMetrics): void {
const ui = contentRoot.getComponent(UITransform);
if (ui) ui.setContentSize(DESIGN_W, m.safeHeight);
contentRoot.setPosition(0, m.contentOffsetY, 0);
contentRoot.setScale(new Vec3(m.contentScale, m.contentScale, 1));
}
/** 将背景精灵按屏幕比例等比铺满(cover),消除全面屏上下黑边 */
export function applyCoverBackground(bgNode: Node, m: ScreenMetrics): void {
bgNode.setPosition(0, 0, 0);
bgNode.setScale(new Vec3(m.bgCoverScale, m.bgCoverScale, 1));
}
/** 将遮罩节点铺满全屏(兼容任意长宽比) */
export function applyFullScrimSize(scrimNode: Node, m: ScreenMetrics): void {
const ui = scrimNode.getComponent(UITransform);
if (ui) ui.setContentSize(Math.max(2400, m.visibleW + 40), Math.max(2400, m.visibleH + 40));
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a8021e06-ffa1-41ce-bd82-0ac950fbd90f",
"files": [],
"subMetas": {},
"userData": {}
}
+853
View File
@@ -0,0 +1,853 @@
import { Button, Color, Graphics, ImageAsset, Label, Layers, Node, resources, Sprite, SpriteFrame, Texture2D, UITransform, Widget } from 'cc';
declare const wx: any;
export const UI_LAYER = Layers.Enum.UI_2D;
export function hex(code: string): Color {
const c = new Color();
Color.fromHEX(c, code);
return c;
}
export interface BoxStyle {
fill?: string;
stroke?: string;
strokeWidth?: number;
radius?: number;
/** 3D 底部厚边(实体按键/木牌立体感) */
depth?: number;
depthColor?: string;
/** 柔和落影偏移 */
shadow?: number;
shadowColor?: string;
/** 顶部高光细线 */
highlight?: string;
/** 内侧虚线手缝线装饰 */
stitchColor?: string;
stitchInset?: number;
/** 四角黄铜铆钉装饰 */
rivets?: boolean;
rivetColor?: string;
}
export function createUINode(name: string, w: number, h: number, parent?: Node): Node {
const node = new Node(name);
node.layer = UI_LAYER;
const ui = node.addComponent(UITransform);
ui.setContentSize(w, h);
if (parent) parent.addChild(node);
return node;
}
function drawDashedRect(g: Graphics, x: number, y: number, w: number, h: number, color: string): void {
g.strokeColor = hex(color);
g.lineWidth = 1.6;
const dash = 7;
const gap = 5;
const drawEdge = (x1: number, y1: number, x2: number, y2: number) => {
const dist = Math.hypot(x2 - x1, y2 - y1);
const ux = (x2 - x1) / dist;
const uy = (y2 - y1) / dist;
let pos = 4;
while (pos < dist - 4) {
const end = Math.min(dist - 4, pos + dash);
g.moveTo(x1 + ux * pos, y1 + uy * pos);
g.lineTo(x1 + ux * end, y1 + uy * end);
pos = end + gap;
}
};
drawEdge(x, y + h, x + w, y + h);
drawEdge(x + w, y + h, x + w, y);
drawEdge(x + w, y, x, y);
drawEdge(x, y, x, y + h);
g.stroke();
}
export function drawPadlockIcon(
g: Graphics,
scale = 1,
bodyColor = '#d6b67d',
shackleColor = '#ecd2a2',
keyholeColor = '#46311f',
): void {
g.clear();
const s = scale;
const r = 3.7 * s;
const archY = 3.2 * s;
// 锁梁(U 型圆弧,手动采样保证各端方向一致)
g.strokeColor = hex(shackleColor);
g.lineWidth = Math.max(1.5, 2.0 * s);
g.moveTo(-r, 0.2 * s);
g.lineTo(-r, archY);
const steps = 12;
for (let i = 1; i <= steps; i++) {
const t = Math.PI - (Math.PI * i) / steps;
g.lineTo(Math.cos(t) * r, archY + Math.sin(t) * r);
}
g.lineTo(r, 0.2 * s);
g.stroke();
// 锁身(倒角金属块)
const bw = 11.4 * s;
const bh = 8.6 * s;
g.fillColor = hex(bodyColor);
g.roundRect(-bw / 2, -6.8 * s, bw, bh, 2.2 * s);
g.fill();
// 锁孔
g.fillColor = hex(keyholeColor);
g.circle(0, -1.7 * s, 1.45 * s);
g.fill();
g.rect(-0.68 * s, -4.6 * s, 1.36 * s, 2.7 * s);
g.fill();
}
export function drawEnvelopeIcon(g: Graphics, scale = 1, color = '#fff2cf', sealColor = '#d45a52'): void {
g.clear();
const s = scale;
const w = 22 * s;
const h = 15 * s;
g.strokeColor = hex(color);
g.lineWidth = Math.max(1.6, 2.1 * s);
g.roundRect(-w / 2, -h / 2, w, h, 2.4 * s);
g.stroke();
g.moveTo(-w / 2 + 1.5 * s, h / 2 - 1.5 * s);
g.lineTo(0, -1.2 * s);
g.lineTo(w / 2 - 1.5 * s, h / 2 - 1.5 * s);
g.stroke();
g.fillColor = hex(sealColor);
g.circle(0, -1.6 * s, 3.0 * s);
g.fill();
}
export function drawSpoolIcon(g: Graphics, scale = 1, woodColor = '#f4d694', threadColor = '#93be76'): void {
g.clear();
const s = scale;
// 绕线身
g.fillColor = hex(threadColor);
g.roundRect(-7 * s, -7 * s, 14 * s, 14 * s, 2.5 * s);
g.fill();
// 几道柔和丝线横纹
g.strokeColor = hex('#eef7dc99');
g.lineWidth = 1.3 * s;
for (const ry of [-3.4, 0, 3.4]) {
g.moveTo(-6.2 * s, ry * s);
g.lineTo(6.2 * s, ry * s);
}
g.stroke();
// 上下木挡片
g.fillColor = hex(woodColor);
g.roundRect(-10.5 * s, 6.2 * s, 21 * s, 4.4 * s, 2 * s);
g.roundRect(-10.5 * s, -10.6 * s, 21 * s, 4.4 * s, 2 * s);
g.fill();
}
export function drawGalleryFrameIcon(g: Graphics, scale = 1, frameColor = '#fff0c8', accentColor = '#e6b14c'): void {
g.clear();
const s = scale;
const w = 20 * s;
const h = 22 * s;
g.strokeColor = hex(frameColor);
g.lineWidth = Math.max(1.8, 2.2 * s);
g.roundRect(-w / 2, -h / 2, w, h, 3 * s);
g.stroke();
// 内绣绷圆环 + 小花点缀
g.strokeColor = hex(accentColor);
g.lineWidth = 1.6 * s;
g.circle(0, 1.5 * s, 5.4 * s);
g.stroke();
g.fillColor = hex(accentColor);
g.circle(0, 1.5 * s, 2.2 * s);
g.fill();
g.strokeColor = hex(frameColor);
g.lineWidth = 1.5 * s;
g.moveTo(-5.5 * s, -6.8 * s);
g.lineTo(5.5 * s, -6.8 * s);
g.stroke();
}
export function drawRoundedBox(g: Graphics, w: number, h: number, style: BoxStyle): void {
g.clear();
const r = Math.min(style.radius ?? 16, w / 2, h / 2);
const x = -w / 2;
const y = -h / 2;
const depth = style.depth ?? 0;
const shadow = style.shadow ?? 0;
// 1. 柔和地面投影
if (shadow > 0) {
g.fillColor = hex(style.shadowColor ?? '#1b211438');
const sy = y - depth - shadow;
if (r > 0) g.roundRect(x + 1, sy, w - 2, h, r);
else g.rect(x + 1, sy, w - 2, h);
g.fill();
}
// 2. 实体 3D 底座厚边
if (depth > 0) {
g.fillColor = hex(style.depthColor ?? '#3b4530');
if (r > 0) g.roundRect(x, y - depth, w, h, r);
else g.rect(x, y - depth, w, h);
g.fill();
}
// 3. 主面板填充
if (style.fill) {
g.fillColor = hex(style.fill);
if (r > 0) g.roundRect(x, y, w, h, r);
else g.rect(x, y, w, h);
g.fill();
}
// 4. 顶部微光高光带(让按钮/木牌有温润手作光泽)
if (style.highlight && w > 24 && h > 16) {
const inset = Math.max(4, Math.min(r * 0.65, 16));
g.strokeColor = hex(style.highlight);
g.lineWidth = 2;
g.moveTo(x + inset, y + h - 2.5);
g.lineTo(x + w - inset, y + h - 2.5);
g.stroke();
}
// 5. 外描边
if (style.stroke) {
g.strokeColor = hex(style.stroke);
g.lineWidth = style.strokeWidth ?? 2;
if (r > 0) g.roundRect(x, y, w, h, r);
else g.rect(x, y, w, h);
g.stroke();
}
// 6. 内侧手缝虚线
if (style.stitchColor) {
const inset = style.stitchInset ?? 8;
if (w > inset * 2 + 16 && h > inset * 2 + 16) {
drawDashedRect(g, x + inset, y + inset, w - inset * 2, h - inset * 2, style.stitchColor);
}
}
// 7. 四角黄铜铆钉
if (style.rivets && w > 48 && h > 40) {
const pad = Math.max(12, Math.min(18, r * 0.65));
const pts = [
[x + pad, y + h - pad],
[x + w - pad, y + h - pad],
[x + pad, y + pad],
[x + w - pad, y + pad],
];
for (const [rx, ry] of pts) {
g.fillColor = hex('#2c1e1255');
g.circle(rx, ry - 1.2, 3.6);
g.fill();
g.fillColor = hex(style.rivetColor ?? '#d9ad62');
g.circle(rx, ry, 3.2);
g.fill();
g.fillColor = hex('#fff2cfcc');
g.circle(rx - 0.9, ry + 0.9, 1.1);
g.fill();
}
}
}
export function createPanel(name: string, w: number, h: number, style: BoxStyle, parent?: Node): { node: Node; graphics: Graphics } {
const node = createUINode(name, w, h, parent);
const graphics = node.addComponent(Graphics);
drawRoundedBox(graphics, w, h, style);
return { node, graphics };
}
export interface LabelStyle {
size?: number;
lineHeight?: number;
color?: string;
bold?: boolean;
align?: number;
verticalAlign?: number;
overflow?: number;
}
export function createLabel(name: string, text: string, w: number, h: number, style: LabelStyle = {}, parent?: Node): Label {
const node = createUINode(name, w, h, parent);
const label = node.addComponent(Label);
label.string = text;
label.fontSize = style.size ?? 24;
label.lineHeight = style.lineHeight ?? Math.round((style.size ?? 24) * 1.25);
label.color = hex(style.color ?? '#302e22');
label.isBold = Boolean(style.bold);
label.horizontalAlign = style.align ?? Label.HorizontalAlign.CENTER;
label.verticalAlign = style.verticalAlign ?? Label.VerticalAlign.CENTER;
if (style.overflow !== undefined) label.overflow = style.overflow;
return label;
}
export interface ButtonSpec {
name: string;
text: string;
w: number;
h: number;
fill: string;
stroke?: string;
depth?: number;
depthColor?: string;
shadow?: number;
highlight?: string;
stitchColor?: string;
textColor?: string;
fontSize?: number;
radius?: number;
bold?: boolean;
onClick: () => void;
}
export interface StyledButton {
node: Node;
button: Button;
label: Label;
graphics: Graphics;
setStyle: (fill: string, stroke: string | undefined, textColor: string, depthColor?: string) => void;
setEnabled: (enabled: boolean) => void;
}
export function createButton(spec: ButtonSpec, parent?: Node): StyledButton {
const radius = spec.radius ?? Math.min(22, spec.h / 2);
const depth = spec.depth ?? 5;
const shadow = spec.shadow ?? 3;
const highlight = spec.highlight ?? '#ffffff55';
const defaultDepth = spec.depthColor ?? spec.stroke ?? '#3c4530';
const { node, graphics } = createPanel(
spec.name,
spec.w,
spec.h,
{
fill: spec.fill,
stroke: spec.stroke,
strokeWidth: 2,
radius,
depth,
depthColor: defaultDepth,
shadow,
highlight,
stitchColor: spec.stitchColor,
stitchInset: 6,
},
parent,
);
const label = createLabel(
'Label',
spec.text,
spec.w - 14,
spec.h,
{
size: spec.fontSize ?? 24,
color: spec.textColor ?? '#302e22',
bold: spec.bold ?? true,
overflow: Label.Overflow.SHRINK,
},
node,
);
const button = node.addComponent(Button);
button.transition = Button.Transition.SCALE;
button.zoomScale = 0.93;
node.on(Button.EventType.CLICK, () => {
if (button.interactable) spec.onClick();
});
return {
node,
button,
label,
graphics,
setStyle(fill: string, stroke: string | undefined, textColor: string, depthColor?: string) {
drawRoundedBox(graphics, spec.w, spec.h, {
fill,
stroke,
strokeWidth: 2,
radius,
depth,
depthColor: depthColor ?? stroke ?? defaultDepth,
shadow,
highlight,
stitchColor: spec.stitchColor,
stitchInset: 6,
});
label.color = hex(textColor);
},
setEnabled(enabled: boolean) {
button.interactable = enabled;
const base = label.color.clone();
base.a = enabled ? 255 : 115;
label.color = base;
},
};
}
export interface DockButtonSpec {
name: string;
icon: string;
text: string;
w: number;
h: number;
fill: string;
stroke: string;
depthColor: string;
iconBg: string;
iconColor: string;
textColor: string;
onClick: () => void;
}
export interface DockButton extends StyledButton {
iconLabel: Label;
iconBgGraphics: Graphics;
setDockStyle: (fill: string, stroke: string, depthColor: string, iconBg: string, iconColor: string, textColor: string) => void;
}
/** 底部游戏工具栏专用:上图标徽章 + 下短文字 + 3D 实体木/陶按压底座 */
export function createDockButton(spec: DockButtonSpec, parent?: Node): DockButton {
const radius = 20;
const { node, graphics } = createPanel(
spec.name,
spec.w,
spec.h,
{
fill: spec.fill,
stroke: spec.stroke,
strokeWidth: 2,
radius,
depth: 6,
depthColor: spec.depthColor,
shadow: 4,
highlight: '#fffdf466',
},
parent,
);
const badge = createPanel('IconBadge', 44, 44, { fill: spec.iconBg, radius: 22 }, node);
badge.node.setPosition(0, 14, 0);
const iconLabel = createLabel('Icon', spec.icon, 44, 44, { size: 25, color: spec.iconColor, bold: true }, badge.node);
const label = createLabel(
'Label',
spec.text,
spec.w - 10,
26,
{ size: 18, color: spec.textColor, bold: true, overflow: Label.Overflow.SHRINK },
node,
);
label.node.setPosition(0, -25, 0);
const button = node.addComponent(Button);
button.transition = Button.Transition.SCALE;
button.zoomScale = 0.91;
node.on(Button.EventType.CLICK, () => {
if (button.interactable) spec.onClick();
});
const applyDock = (fill: string, stroke: string, depthColor: string, iconBg: string, iconColor: string, textColor: string) => {
drawRoundedBox(graphics, spec.w, spec.h, {
fill,
stroke,
strokeWidth: 2,
radius,
depth: 6,
depthColor,
shadow: 4,
highlight: '#fffdf466',
});
drawRoundedBox(badge.graphics, 44, 44, { fill: iconBg, radius: 22 });
iconLabel.color = hex(iconColor);
label.color = hex(textColor);
};
return {
node,
button,
label,
graphics,
iconLabel,
iconBgGraphics: badge.graphics,
setStyle(fill: string, stroke: string | undefined, textColor: string, depthColor?: string) {
applyDock(fill, stroke ?? spec.stroke, depthColor ?? stroke ?? spec.depthColor, spec.iconBg, spec.iconColor, textColor);
},
setDockStyle: applyDock,
setEnabled(enabled: boolean) {
button.interactable = enabled;
const tc = label.color.clone();
tc.a = enabled ? 255 : 110;
label.color = tc;
const ic = iconLabel.color.clone();
ic.a = enabled ? 255 : 110;
iconLabel.color = ic;
},
};
}
function makeOffscreenCanvas(w: number, h: number): any {
const c = typeof wx !== 'undefined' && typeof wx.createCanvas === 'function'
? wx.createCanvas()
: document.createElement('canvas');
c.width = w;
c.height = h;
return c;
}
function canvasToSpriteFrame(canvas: any): SpriteFrame {
const img = new ImageAsset(canvas);
const tex = new Texture2D();
tex.image = img;
const sf = new SpriteFrame();
sf.texture = tex;
return sf;
}
let cachedPlayBg: SpriteFrame | null = null;
let cachedLobbyBg: SpriteFrame | null = null;
/** 生成对局场景全屏「手作刺绣工坊桌面」纹理(苔绿麻布台垫 + 暖光斜照 + 木桌边沿 + 角落小道具) */
export function createAtelierTableSpriteFrame(): SpriteFrame {
if (cachedPlayBg) return cachedPlayBg;
const W = 750;
const H = 1334;
const canvas = makeOffscreenCanvas(W, H);
const ctx: CanvasRenderingContext2D = canvas.getContext('2d');
// 1. 基底:苔藓绿手作亚麻桌垫渐变(模拟从左上方洒下的自然窗光)
const baseGrad = ctx.createRadialGradient(210, 260, 40, W * 0.52, H * 0.48, 860);
baseGrad.addColorStop(0, '#728562');
baseGrad.addColorStop(0.42, '#5c6e4f');
baseGrad.addColorStop(0.82, '#47573d');
baseGrad.addColorStop(1, '#36432e');
ctx.fillStyle = baseGrad;
ctx.fillRect(0, 0, W, H);
// 2. 亚麻细密织纹
ctx.save();
ctx.strokeStyle = 'rgba(255, 248, 226, 0.045)';
ctx.lineWidth = 1;
for (let x = 0; x < W; x += 6) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, H);
ctx.stroke();
}
ctx.strokeStyle = 'rgba(20, 28, 16, 0.05)';
for (let y = 0; y < H; y += 6) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(W, y);
ctx.stroke();
}
ctx.restore();
// 3. 左右极细原木桌沿(带来真实桌面的边界感,但绝不挤占空间)
const drawWoodTrim = (x0: number, w: number) => {
const g = ctx.createLinearGradient(x0, 0, x0 + w, 0);
g.addColorStop(0, '#6e492b');
g.addColorStop(0.5, '#8c603c');
g.addColorStop(1, '#583920');
ctx.fillStyle = g;
ctx.fillRect(x0, 0, w, H);
};
drawWoodTrim(0, 10);
drawWoodTrim(W - 10, 10);
// 4. 内侧细金线压边(刺绣桌垫滚边)
ctx.save();
ctx.strokeStyle = 'rgba(244, 224, 174, 0.24)';
ctx.lineWidth = 2;
ctx.setLineDash([8, 6]);
ctx.strokeRect(20, 20, W - 40, H - 40);
ctx.restore();
// 5. 柔和斜射日光斑(氛围层次)
ctx.save();
const sunGrad = ctx.createLinearGradient(0, 0, 560, 620);
sunGrad.addColorStop(0, 'rgba(255, 245, 212, 0.14)');
sunGrad.addColorStop(0.5, 'rgba(255, 245, 212, 0.03)');
sunGrad.addColorStop(1, 'rgba(255, 245, 212, 0)');
ctx.fillStyle = sunGrad;
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(520, 0);
ctx.lineTo(750, 480);
ctx.lineTo(750, 720);
ctx.lineTo(0, 240);
ctx.closePath();
ctx.fill();
ctx.restore();
// 6. 绣绷底座大柔影(让中央木绣绷宛如真实搁在桌面上)
ctx.save();
const hoopShadow = ctx.createRadialGradient(W / 2, 654, 240, W / 2, 668, 368);
hoopShadow.addColorStop(0, 'rgba(18, 25, 14, 0.42)');
hoopShadow.addColorStop(0.72, 'rgba(18, 25, 14, 0.18)');
hoopShadow.addColorStop(1, 'rgba(18, 25, 14, 0)');
ctx.fillStyle = hoopShadow;
ctx.beginPath();
ctx.arc(W / 2, 658, 368, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
// 7. 桌面四角低调手作装饰(角落暗纹藤叶 + 右下角小木线轴剪影,绝不抢戏)
ctx.save();
ctx.strokeStyle = 'rgba(240, 224, 182, 0.14)';
ctx.lineWidth = 2;
const drawCornerLeaf = (cx: number, cy: number, sx: number, sy: number) => {
ctx.save();
ctx.translate(cx, cy);
ctx.scale(sx, sy);
ctx.beginPath();
ctx.moveTo(0, 48);
ctx.quadraticCurveTo(6, 6, 48, 0);
ctx.stroke();
ctx.beginPath();
ctx.ellipse(22, 16, 10, 4.5, -0.5, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.ellipse(14, 30, 9, 4, -1.0, 0, Math.PI * 2);
ctx.stroke();
ctx.restore();
};
drawCornerLeaf(32, 232, 1, 1);
drawCornerLeaf(W - 32, 232, -1, 1);
drawCornerLeaf(32, 1142, 1, -1);
drawCornerLeaf(W - 32, 1142, -1, -1);
ctx.restore();
// 8. 底部深暗脚垫渐变(托举底部木质工具盘)
const bottomGrad = ctx.createLinearGradient(0, H - 240, 0, H);
bottomGrad.addColorStop(0, 'rgba(24, 31, 19, 0)');
bottomGrad.addColorStop(1, 'rgba(22, 29, 17, 0.42)');
ctx.fillStyle = bottomGrad;
ctx.fillRect(0, H - 240, W, 240);
cachedPlayBg = canvasToSpriteFrame(canvas);
return cachedPlayBg;
}
/** 生成大厅场景全屏「温暖原木手作书案」纹理(暖橡木桌底 + 苔绿亚麻桌旗 + 阳光光晕) */
export function createLobbyDeskSpriteFrame(): SpriteFrame {
if (cachedLobbyBg) return cachedLobbyBg;
const W = 750;
const H = 1334;
const canvas = makeOffscreenCanvas(W, H);
const ctx: CanvasRenderingContext2D = canvas.getContext('2d');
// 1. 暖杏色手工木案渐变
const deskGrad = ctx.createLinearGradient(0, 0, 0, H);
deskGrad.addColorStop(0, '#627354');
deskGrad.addColorStop(0.24, '#56674a');
deskGrad.addColorStop(0.242, '#eadbc0');
deskGrad.addColorStop(0.55, '#f2e6cf');
deskGrad.addColorStop(1, '#dfd0b1');
ctx.fillStyle = deskGrad;
ctx.fillRect(0, 0, W, H);
// 2. 顶部苔绿工坊幕布区域(给游戏标题与今日绣绷展示台营造景深)
const topCloth = ctx.createRadialGradient(W * 0.35, 110, 30, W * 0.5, 190, 520);
topCloth.addColorStop(0, '#6f825e');
topCloth.addColorStop(0.55, '#546548');
topCloth.addColorStop(1, '#3f4e36');
ctx.fillStyle = topCloth;
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(W, 0);
ctx.lineTo(W, 338);
ctx.quadraticCurveTo(W / 2, 372, 0, 338);
ctx.closePath();
ctx.fill();
// 3. 顶部幕布金线滚边与波浪收口
ctx.save();
ctx.strokeStyle = 'rgba(244, 221, 168, 0.55)';
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(0, 338);
ctx.quadraticCurveTo(W / 2, 372, W, 338);
ctx.stroke();
ctx.strokeStyle = 'rgba(255, 245, 218, 0.25)';
ctx.lineWidth = 1.6;
ctx.setLineDash([7, 6]);
ctx.beginPath();
ctx.moveTo(18, 326);
ctx.quadraticCurveTo(W / 2, 358, W - 18, 326);
ctx.stroke();
ctx.restore();
// 4. 下半部分亚麻纸/木纹细肌理
ctx.save();
ctx.strokeStyle = 'rgba(138, 112, 74, 0.045)';
ctx.lineWidth = 1;
for (let y = 360; y < H; y += 7) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(W, y);
ctx.stroke();
}
ctx.strokeStyle = 'rgba(255, 250, 238, 0.14)';
for (let x = 0; x < W; x += 9) {
ctx.beginPath();
ctx.moveTo(x, 360);
ctx.lineTo(x, H);
ctx.stroke();
}
ctx.restore();
// 5. 左右原木桌框边条
const drawSideWood = (x0: number, w: number) => {
const g = ctx.createLinearGradient(x0, 0, x0 + w, 0);
g.addColorStop(0, '#7c5534');
g.addColorStop(0.5, '#9d7048');
g.addColorStop(1, '#684528');
ctx.fillStyle = g;
ctx.fillRect(x0, 0, w, H);
};
drawSideWood(0, 8);
drawSideWood(W - 8, 8);
// 6. 顶部柔光粒子光晕(手作温暖感)
ctx.save();
const glow = ctx.createRadialGradient(140, 80, 10, 140, 80, 260);
glow.addColorStop(0, 'rgba(255, 244, 206, 0.18)');
glow.addColorStop(1, 'rgba(255, 244, 206, 0)');
ctx.fillStyle = glow;
ctx.fillRect(0, 0, 420, 340);
ctx.restore();
cachedLobbyBg = canvasToSpriteFrame(canvas);
return cachedLobbyBg;
}
/** 创建全屏纹理背景精灵 */
export function createBackdropSprite(name: string, frame: SpriteFrame, parent: Node): Node {
const node = createUINode(name, 750, 1334, parent);
const sp = node.addComponent(Sprite);
sp.sizeMode = Sprite.SizeMode.CUSTOM;
sp.spriteFrame = frame;
stretchToParent(node);
return node;
}
const uiSpriteCache = new Map<string, SpriteFrame>();
/** 从 assets/resources/<path> 异步加载 Meowa 生成的精绘游戏 UI 精灵(自动兼容 SpriteFrame 与 ImageAsset) */
export function loadUiSprite(resourcePath: string, sprite: Sprite): void {
const cached = uiSpriteCache.get(resourcePath);
if (cached) {
if (sprite.isValid) sprite.spriteFrame = cached;
return;
}
resources.load(`${resourcePath}/spriteFrame`, SpriteFrame, (err, sf) => {
if (!err && sf) {
uiSpriteCache.set(resourcePath, sf);
if (sprite.isValid) sprite.spriteFrame = sf;
return;
}
resources.load(resourcePath, ImageAsset, (imgErr, img) => {
if (imgErr || !img) return;
const tex = new Texture2D();
tex.image = img;
const fallbackSf = new SpriteFrame();
fallbackSf.texture = tex;
uiSpriteCache.set(resourcePath, fallbackSf);
if (sprite.isValid) sprite.spriteFrame = fallbackSf;
});
});
}
/** 创建加载 Meowa 美术贴图的精灵节点 */
export function createArtSprite(name: string, resourcePath: string, w: number, h: number, parent: Node): { node: Node; sprite: Sprite } {
const node = createUINode(name, w, h, parent);
const sprite = node.addComponent(Sprite);
sprite.sizeMode = Sprite.SizeMode.CUSTOM;
loadUiSprite(resourcePath, sprite);
return { node, sprite };
}
export interface ArtButtonSpec {
name: string;
resourcePath: string;
text?: string;
w: number;
h: number;
textColor?: string;
fontSize?: number;
textOffsetY?: number;
bold?: boolean;
onClick: () => void;
}
export interface ArtButton {
node: Node;
button: Button;
sprite: Sprite;
label?: Label;
setEnabled: (enabled: boolean) => void;
}
/** 创建基于 Meowa 手绘贴图的实体按压按钮 */
export function createArtButton(spec: ArtButtonSpec, parent: Node): ArtButton {
const { node, sprite } = createArtSprite(spec.name, spec.resourcePath, spec.w, spec.h, parent);
let label: Label | undefined;
if (spec.text !== undefined) {
label = createLabel(
'Label',
spec.text,
spec.w - 28,
spec.h - 8,
{
size: spec.fontSize ?? 26,
color: spec.textColor ?? '#3b240a',
bold: spec.bold ?? true,
overflow: Label.Overflow.SHRINK,
},
node,
);
if (spec.textOffsetY) label.node.setPosition(0, spec.textOffsetY, 0);
}
const button = node.addComponent(Button);
button.transition = Button.Transition.SCALE;
button.zoomScale = 0.92;
node.on(Button.EventType.CLICK, () => {
if (button.interactable) spec.onClick();
});
const res: ArtButton = {
node,
button,
sprite,
label,
setEnabled(enabled: boolean) {
button.interactable = enabled;
sprite.color = enabled ? hex('#ffffff') : hex('#c2b8a8');
if (res.label) {
const c = res.label.color.clone();
c.a = enabled ? 255 : 155;
res.label.color = c;
}
},
};
return res;
}
export function stretchToParent(node: Node): Widget {
const widget = node.addComponent(Widget);
widget.isAlignTop = true;
widget.isAlignBottom = true;
widget.isAlignLeft = true;
widget.isAlignRight = true;
widget.top = 0;
widget.bottom = 0;
widget.left = 0;
widget.right = 0;
widget.alignMode = Widget.AlignMode.ON_WINDOW_RESIZE;
return widget;
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "88e02ada-30d0-40d3-bed4-28c125a80104",
"files": [],
"subMetas": {},
"userData": {}
}