// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import JiaZai from "../../Script/JiaZai"; import LoadingCatAnimation from "../../Script/LoadingCatAnimation"; import Utils from "../../Script/module/Pay/Utils"; import NumberToImage from "../../Script/NumberToImage"; import { MiniGameSdk } from "../../Script/Sdk/MiniGameSdk"; const { ccclass, property } = cc._decorator; @ccclass export default class WinStreak extends cc.Component { @property(cc.SpriteAtlas) fontUI: cc.SpriteAtlas = null; @property(cc.SpriteAtlas) fontUI2: cc.SpriteAtlas = null; @property(cc.Node) content: cc.Node = null; //月卡按钮切换 @property(cc.Node) getBtn: cc.Node = null; public juwai = false; btn_Touch: boolean = false; private rainbowStars: cc.Node[] = []; private starTime = 0; private avatarFrame: cc.SpriteFrame = null; onLoad() { this.btn_Touch = true; } start() { // this.init(); } init() { const progress = this.node.getChildByName("progress"); if (cc.fx.GameConfig.usesRainbowWinStreakUI() && progress) { const count = Math.max(0, Math.min(10, cc.fx.GameConfig.GM_INFO.winStreak)); this.node.getChildByName("hammer").active = false; progress.getComponent(cc.Sprite).fillRange = count / 10; if (this.fontUI2) this.numberToImageNodes3(count, 0, 5, "", this.node.getChildByName("number"), false); else this.numberToImageNodes2(count, 10, 5, "", this.node.getChildByName("number"), true); this.initRainbowMarkers(count, progress); return; } if (cc.fx.GameConfig.GM_INFO.winStreak > 0) { let hammer = this.node.getChildByName("hammer").children; let count = cc.fx.GameConfig.GM_INFO.winStreak; let time = 0.1; if (count > 5) { time = 0.05; } if (count > 10) { count = 10; } for (let i = 0; i < count; i++) { if (i < 10) { hammer[i].active = true; hammer[i].scaleX = hammer[i].scaleY = 0; cc.tween(hammer[i]) .delay(i * time) .to(0.2, { scaleX: 1.15, scaleY: 1.15 }) // 快速放大到0.7 .to(0.1, { scaleX: 0.85, scaleY: 0.85 }) // 突然缩小制造弹性感 .to(0.1, { scaleX: 1.1, scaleY: 1.1 }) // 再次弹起到0.6 .to(0.1, { scaleX: 0.9, scaleY: 0.9 }) // 最终稳定到0.5 .to(0.05, { scaleX: 1.05, scaleY: 1.05 }) // X轴抖动效果 .to(0.05, { scaleX: 0.85, scaleY: 0.85 }) // Y轴抖动效果 .to(0.1, { scaleX: 0.95, scaleY: 0.95 }) // 恢复最终比例 .start(); } } } let winStreakCount = cc.fx.GameConfig.GM_INFO.winStreak; if (winStreakCount >= 10) { winStreakCount = 10; } this.numberToImageNodes2(winStreakCount, 10, 5, "", this.node.getChildByName("number"), true); } private initRainbowMarkers(count: number, progress: cc.Node) { const reward = this.node.getChildByName("reward"); const avatar = this.node.getChildByName("avatar"); const milestone = count > 0 ? this.node.getChildByName("hammer").getChildByName(String(count)) : progress; if (milestone) { const position = milestone.convertToWorldSpaceAR(cc.v2()); [reward, avatar].forEach(node => { if (node) node.x = node.parent.convertToNodeSpaceAR(position).x; }); } this.rainbowStars = reward ? reward.children.filter(node => node.name === "star") : []; this.starTime = 0; this.update(0); const mask = avatar && avatar.getChildByName("mask"); if (!mask) return; const icon = mask.getChildByName("icon"); const spine = mask.getChildByName("sp"); const selected = cc.fx.GameConfig.GM_INFO.useravatarIcon || "icon_0"; const remote = selected.length > 10; icon.active = remote; spine.active = !remote; if (remote) { icon.getComponent(cc.Sprite).spriteFrame = null; cc.assetManager.loadRemote(selected, { ext: '.png' }, (err, texture: cc.Texture2D) => { if (err || !texture || !cc.isValid(icon, true) || cc.fx.GameConfig.GM_INFO.useravatarIcon !== selected) return; if (!this.avatarFrame) this.avatarFrame = new cc.SpriteFrame(texture); else this.avatarFrame.setTexture(texture); icon.getComponent(cc.Sprite).spriteFrame = this.avatarFrame; }); } else { cc.fx.GameTool.loadSpineSimple(spine, cc.fx.GameTool.getActionName(selected)); } } update(dt: number) { if (!this.rainbowStars.length) return; this.starTime = (this.starTime + dt) % 1.8; this.rainbowStars.forEach((star, index) => { const phase = (this.starTime / 1.8 - index / this.rainbowStars.length) * Math.PI * 2; star.opacity = 40 + (Math.cos(phase) + 1) * 107.5; }); } onDestroy() { if (this.avatarFrame) this.avatarFrame.destroy(); } //入场动画 setAction() { } setReward(id) { } closeWinStreak() { if (this.node) this.node.active = false; } openLoad() { LoadingCatAnimation.play(this.node.getChildByName("Loading")); } openConfirmBox() { this.closeLoad(); this.node.getChildByName("ConfirmBox").active = true; } closeConfirmBox() { this.node.getChildByName("ConfirmBox").active = false; } closeLoad() { LoadingCatAnimation.stop(this.node.getChildByName("Loading")); } //点击去完成 clickBtn(event, data) { if (this.node) this.node.active = false; const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 const jiazaiComp = jiazaiNode.getComponent(JiaZai); if (jiazaiComp) { jiazaiComp.startGame(); } } numberToImageNodes2(number, width, posX, name, targetNode: cc.Node, right: boolean = false) { const numStr = number.toString(); let cha = 0; if (number > 99) cha = -posX else if (number < 10) cha = posX if (targetNode.children.length > 0) targetNode.removeAllChildren(); const digitNodes: cc.Node[] = []; for (let i = 0; i < numStr.length; i++) { let digit = parseInt(numStr[i], 10); const node = new cc.Node(); const sprite = node.addComponent(cc.Sprite); if (numStr[i] == ":") digit = 10; sprite.spriteFrame = this.fontUI._spriteFrames[name + digit + ""]; digitNodes.push(node); } // 计算总宽度 // const totalWidth = (numStr.length - 1) * width + (digitNodes[0]?.width || 0); // 计算总宽度,累加每个节点的宽度和间距 let totalWidth = 0; for (let i = 0; i < digitNodes.length; i++) { totalWidth += digitNodes[i].width; if (i < digitNodes.length - 1) { totalWidth += width; } } if (right) { // 新右对齐逻辑:从右向左排列 let currentX = 0; // 最右侧起点 for (let i = digitNodes.length - 1; i >= 0; i--) { const node = digitNodes[i]; node.x = currentX - node.width; currentX -= (node.width + width); // 向左累加宽度和间距 if (targetNode) node.parent = targetNode; } } else { let currentX = cha; for (let i = 0; i < digitNodes.length; i++) { const node = digitNodes[i]; node.x = currentX; currentX += node.width + width; if (targetNode) node.parent = targetNode; } } } numberToImageNodes3(number, width, posX, name, targetNode: cc.Node, right: boolean = false) { const numStr = number.toString(); let cha = 0; if (number > 99) cha = -posX else if (number < 10) cha = posX if (targetNode.children.length > 0) targetNode.removeAllChildren(); const digitNodes: cc.Node[] = []; for (let i = 0; i < numStr.length; i++) { let digit = parseInt(numStr[i], 10); const node = new cc.Node(); const sprite = node.addComponent(cc.Sprite); if (numStr[i] == ":") digit = 10; sprite.spriteFrame = this.fontUI2._spriteFrames[name + digit + ""]; digitNodes.push(node); } // 计算总宽度 // const totalWidth = (numStr.length - 1) * width + (digitNodes[0]?.width || 0); // 计算总宽度,累加每个节点的宽度和间距 let totalWidth = 0; for (let i = 0; i < digitNodes.length; i++) { totalWidth += digitNodes[i].width; if (i < digitNodes.length - 1) { totalWidth += width; } } if (right) { // 新右对齐逻辑:从右向左排列 let currentX = 0; // 最右侧起点 for (let i = digitNodes.length - 1; i >= 0; i--) { const node = digitNodes[i]; node.x = currentX - node.width; currentX -= (node.width + width); // 向左累加宽度和间距 if (targetNode) node.parent = targetNode; } } else { let currentX = cha; for (let i = 0; i < digitNodes.length; i++) { const node = digitNodes[i]; node.x = currentX; currentX += node.width + width; if (targetNode) node.parent = targetNode; } } } }