import { _decorator, Component, instantiate, Node, Prefab, sp, tween, UIOpacity, UITransform, v3 } from 'cc'; import { Icon } from './Icon'; import { Roller } from './Roller'; import { RollerManager } from './RollerManager'; let { ccclass, property } = _decorator; @ccclass('UpLayer') export class UpLayer extends Component { @property(Node) scatterLayer: Node = null; @property(Node) MultiLayer: Node = null; @property(Node) winLayer: Node = null; @property(Node) winGrayLayer: Node = null; @property(Node) winSpineLayer: Node = null; @property(Node) winIconLayer: Node = null; @property(Prefab) winSpinePrefab: Prefab = null; // 统一隐藏所有层 hideAllLayer() { this.scatterLayer.active = false; this.MultiLayer.active = false; this.winLayer.active = false; this.winGrayLayer.active = false; this.winSpineLayer.active = false; this.winIconLayer.active = false; } // ---------------------------------------winIconLayer相关 --------------------------------------- setWinLayerActive(bol: boolean) { this.winLayer.active = bol; this.winIconLayer.active = bol; this.winSpineLayer.active = bol; this.setWinGrayNode(bol); } setWinGrayNode(bool: boolean) { this.winLayer.active = true; this.winSpineLayer.active = true; let uiOpacity = this.winGrayLayer.getComponent(UIOpacity); if (bool) { this.winGrayLayer.active = bool; uiOpacity.opacity = 0; tween(uiOpacity) .to(0.2, { opacity: 255 }, { easing: 'quadOut' }) .start(); } else { uiOpacity.opacity = 255; tween(uiOpacity) .to(0.2, { opacity: 0 }, { easing: 'quadOut' }) .call(() => { this.winLayer.active = false; this.winSpineLayer.active = false; this.winGrayLayer.active = bool; }) .start(); } } playIconWinAni(iconNode: Node) { this.winLayer.active = true; this.winSpineLayer.active = true; this.winIconLayer.active = true; let iconWorldPosition = iconNode.getWorldPosition(); let iconLocalPosition = this.winIconLayer.getComponent(UITransform).convertToNodeSpaceAR(iconWorldPosition); iconNode.parent = this.winIconLayer; iconNode.setPosition(iconLocalPosition); iconNode.getComponent(Icon).playBounceSpine(); let winSpineNode = instantiate(this.winSpinePrefab); let spine = winSpineNode.getChildByName('spine').getComponent(sp.Skeleton); winSpineNode.parent = this.winSpineLayer; winSpineNode.setPosition(iconLocalPosition); winSpineNode.setSiblingIndex(9999); spine.setCompleteListener(null); spine.setCompleteListener(() => { winSpineNode.destroy(); }); spine.setAnimation(0, 'animation', false); } // ---------------------------------------readyHandNode、scatterLayer、wildLayer相关 --------------------------------------- adopted = new Map(); setSpecialLayersActive() { let hasMulti = Array.from(this.adopted.values()).some(v => v.type === 'Multi'); let hasScatter = Array.from(this.adopted.values()).some(v => v.type === 'scatter'); this.MultiLayer.active = hasMulti; this.scatterLayer.active = hasScatter; } adoptSpecial(node: Node, rollerId: number, startPos: number, height: number, type: 'Multi' | 'scatter') { if (!node || !node.isValid) return; if (this.adopted.has(node)) return; let wp = node.worldPosition.clone(); let layer = type === 'Multi' ? this.MultiLayer : this.scatterLayer; layer.active = true; node.parent = layer; node.setWorldPosition(wp); node.setSiblingIndex(9999); this.adopted.set(node, { rollerId, startPos, height, type }); this.setSpecialLayersActive(); } // 增量同步某列(停轮/单列落定时可用) syncSpecialFromRoller(roller: Roller) { if (!roller) return; let seen = new Set(); for (let i = 0; i < roller.row; i++) { let n = (roller as any).getIconNode(i); if (!n || seen.has(n)) continue; seen.add(n); let icon = n.getComponent(Icon); if (!icon || !icon.isWildOrScatter) continue; let msg = (roller as any).getNodeMsgFromPos(i); if (!msg) continue; let type: 'Multi' | 'scatter' = icon.index === 0 ? 'Multi' : 'scatter'; this.adoptSpecial(msg.node, roller.rollerId, msg.start, msg.height, type); } } // 删除前:去登记,避免后续“归还” removeSpecialByNode(node: Node) { if (!node) return; if (this.adopted.delete(node)) this.setSpecialLayersActive(); } // 统一归还(开新轮或重算前调用) giveBackAllSpecials(rm: RollerManager) { if (!rm) return; this.adopted.forEach((info, node) => { if (!node || !node.isValid) return; let roller = rm.allRollers[info.rollerId]; if (!roller) return; node.parent = roller.node; node.setPosition(roller.getIconPosition(info.startPos, info.height)); }); this.adopted.clear(); this.setSpecialLayersActive(); } // 全量重算:不累加,重新扫描所有列 resetAndSyncAllSpecials(rm: RollerManager) { if (!rm) return; this.giveBackAllSpecials(rm); // 清空旧数据与节点 for (let i = 0; i < rm.allRollers.length; i++) { this.syncSpecialFromRoller(rm.allRollers[i]); } } playScatterWaitSpine(bol: boolean) { this.scatterLayer.children.forEach(child => child.getComponent(Icon).playScatterWaitSpine(bol)); } }