import { _decorator, assetManager, BitmapFont, Component, Graphics, Mask, Sprite, SpriteFrame, UITransform, Widget } from 'cc'; import { EDITOR } from 'cc/env'; import { ART, ART_KEYS, FONT_UUID, SYMBOL_ART } from './OrchardAssets'; import { OrchardComposer } from './OrchardComposer'; import { authorDialogs } from './OrchardDialogs'; import { OrchardView } from './OrchardView'; import { initialState } from './GameSession'; const { ccclass, property, executeInEditMode } = _decorator; @ccclass('OrchardAuthoring') @executeInEditMode export class OrchardAuthoring extends Component { @property status = 'Not authored'; @property get composeReference(): boolean { return false; } set composeReference(value: boolean) { if (!EDITOR || !value || this.status === 'Preparing artwork') return; this.status = 'Preparing artwork'; assetManager.loadAny([...ART_KEYS.map(key => ART[key]), FONT_UUID], (error, assets) => { if (!this.isValid) return; if (error) { this.status = 'Artwork preparation failed'; return; } try { const list = assets as (SpriteFrame | BitmapFont)[]; const view = this.node.getComponent(OrchardView) ?? this.node.addComponent(OrchardView); view.artFrames = list.slice(0, ART_KEYS.length) as SpriteFrame[]; view.numerals = list[ART_KEYS.length] as BitmapFont; this.compose(view); this.status = 'Ready: editable reference layout'; } catch (cause) { this.status = `Layout error: ${cause instanceof Error ? cause.message : 'unknown'}`; } }); } private compose(view: OrchardView): void { const root = this.node; const widget = root.getComponent(Widget); if (widget) { widget.alignFlags = 0; widget.enabled = false; } root.getComponent(UITransform)!.setContentSize(1080, 1920); root.setPosition(540, 960, 0); const ui = new OrchardComposer(root, key => view.artFrames[ART_KEYS.indexOf(key)], view.numerals!); ui.image('OrchardScenery', 'berry-satin', 540, 960, 1080, 1920); ui.image('OrchardCrest', 'crest-lockup', 516, 223, 633, 417); ui.button('PreferencesAccess', 'preferences-orb', 96, 78, 122, 122); ui.image('WalletPlate', 'wallet-pill', 906, 50, 314, 92); ui.text('WalletAmount', '100,000', 937, 48, 210, 68, 47); ui.image('ReelSurround', 'neon-grid', 540, 817, 1080, 755); const board = initialState().board; for (let c = 0; c < 5; c++) { const column = ui.group(`ReelWindow${c}`); column.setPosition(-410 + c * 205, 145, 0); column.getComponent(UITransform)!.setContentSize(200, 690); const mask = column.getComponent(Mask) ?? column.addComponent(Mask); mask.type = Mask.Type.GRAPHICS_RECT; for (let r = 0; r < 6; r++) { const n = ui.image(`Cell${r}`, SYMBOL_ART[board[c][r % 3]], 540, 960, 190, 205, column); n.setPosition(0, 230 - r * 230, 0); n.getComponent(Sprite)!.trim = false; const size = n.getComponent(Sprite)!.spriteFrame!.originalSize; const scale = Math.min(198 / size.width, 212 / size.height); n.getComponent(UITransform)!.setContentSize(size.width * scale, size.height * scale); } } const lines = ui.group('WinningLines'); lines.getComponent(Graphics) ?? lines.addComponent(Graphics); const normal = ui.group('NormalPrize'); ui.image('NormalPrizePlate', 'prize-plaque', 540, 1287, 712, 153, normal); ui.image('NormalPrizeTitle', 'prize-heading', 380, 1287, 190, 86, normal); ui.text('NormalPrizeAmount', '0', 641, 1288, 310, 124, 108, normal, true); const ribbon = ui.group('RoundsRibbon'); ui.image('RoundsPlate', 'rounds-ribbon', 540, 1257, 980, 138, ribbon); ui.image('RoundsHeading', 'bonus-heading', 416, 1257, 354, 58, ribbon); ui.text('RoundsCount', '8', 649, 1257, 128, 92, 85, ribbon, true); ui.image('RoundsSuffix', 'remaining-heading', 776, 1257, 151, 58, ribbon); ribbon.active = false; const dual = ui.group('BonusPrize'); ui.image('RoundPrizePlate', 'round-prize-card', 300, 1404, 431, 150, dual); ui.image('BonusPrizePlate', 'bonus-prize-card', 770, 1404, 482, 162, dual); ui.text('RoundPrizeAmount', '0', 300, 1425, 350, 90, 76, dual, true); ui.text('BonusPrizeAmount', '0', 770, 1425, 395, 95, 78, dual, true); dual.active = false; const wager = ui.group('WagerControls'); wager.setPosition(0, -500, 0); ui.image('WagerPlate', 'wager-plaque', 540, 960, 773, 139, wager); ui.button('WagerDecrease', 'wager-down', 248, 960, 126, 102, wager); ui.button('WagerIncrease', 'wager-up', 834, 960, 128, 102, wager); ui.image('WagerTitle', 'wager-heading', 442, 960, 96, 59, wager); ui.text('WagerAmount', '2,000', 602, 960, 218, 90, 73, wager, true); ui.button('LaunchAccess', 'launch-orb', 540, 1714, 342, 341); ui.button('RepeatAccess', 'repeat-orb', 760, 1598, 141, 140); ui.button('GuideAccess', 'guide-pill', 164, 1720, 284, 123); ui.button('GiftAccess', 'daily-pill', 928, 1720, 264, 121); ui.text('GameNotice', '', 540, 191, 760, 84, 30).active = false; authorDialogs(ui); } }