import { _decorator, Button, Canvas, Color, Component, Label, Node, Sprite, UITransform, Widget } from 'cc'; import { EDITOR } from 'cc/env'; import { GuestLoginView } from './GuestLoginView'; import { StartupLoadingView } from '../../startup/scripts/StartupLoadingView'; const { ccclass, executeInEditMode, property } = _decorator; /** 仅按显式开关校准已存在节点,不在运行时重建界面。 / Explicit editor-only calibration of existing nodes; never rebuild UI at runtime. */ @ccclass('WelcomeLayoutAuthoring') @executeInEditMode export class WelcomeLayoutAuthoring extends Component { @property get applyPreparationLayout(): boolean { return false; } set applyPreparationLayout(value: boolean) { if (!EDITOR || !value) return; const panel = this.child(this.node, 'PreparationPanel'); const group = this.child(this.node, 'WelcomeComposition'); const loading = this.node.getComponent(StartupLoadingView); if (!loading || !loading.frameArtwork || !loading.fillArtwork) throw new Error('Preparation artwork is not bound.'); this.box(panel, 0, 0, 1080, 1920); this.text(this.child(panel, 'PreparationTitle'), 'LOADING...', -45, -454, 640, 90, 68); this.text(this.child(panel, 'PreparationPercent'), '70%', 368, -454, 220, 90, 68); this.text(this.child(panel, 'PreparationCaption'), 'Getting things ready', 0, -699, 920, 76, 51); for (const name of ['PreparationTitle', 'PreparationPercent', 'PreparationCaption']) { this.child(panel, name).getComponent(Label)!.isBold = true; } const frame = this.child(panel, 'PreparationFrame'); this.box(frame, -2.5, -576, 973, 168); frame.getComponent(Sprite)!.spriteFrame = loading.frameArtwork; this.sprite(frame); const fill = this.child(panel, 'PreparationFill'); this.box(fill, -458, -582, 906, 102); fill.getComponent(UITransform)!.setAnchorPoint(0, .5); const meter = fill.getComponent(Sprite)!; meter.spriteFrame = loading.fillArtwork; this.sprite(fill); meter.type = Sprite.Type.SLICED; // 左右圆头保持固定宽度,中段伸缩,不拉伸整条高光。 / Keep rounded caps fixed and stretch only the center highlight. // 九宫格边距由重命名资源的导入设置持久化。 / Slice borders are persisted in the renamed resource import settings. loading.login = group.getComponent(GuestLoginView); loading.panel = panel; loading.meter = meter; loading.percentage = this.child(panel, 'PreparationPercent').getComponent(Label); loading.caption = this.child(panel, 'PreparationCaption').getComponent(Label); loading.loginControls = ['GuestAccess', 'GuestReassurance', 'PrivacyLink', 'TermsLink', 'LegalDivider', 'AuthenticationStatus'].map(name => this.child(group, name)); fill.getComponent(UITransform)!.setContentSize(906 * .7, 102); panel.active = false; } @property get applyReferenceLayout(): boolean { return false; } set applyReferenceLayout(value: boolean) { if (!EDITOR || !value) return; const canvas = this.node; const group = this.child(canvas, 'WelcomeComposition'); const widget = canvas.getComponent(Widget); if (widget) { widget.alignFlags = 0; widget.enabled = false; } // 保存的设计画布与项目设置保持一致,运行适配仍由独立组件负责。 / Persist the design canvas; the viewport component owns runtime adaptation. canvas.getComponent(UITransform)!.setContentSize(1080, 1920); canvas.setPosition(540, 960, 0); const camera = canvas.getChildByName('Camera'); if (!canvas.getComponent(Canvas) || !camera) throw new Error('Welcome canvas is unavailable.'); const backdrop = this.child(canvas, 'OrchardBackdrop'); this.box(backdrop, 0, 0, 1080, 1920); backdrop.setSiblingIndex(1); this.sprite(backdrop); this.box(this.child(group, 'BrandMark'), 4, 466.5, 982, 643); this.box(this.child(group, 'FruitArrangement'), -7.5, -78, 991, 456); this.box(this.child(group, 'GuestAccess'), -1.5, -460, 1027, 268); for (const name of ['BrandMark', 'FruitArrangement', 'GuestAccess']) this.sprite(this.child(group, name)); const button = this.child(group, 'GuestAccess').getComponent(Button); if (button) { button.transition = Button.Transition.SCALE; button.zoomScale = .97; } this.text(this.child(group, 'GuestReassurance'), 'No account needed', 0, -618, 780, 90, 56); this.text(this.child(group, 'PrivacyLink'), 'Privacy Policy', -190, -765, 300, 88, 38, true); this.text(this.child(group, 'TermsLink'), 'Terms of Service', 179, -765, 340, 88, 38, true); this.text(this.child(group, 'LegalDivider'), '|', -10, -765, 28, 76, 56); this.child(group, 'LegalDivider').getComponent(Label)!.color = new Color(236, 0, 136, 255); const status = this.child(group, 'AuthenticationStatus'); this.text(status, '', 0, -692, 960, 50, 25); status.active = false; } private child(parent: Node, name: string): Node { const node = parent.getChildByName(name); if (!node) throw new Error(`Missing welcome node: ${name}`); return node; } private box(node: Node, x: number, y: number, width: number, height: number): void { node.setPosition(x, y, 0); node.setScale(1, 1, 1); node.getComponent(UITransform)!.setContentSize(width, height); } private sprite(node: Node): void { const sprite = node.getComponent(Sprite)!; sprite.sizeMode = Sprite.SizeMode.CUSTOM; sprite.trim = false; } private text(node: Node, text: string, x: number, y: number, width: number, height: number, font: number, underline = false): void { const label = node.getComponent(Label)!; label.overflow = Label.Overflow.SHRINK; label.string = text; label.fontFamily = 'Arial'; label.fontSize = font; label.lineHeight = font + 8; label.horizontalAlign = Label.HorizontalAlign.CENTER; label.verticalAlign = Label.VerticalAlign.CENTER; label.enableWrapText = true; label.isBold = false; label.isUnderline = underline; label.color = new Color(250, 250, 250, 255); this.box(node, x, y, width, height); } }