From 5b04762c747e3b0007a484c155b2d25b92e4d115 Mon Sep 17 00:00:00 2001 From: "YZ\\249929363" <249929363@qq.com> Date: Thu, 17 Jul 2025 10:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8E=B7=E5=BE=97=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/JiaZai.ts | 52 ++- assets/Script/Map.ts | 1 + assets/Script/Reward.ts | 150 +++++++- assets/UI/UI/pop/rankui.png.meta | 2 +- .../prefab/RewardWindow.prefab} | 32 +- .../prefab/RewardWindow.prefab.meta} | 0 .../pop => shop/prefab}/rewardNode.prefab | 355 +++++++++++++++--- .../prefab}/rewardNode.prefab.meta | 0 assets/shop/prefab/shop.prefab | 10 +- 9 files changed, 519 insertions(+), 83 deletions(-) rename assets/{prefab/pop/Rward.prefab => shop/prefab/RewardWindow.prefab} (98%) rename assets/{prefab/pop/Rward.prefab.meta => shop/prefab/RewardWindow.prefab.meta} (100%) rename assets/{prefab/pop => shop/prefab}/rewardNode.prefab (68%) rename assets/{prefab/pop => shop/prefab}/rewardNode.prefab.meta (100%) diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index f4e1cfa..79cdfc1 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -95,18 +95,26 @@ export default class JiaZai extends cc.Component { } JiaZai.cachedShopPrefab = prefab; }); + bundle.load('prefab/RewardWindow', cc.Prefab, (err: Error, prefab: cc.Prefab) => { + if (err) { + cc.error(err.message || err); + return; + } + JiaZai.cachedRewardPrefab = prefab; + // let data = [ + // { type: "coin", count: 125294 }, + // { type: "coin", count: 7498 }, + // { type: "freeze", count: 2 }, + // { type: "hammer", count: 2 }, + // { type: "magic", count: 2 }, + // { type: "coin", count: 250 }, + // ] + + // this.openRewardWindow(data); + this.getOrder(); + }); }); } - // 预加载 reward 预制体 - if (!JiaZai.cachedRewardPrefab) { - cc.assetManager.loadBundle('reward', (err: Error, bundle: cc.AssetManager.Bundle) => { - if (err) { - cc.error(err.message || err); - return; - } - }) - } - if (cc.fx.GameConfig.GM_INFO.first) { //console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid); @@ -142,11 +150,8 @@ export default class JiaZai extends cc.Component { }, 1000); } - //console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen); AudioManager._instance.playMusicGame(); - - this.getOrder(); } start() { @@ -296,6 +301,7 @@ export default class JiaZai extends cc.Component { uploadToCloud(level: number) { if (typeof wx !== 'undefined') { + //@ts-ignore wx.setUserCloudStorage({ KVDataList: [ { key: 'level', value: String(level) } @@ -397,6 +403,26 @@ export default class JiaZai extends cc.Component { // //console.log("shopNode parent:", this.shopNode.parent); } + openRewardWindow(data) { + if (!JiaZai.cachedRewardPrefab) { + cc.error('Reward prefab is not loaded yet.'); + return; + } + if (!this.RewardNode) { + // 第一次使用,创建节点 + this.RewardNode = cc.instantiate(JiaZai.cachedRewardPrefab); + this.node.addChild(this.RewardNode); + this.RewardNode.getComponent("Reward").init(data); + } + else { + this.RewardNode.destroy(); + this.RewardNode = null; + this.RewardNode = cc.instantiate(JiaZai.cachedRewardPrefab); + this.node.addChild(this.RewardNode); + this.RewardNode.getComponent("RewardWindow").init(data); + } + } + // 关闭商店 closeShop() { if (this.shopNode) { diff --git a/assets/Script/Map.ts b/assets/Script/Map.ts index ef8686f..79eb597 100644 --- a/assets/Script/Map.ts +++ b/assets/Script/Map.ts @@ -1582,6 +1582,7 @@ export default class MapConroler extends cc.Component { } uploadToCloud(level: number) { if (typeof wx !== 'undefined') { + //@ts-ignore wx.setUserCloudStorage({ KVDataList: [ { key: 'level', value: String(level) } diff --git a/assets/Script/Reward.ts b/assets/Script/Reward.ts index 03b6be8..5df322c 100644 --- a/assets/Script/Reward.ts +++ b/assets/Script/Reward.ts @@ -1,3 +1,4 @@ +import NumberToImage from "./NumberToImage"; const { ccclass, property, requireComponent } = cc._decorator; @@ -8,12 +9,159 @@ export default class Reward extends cc.Component { @property(cc.Prefab) rewardNode: cc.Prefab = null; + actionOver: boolean; + speedTime: number = 50; + private originalTimeScale: number = 1; // 记录原始时间缩放比例 onLoad() { - + // 为节点添加点击事件监听器 + this.speedTime = 50; } start() { + // ... 已有代码 ... + this.node.on(cc.Node.EventType.TOUCH_END, this.onNodeClick, this); + } + + /** + * 节点点击事件处理函数 + */ + onNodeClick() { + console.log('Reward 节点被点击了', this.actionOver); + // 这里可以添加点击后的具体逻辑 + if (this.actionOver == true) { + this.node.destroy(); + } + else { + // 游戏整体加速 + this.speedUpGame(); + } + } + + + speedUpGame() { + this.speedTime = 0; + this.originalTimeScale = cc.director.getScheduler().getTimeScale(); // 记录原始时间缩放比例 + cc.director.getScheduler().setTimeScale(10); // 加速到 2 倍速 + // 在奖励节点创建完成后恢复正常速度 + const checkCompletion = () => { + if (this.actionOver) { + cc.director.getScheduler().setTimeScale(this.originalTimeScale); // 恢复原始时间缩放比例 + } else { + setTimeout(checkCompletion, 50); // 每隔 100 毫秒检查一次 + } + }; + checkCompletion(); + } + + /** + * 初始化 + * @param data 数据 + */ + init(data) { + this.actionOver = false; + const num = Math.min(data.length, 9); // 确保 num 不超过 9 + const spacing = 10; // 间隔,默认 10 + if (this.rewardNode && num > 0) { + // 获取单个 rewardNode 的宽度和高度 + const tempNode = cc.instantiate(this.rewardNode); + const nodeWidth = tempNode.width; + const nodeHeight = tempNode.height; + tempNode.destroy(); + + // 定义每一行的节点数量 + const rowCounts: number[] = []; + if (num <= 3) { + rowCounts.push(num); + } else if (num === 4) { + rowCounts.push(2, 2); + } else if (num === 5) { + rowCounts.push(3, 2); + } else if (num === 6) { + rowCounts.push(3, 3); + } else if (num === 7) { + rowCounts.push(3, 3, 1); + } else if (num === 8) { + rowCounts.push(3, 3, 2); + } else if (num === 9) { + rowCounts.push(3, 3, 3); + } + + // 计算总高度 + const rows = rowCounts.length; + const totalHeight = (nodeHeight * rows) + (spacing * (rows - 1)); + + // 计算起始位置的 y 坐标 + const startY = totalHeight / 2 - nodeHeight / 2; + + let index = 0; + const createNodeWithDelay = (row: number, col: number) => { + setTimeout(() => { + const rewardNode = cc.instantiate(this.rewardNode); + rewardNode.parent = this.node; + // 计算当前行的总宽度 + let startX = 0; + if (row === 0) { + const totalWidth = (nodeWidth * rowCounts[row]) + (spacing * (rowCounts[row] - 1)); + startX = -totalWidth / 2 + nodeWidth / 2; + } else { + startX = -((nodeWidth * 3) + (spacing * 2)) / 2 + nodeWidth / 2; + } + // 计算每个节点的 x 和 y 位置 + const xPos = startX + (col * (nodeWidth + spacing)); + const yPos = startY - (row * (nodeHeight + spacing)); + rewardNode.setPosition(xPos, yPos); + // 查找 rewardNode 的子节点 icon + const iconNode = rewardNode.getChildByName('icon'); + iconNode.getChildByName(data[index].type).active = true; + let label = rewardNode.getChildByName('label') + if (data[index].type == 'coin') + NumberToImage.numberToImageNodes(data[index].count, 45, 5, "coins", label, true); + else { + NumberToImage.numberToImageNodes(data[index].count, 50, 15, "coins", label, true); + rewardNode.getChildByName('xnode').opacity = 0; + label.x += 20; + } + rewardNode.getChildByName('label').active = false; + if (iconNode) { + cc.tween(iconNode) + .to(0.2, { scale: 1.1 }) + .to(0.1, { scale: 0.9 }) + .to(0.05, { scale: 1 }) + .delay(0.1) + .call(() => { + rewardNode.getChildByName('label').active = true; + if (rewardNode.getChildByName('xnode').opacity != 255) { + rewardNode.getChildByName('xnode').active = true; + rewardNode.getChildByName('xnode').opacity = 255; + } + }) + .start(); + } + + index++; + if (index == data.length - 1) { + setTimeout(() => { + this.actionOver = true; + }, 500); + + } + if (index < data.length - 1) { + const nextCol = col + 1; + if (nextCol < rowCounts[row]) { + createNodeWithDelay(row, nextCol); + } else { + createNodeWithDelay(row + 1, 0); + } + } + }, index * this.speedTime); // 每个节点间隔 0.1 秒 + }; + createNodeWithDelay(0, 0); + } + } + + + } diff --git a/assets/UI/UI/pop/rankui.png.meta b/assets/UI/UI/pop/rankui.png.meta index 9a6d74d..24e1eef 100644 --- a/assets/UI/UI/pop/rankui.png.meta +++ b/assets/UI/UI/pop/rankui.png.meta @@ -8,7 +8,7 @@ "premultiplyAlpha": false, "genMipmaps": false, "packable": true, - "width": 1790, + "width": 1852, "height": 1765, "platformSettings": {}, "subMetas": {} diff --git a/assets/prefab/pop/Rward.prefab b/assets/shop/prefab/RewardWindow.prefab similarity index 98% rename from assets/prefab/pop/Rward.prefab rename to assets/shop/prefab/RewardWindow.prefab index e5f54cb..916981e 100644 --- a/assets/prefab/pop/Rward.prefab +++ b/assets/shop/prefab/RewardWindow.prefab @@ -23,6 +23,9 @@ ], "_active": true, "_components": [ + { + "__id__": 6 + }, { "__id__": 7 }, @@ -55,8 +58,8 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - 0, - 0, + 540, + 960, 0, 0, 0, @@ -95,13 +98,10 @@ }, { "__id__": 4 - }, - { - "__id__": 5 } ], "_prefab": { - "__id__": 6 + "__id__": 5 }, "_opacity": 150, "_color": { @@ -182,16 +182,6 @@ "_atlas": null, "_id": "" }, - { - "__type__": "cc.BlockInputEvents", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 2 - }, - "_enabled": true, - "_id": "" - }, { "__type__": "cc.Widget", "_name": "", @@ -270,6 +260,16 @@ }, "_id": "" }, + { + "__type__": "cc.BlockInputEvents", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "_id": "" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/prefab/pop/Rward.prefab.meta b/assets/shop/prefab/RewardWindow.prefab.meta similarity index 100% rename from assets/prefab/pop/Rward.prefab.meta rename to assets/shop/prefab/RewardWindow.prefab.meta diff --git a/assets/prefab/pop/rewardNode.prefab b/assets/shop/prefab/rewardNode.prefab similarity index 68% rename from assets/prefab/pop/rewardNode.prefab rename to assets/shop/prefab/rewardNode.prefab index 6f8db03..3cfa13e 100644 --- a/assets/prefab/pop/rewardNode.prefab +++ b/assets/shop/prefab/rewardNode.prefab @@ -24,19 +24,16 @@ "__id__": 5 }, { - "__id__": 8 + "__id__": 19 }, { - "__id__": 11 - }, - { - "__id__": 14 + "__id__": 21 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 17 + "__id__": 24 }, "_opacity": 255, "_color": { @@ -48,8 +45,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 0, - "height": 0 + "width": 360, + "height": 360 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -167,7 +164,7 @@ "defaultAnimation": "animation", "_preCacheMode": 0, "_cacheMode": 0, - "loop": true, + "loop": false, "premultipliedAlpha": false, "timeScale": 1, "_accTime": 0, @@ -178,7 +175,7 @@ "_animationName": "animation", "_animationQueue": [], "_headAniInfo": null, - "_playTimes": 0, + "_playTimes": 1, "_isAniComplete": true, "_N$skeletonData": { "__uuid__": "62ae7eaa-1552-4465-9696-f6220311642a" @@ -204,20 +201,93 @@ }, { "__type__": "cc.Node", - "_name": "coin", + "_name": "icon", "_objFlags": 0, "_parent": { "__id__": 1 }, - "_children": [], - "_active": true, - "_components": [ + "_children": [ { "__id__": 6 + }, + { + "__id__": 9 + }, + { + "__id__": 12 + }, + { + "__id__": 15 + } + ], + "_active": true, + "_components": [], + "_prefab": { + "__id__": 18 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 0 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0.1, + 0.1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "coin", + "_objFlags": 0, + "_parent": { + "__id__": 5 + }, + "_children": [], + "_active": false, + "_components": [ + { + "__id__": 7 } ], "_prefab": { - "__id__": 7 + "__id__": 8 }, "_opacity": 255, "_color": { @@ -248,9 +318,9 @@ 0, 0, 1, - 1.5, - 1.5, - 1 + 1.6, + 1.6, + 10 ] }, "_eulerAngles": { @@ -271,7 +341,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 5 + "__id__": 6 }, "_enabled": true, "_materials": [ @@ -308,7 +378,7 @@ "asset": { "__id__": 0 }, - "fileId": "40yFZaE/dBDrxorfDNFUMC", + "fileId": "315emM+4FE3ahxG+gJrlde", "sync": false }, { @@ -316,17 +386,17 @@ "_name": "freeze", "_objFlags": 0, "_parent": { - "__id__": 1 + "__id__": 5 }, "_children": [], "_active": false, "_components": [ { - "__id__": 9 + "__id__": 10 } ], "_prefab": { - "__id__": 10 + "__id__": 11 }, "_opacity": 255, "_color": { @@ -351,15 +421,15 @@ "ctor": "Float64Array", "array": [ 0, - 0, + 22.703, 0, 0, 0, 0, 1, - 0.6, - 0.6, - 1 + 0.7, + 0.7, + 6 ] }, "_eulerAngles": { @@ -380,7 +450,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 8 + "__id__": 9 }, "_enabled": true, "_materials": [ @@ -417,7 +487,7 @@ "asset": { "__id__": 0 }, - "fileId": "c5266WhWxF3plZF/PuHtKD", + "fileId": "3crJ0GPJBL/rvs/pHPjNL1", "sync": false }, { @@ -425,17 +495,17 @@ "_name": "hammer", "_objFlags": 0, "_parent": { - "__id__": 1 + "__id__": 5 }, "_children": [], "_active": false, "_components": [ { - "__id__": 12 + "__id__": 13 } ], "_prefab": { - "__id__": 13 + "__id__": 14 }, "_opacity": 255, "_color": { @@ -466,9 +536,9 @@ 0, 0, 1, - 0.6, - 0.6, - 1 + 0.7, + 0.7, + 6 ] }, "_eulerAngles": { @@ -489,7 +559,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 11 + "__id__": 12 }, "_enabled": true, "_materials": [ @@ -526,7 +596,7 @@ "asset": { "__id__": 0 }, - "fileId": "72MartNEJAL6ekj/G4vmuw", + "fileId": "68PN+eHZ5Bbo8mITd+YvXp", "sync": false }, { @@ -534,17 +604,17 @@ "_name": "magic", "_objFlags": 0, "_parent": { - "__id__": 1 + "__id__": 5 }, "_children": [], "_active": false, "_components": [ { - "__id__": 15 + "__id__": 16 } ], "_prefab": { - "__id__": 16 + "__id__": 17 }, "_opacity": 255, "_color": { @@ -568,16 +638,16 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - 5.527, - -7.6, + 6.895, + -3.438, 0, 0, 0, 0, 1, - 0.6, - 0.6, - 1 + 0.7, + 0.7, + 6 ] }, "_eulerAngles": { @@ -598,7 +668,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 14 + "__id__": 15 }, "_enabled": true, "_materials": [ @@ -635,7 +705,198 @@ "asset": { "__id__": 0 }, - "fileId": "12il4hk6JFpoeVFTlRc+fT", + "fileId": "2cfv2rf4ZHfJ7M7Sfctb2n", + "sync": false + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "4ecEJ6eatJpqbvSnXz4AeB", + "sync": false + }, + { + "__type__": "cc.Node", + "_name": "label", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": false, + "_components": [], + "_prefab": { + "__id__": 20 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 88.98, + "height": 50.4 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 20, + -121.815, + 0, + 0, + 0, + 0, + 1, + 0.8, + 0.8, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "7aXb81olxIzp8lpa61lOZY", + "sync": false + }, + { + "__type__": "cc.Node", + "_name": "xnode", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": false, + "_components": [ + { + "__id__": 22 + } + ], + "_prefab": { + "__id__": 23 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 43, + "height": 49 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + -19.101, + -121.815, + 0, + 0, + 0, + 0, + 1, + 0.8, + 0.8, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 21 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "ee1f756f-b070-44b1-a415-4809b2634490" + }, + "_type": 0, + "_sizeMode": 1, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": { + "__uuid__": "fa9a438e-1f24-47fe-bbcd-b75abcff2ea8" + }, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "7cGPLzslJHCaN+gsEC5eUm", "sync": false }, { diff --git a/assets/prefab/pop/rewardNode.prefab.meta b/assets/shop/prefab/rewardNode.prefab.meta similarity index 100% rename from assets/prefab/pop/rewardNode.prefab.meta rename to assets/shop/prefab/rewardNode.prefab.meta diff --git a/assets/shop/prefab/shop.prefab b/assets/shop/prefab/shop.prefab index 185ab7e..13d900f 100644 --- a/assets/shop/prefab/shop.prefab +++ b/assets/shop/prefab/shop.prefab @@ -4626,7 +4626,7 @@ "__id__": 125 } ], - "_active": false, + "_active": true, "_components": [ { "__id__": 128 @@ -4844,7 +4844,7 @@ "__id__": 18 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 131 @@ -4951,7 +4951,7 @@ "__id__": 18 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 134 @@ -5058,7 +5058,7 @@ "__id__": 18 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 137 @@ -5241,7 +5241,7 @@ "__id__": 249 } ], - "_active": false, + "_active": true, "_components": [], "_prefab": { "__id__": 260