// import { _decorator, color, Color, Component, Graphics, instantiate, Label, Node, Prefab, sp, UIOpacity, UITransform, v3, Vec3 } from 'cc'; // import { Icon } from './Icon'; // import { RollerManager } from './RollerManager'; // import { gold2cash } from '../../../Loading/scripts/comm'; // import { NodePoolManager } from '../../../Loading/scripts/manager/NodePoolManager'; // import { AudioManager } from '../../../Loading/scripts/manager/AudioManager'; // const { ccclass, property } = _decorator; // @ccclass('WinLayer') // export class WinLayer extends Component { // // 灰色节点 // @property(Node) // grayNode: Node = null; // // 方框动画父节点 // @property(Node) // winEffectParent: Node = null; // // 方框动画 // @property(Prefab) // winEffectPre: Prefab = null; // // 线的父节点 // @property(Node) // lineParentNode: Node = null; // @property(Prefab) // lineSpinePre: Prefab = null; // // icon父节点 // @property(Node) // iconLayer: Node = null; // // rollerManager // @property(RollerManager) // rollerManager: RollerManager = null; // // 左右两边光效节点 // @property(Node) // lineNum: Node = null; // // 分数节点 // @property(Label) // score: Label = null; // iconPosArray: Vec3[] = []; // 图标位置数组 // hitLineData: HitLineMap; // 中奖数据 // hitBlockData: HitBlockInfo[] = []; // aniTime: number = 2; // 动画间隔 // columnGroups: number[][][] = []; // 服务器数据转本地需要的数据 // drawLineData: number[] = []; // winningIconPos: number[] = []; // private winIconNodeMap: Map = new Map; // 保存本地的icon // start() { // for (let i = 0; i < 10; i++) { // let worldPos = this.rollerManager.getIconWorldPosition(i); // let localPos = this.iconLayer.getComponent(UITransform).convertToNodeSpaceAR(worldPos); // this.iconPosArray.push(localPos) // } // } // processHitLineData(hitLineData: HitLineMap) { // if (!hitLineData || Object.keys(hitLineData).length === 0) { // return []; // } // let keys: number[] = Object.keys(hitLineData) // .filter(key => hitLineData[key] !== null) // 过滤 null 的条目 // .map(key => parseInt(key)); // let lines: number[][] = keys.map(key => hitLineData[key]?.Line || []); // // 获取 [[1,2,5,6,8],[1,5,8],[2,6,8]],去重后的所有中奖图标集合 // let lineGroups = [ // lines.reduce((acc, curr) => acc.concat(curr), []) // 展开所有 Line 数据 // .filter((value, index, self) => self.indexOf(value) === index), // 去重 // ...lines, // 每个 Line 数据单独作为一个分组 // ]; // // 映射 // let mappedLineGroups = lineGroups.map(lineGroup => // lineGroup.map(iconIndex => ICON_POSITION[iconIndex] !== undefined ? ICON_POSITION[iconIndex] : iconIndex) // ); // // 按列划分 mappedLineGroups // let columns = [ // [0, 1, 2], // [3, 4, 5, 6], // [7, 8, 9], // // 如果列数更多,可以继续添加更多的列 // ]; // let columnGroups = mappedLineGroups.map(lineGroup => // columns.map(column => // lineGroup.filter(iconIndex => column.indexOf(iconIndex) !== -1) // 用 indexOf 代替 includes // ) // ); // return columnGroups; // // columnGroups: [ // // [[1, 2], [3, 5, 6], [7, 8]], // 基于 lineGroups[0]: [1,2,3,5,6,7,8] // // [[1], [5], [8]], // 基于 lineGroups[1]: [1,5,8] // // [[2], [6], [8]], // 基于 lineGroups[2]: [2,6,8] // // [[1], [3], [7]], // 基于 lineGroups[3]: [1,3,7] // // ] // } // getLines(hitLineData: HitLineMap): number[] { // if (hitLineData == null) return []; // if (Object.keys(hitLineData) == null) return []; // this.drawLineData = []; // for (let key of Object.keys(hitLineData)) { // this.drawLineData.push(+key); // } // return this.drawLineData; // } // playAni(bol: boolean, spinData?: SpinData, isFreeSpin: boolean = false) { // if (bol) { // // 处理数据 // this.grayNode.active = true; // if (spinData.HitLine != null && spinData.HitBlock.length < 5) { // this.hitLineData = spinData.HitLine; // this.columnGroups = this.processHitLineData(spinData.HitLine); // this.drawLineData = this.getLines(spinData.HitLine); // this.loopAnimations(); // } else if (spinData.HitLine == null && spinData.HitBlock.length >= 5) { // this.hitBlockData = spinData.HitBlock; // if (isFreeSpin) { // } else { // this.playBoxAni(bol); // } // } // } else { // this.grayNode.active = false; // this.playScore(false, 0); // this.stopAnimations(); // this.lineParentNode.removeAllChildren(); // } // } // payLineOn(lines: number[]) { // lines.forEach(line => { // let left = this.lineNum.getChildByName(`payline_on_left_${line}`); // let right = this.lineNum.getChildByName(`payline_on_right_${line}`); // left.getComponent(UIOpacity).opacity = 255; // right.getComponent(UIOpacity).opacity = 255; // }) // } // payAllLineOff() { // this.lineNum.children.forEach(child => { // child.getComponent(UIOpacity).opacity = 0; // }) // } // playScore(bol: boolean, score: number) { // this.score.node.active = bol; // if (bol) // this.score.string = gold2cash(score); // } // loopAnimations() { // let playAllAnimations = (onComplete: () => void) => { // // 线 // this.payLineOn(this.drawLineData); // this.recycleAniNode(); // this.playScore(false, 0); // AudioManager.instance.playSFX('Win_Score_Sound', 0.5); // //按顺序播放动画 // let allIconsPos = this.columnGroups[0]; // this.winningIconPos = []; // for (let i = 0; i < allIconsPos.length; i++) { // this.scheduleOnce(() => { // let posArr = allIconsPos[i]; // this.playAnimationAtPosition(posArr); // this.playWinIconSpine(true, posArr); // this.winningIconPos.push(...posArr); // }, i * 0.15) // } // // 画线 // this.drawLines(); // // 假设每个动画时长 2 秒,延时后回调完成事件 // if (Object.keys(this.hitLineData).length == 1) { // return; // } // this.scheduleOnce(() => { // this.playWinIconSpine(false, this.winningIconPos); // this.recycleAniNode(); // this.payAllLineOff(); // this.lineParentNode.removeAllChildren(); // onComplete(); // }, this.aniTime); // }; // let playLineAnimations = (lineIndex: number, onComplete: () => void) => { // if (lineIndex >= this.columnGroups.length) { // onComplete(); // return; // } // // 播放中奖线 // let keysNum = Object.keys(this.hitLineData).map(Number); // 获取并转换为数字 // this.payLineOn([keysNum[lineIndex - 1]]); // AudioManager.instance.playSFX('Win_Line_Sound', 0.5); // let allIconsPos = this.columnGroups[lineIndex]; // this.winningIconPos = []; // for (let i = 0; i < allIconsPos.length; i++) { // this.scheduleOnce(() => { // let posArr = allIconsPos[i]; // this.playAnimationAtPosition(posArr); // this.playWinIconSpine(true, posArr); // this.winningIconPos.push(...posArr); // }, i * 0.15) // } // // 播放分数 // this.drawOneLine(this.drawLineData[lineIndex - 1]); // this.playScore(true, this.hitLineData[keysNum[lineIndex - 1]].Score); // let worldPos = this.rollerManager.getIconWorldPosition(allIconsPos[1][0]); // let localPos = this.score.node.parent.getComponent(UITransform).convertToNodeSpaceAR(worldPos); // localPos.y -= 50; // this.score.node.setPosition(localPos); // // // 每组动画播放完后延时 2 秒播放下一组 // this.scheduleOnce(() => { // this.playWinIconSpine(false, this.winningIconPos); // this.recycleAniNode(); // this.payAllLineOff(); // this.lineParentNode.removeAllChildren(); // playLineAnimations(lineIndex + 1, onComplete); // }, this.aniTime); // }; // let loop = () => { // playAllAnimations(() => { // playLineAnimations(1, () => { // // 循环播放 // loop(); // }); // }); // }; // loop(); // } // playAnimationAtPosition(posArr: number[]) { // posArr.forEach(pos => { // let position = this.iconPosArray[pos]; // let animNode = NodePoolManager.instance.getNodeFromPoolStatic('winEffect', this.winEffectPre); // animNode.parent = this.winEffectParent; // 将动画节点挂载到当前节点 // animNode.setPosition(position); // 设置位置 // }); // } // playWinIconSpine(bol: boolean, posArr: number[]) { // posArr.sort(); // posArr.forEach(pos => { // let icon = this.rollerManager.getIconNode(pos); // if (icon != null) { // let iconScp = icon.getComponent(Icon); // iconScp.playWinAni(bol); // } // }) // this.moveWinIconToLayer(posArr, bol); // } // moveWinIconToLayer(posArray: number[], bol: boolean) { // if (bol) { // posArray.forEach(pos => { // let iconNode = this.rollerManager.getIconNode(pos); // if (iconNode) { // iconNode.parent = this.iconLayer; // this.winIconNodeMap.set(pos, iconNode); // let worldPos = this.rollerManager.getIconWorldPosition(pos); // let localPos = this.iconLayer.getComponent(UITransform).convertToNodeSpaceAR(worldPos); // iconNode.setPosition(localPos); // } // }) // } else { // posArray.forEach(pos => { // let iconNode = this.winIconNodeMap.get(pos); // if (iconNode) { // iconNode.parent = this.rollerManager.getContentNode(pos); // this.winIconNodeMap.delete(pos); // let worldPos = this.rollerManager.getIconWorldPosition(pos); // let rollerContentNode = this.rollerManager.getContentNode(pos); // let localPos = rollerContentNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos); // iconNode.setPosition(localPos); // } // }) // } // } // // 画所有线 // drawLines() { // this.lineParentNode.removeAllChildren(); // this.drawLineData.forEach(lineIndex => { // this.drawOneLine(lineIndex); // }) // } // drawOneLine(index: number) { // let lineNode = NodePoolManager.instance.getNodeFromPoolStatic('lineNode', this.lineSpinePre); // this.lineParentNode.addChild(lineNode); // let spine = lineNode.getChildByName('spine').getComponent(sp.Skeleton); // spine.setAnimation(0, `${index}`, true); // } // stopAnimations() { // this.playWinIconSpine(false, this.winningIconPos); // this.playBoxAni(false); // this.winningIconPos = []; // this.hitBlockData = []; // this.payAllLineOff(); // this.recycleAniNode(); // this.unscheduleAllCallbacks(); // 停止所有定时任务 // } // recycleAniNode() { // while (this.winEffectParent.children.length > 0) { // let node = this.winEffectParent.children[0]; // NodePoolManager.instance.putNodeToPool('winEffect', node); // } // while (this.lineParentNode.children.length > 0) { // let node = this.lineParentNode.children[0]; // NodePoolManager.instance.putNodeToPool('lineNode', node); // } // } // onDestroy() { // this.stopAnimations(); // 确保销毁时停止动画 // } // // 加入非空判断 // playBoxAni(bol: boolean) { // if (this.hitBlockData.length == 0 || this.hitBlockData == null) return; // this.hitBlockData.forEach(hitBlock => { // this.playWinIconSpine(bol, [ICON_POSITION[hitBlock.Position]]); // }) // } // }