From ad9c1814d84ce4578a311913af1294154feec5be Mon Sep 17 00:00:00 2001 From: "YZ\\249929363" <249929363@qq.com> Date: Thu, 17 Jul 2025 18:54:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/JiaZai.ts | 18 +- assets/Script/NumberToImage.ts | 73 ++++ assets/Script/Reward.ts | 17 +- assets/Script/module/Pay/Utils.ts | 3 +- assets/Script/module/Tool/GameTool.ts | 9 +- assets/shop/prefab/rewardNode.prefab | 468 +++++++++++++++++++++++++- assets/shop/prefab/shop.prefab | 6 +- 7 files changed, 565 insertions(+), 29 deletions(-) diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index 79cdfc1..06fbce5 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -101,16 +101,16 @@ export default class JiaZai extends cc.Component { 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 }, - // ] + let data = [ + { type: "coin", count: 125294 }, + { type: "coin", count: 7498 }, + { type: "freeze", count: 2 }, + { type: "hammer", count: 2 }, + { type: "magic", count: 2 }, + { type: "infinite_health", count: 1800 * 4 }, + ] - // this.openRewardWindow(data); + this.openRewardWindow(data); this.getOrder(); }); }); diff --git a/assets/Script/NumberToImage.ts b/assets/Script/NumberToImage.ts index 8383afc..1aa7668 100644 --- a/assets/Script/NumberToImage.ts +++ b/assets/Script/NumberToImage.ts @@ -106,6 +106,79 @@ export default class NumberToImage extends cc.Component { } + + static getTimeMargin2(number, width, name, targetNode: cc.Node, middle: boolean = false) { + let timeArr = []; + let total = 0; + total = number; + let hour = 0; + hour = parseInt((total / 3600) + "");//计算整数小时数 + let afterHour = total - hour * 60 * 60;//取得算出小时数后剩余的秒数 + let min = parseInt((afterHour / 60) + "");//计算整数分 + let m = "" + min; + + if (min < 10) m = "0" + min; + let afterMin = total - hour * 60 * 60 - min * 60;//取得算出分后剩余的秒数 + let miao = afterMin + ""; + + if (afterMin < 10) miao = "0" + afterMin; + // 将小时部分格式化为两位数 + let h = "" + hour; + if (hour < 10) h = "0" + hour; + + let result = m + miao; + // 拼接小时、分、秒 + if (hour > 0) + result = h + m + miao; + for (let i = 0; i < result.length; i++) { + const digit = parseInt(result[i], 10); + timeArr.push(digit); + } + + const digitNodes: cc.Node[] = []; + + if (targetNode.children.length > 0) { + for (let i = 0; i < targetNode.children.length; i++) { + const node = targetNode.children[i]; + const sprite = node.getComponent(cc.Sprite); + sprite.spriteFrame = this.font._spriteFrames[name + timeArr[i] + ""]; + digitNodes.push(node); + } + } + else { + for (let i = 0; i < timeArr.length; i++) { + const node = new cc.Node(); + const sprite = node.addComponent(cc.Sprite); + const digit = timeArr[i]; + sprite.spriteFrame = this.font._spriteFrames[name + digit + ""]; + digitNodes.push(node); + } + } + + // 计算总宽度 + const totalWidth = (timeArr.length - 1) * width + (digitNodes[0]?.width || 0); + + if (middle) { + // 计算居中的起始位置 + const startX = -totalWidth / 2; + for (let i = 0; i < digitNodes.length; i++) { + const node = digitNodes[i]; + node.x = startX + i * width; + if (i > 1) node.x += 20; + if (i > 3) node.x += 20; + node.parent = targetNode; + } + } else { + for (let i = 0; i < digitNodes.length; i++) { + const node = digitNodes[i]; + node.x = i * width; + if (i > 1) node.x += 20; + if (i > 3) node.x += 20; + node.parent = targetNode; + } + } + } + // static calculateAndConvert(num1: number, num2: number, operator: '+' | '-' | '*' | '/', spriteFrames: SpriteFrame[]): Node[] { // let result: number; // switch (operator) { diff --git a/assets/Script/Reward.ts b/assets/Script/Reward.ts index 5df322c..395d29a 100644 --- a/assets/Script/Reward.ts +++ b/assets/Script/Reward.ts @@ -119,6 +119,11 @@ export default class Reward extends cc.Component { let label = rewardNode.getChildByName('label') if (data[index].type == 'coin') NumberToImage.numberToImageNodes(data[index].count, 45, 5, "coins", label, true); + else if (data[index].type == 'infinite_health') { + NumberToImage.getTimeMargin2(data[index].count, 45, "coins", label, true); + if (data[index].count > 3600) label.x -= 10; + rewardNode.getChildByName('xnode').opacity = 1; + } else { NumberToImage.numberToImageNodes(data[index].count, 50, 15, "coins", label, true); rewardNode.getChildByName('xnode').opacity = 0; @@ -133,7 +138,13 @@ export default class Reward extends cc.Component { .delay(0.1) .call(() => { rewardNode.getChildByName('label').active = true; - if (rewardNode.getChildByName('xnode').opacity != 255) { + if (rewardNode.getChildByName('xnode').opacity == 1) { + rewardNode.getChildByName('xnode').opacity = 0; + let name = "icon1"; + if (rewardNode.getChildByName('label').children.length > 4) name = "icon2"; + iconNode.getChildByName('infinite_health').getChildByName(name).active = true; + } + else if (rewardNode.getChildByName('xnode').opacity != 255) { rewardNode.getChildByName('xnode').active = true; rewardNode.getChildByName('xnode').opacity = 255; } @@ -142,13 +153,13 @@ export default class Reward extends cc.Component { } index++; - if (index == data.length - 1) { + if (index == data.length) { setTimeout(() => { this.actionOver = true; }, 500); } - if (index < data.length - 1) { + if (index < data.length) { const nextCol = col + 1; if (nextCol < rowCounts[row]) { createNodeWithDelay(row, nextCol); diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 9bd2781..84e4f10 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -713,7 +713,7 @@ export default class Utils { } //上传关卡等级信息 - static setUserHealth(health, callBack) { + static setUserHealth(timestamp, callBack) { if (typeof wx !== 'undefined' && wx !== null) { let uid = cc.fx.StorageMessage.getStorage("uid"); //旧的读取数据设置数据方法,以强联网为主 @@ -724,6 +724,7 @@ export default class Utils { uid: cc.fx.GameConfig.GM_INFO.uid, action: 'save', healthAmount: cc.fx.GameConfig.GM_INFO.hp, + timestamp: timestamp } Utils.POST("userHealth", setData, res => { console.log("获得userHealth数据:", res); diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index 3e104cd..74fd425 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -604,7 +604,10 @@ var GameTool = { // else MiniGameSdk.API.showToast("体力值恢复"); const timestamp = Date.now(); - let healthInfo = {} + let healthInfo = { + "health": cc.fx.GameConfig.GM_INFO.hp, + "timestamp": timestamp + } //如果消耗之前不是满体力,说明已经在恢复期,并不用修改时间 if (health < 0 && cc.fx.GameConfig.GM_INFO.hp != 4) { @@ -631,7 +634,7 @@ var GameTool = { data: { action: 'save', healthAmount: cc.fx.GameConfig.GM_INFO.hp, - timestamp: timestamp + timestamp: healthInfo.timestamp }, success: res => { if (callback) { @@ -648,7 +651,7 @@ var GameTool = { }) //laf云函数 - Utils.setUserHealth(health, (data) => { + Utils.setUserHealth(healthInfo.timestamp, (data) => { }) } }, diff --git a/assets/shop/prefab/rewardNode.prefab b/assets/shop/prefab/rewardNode.prefab index 3cfa13e..59fab0b 100644 --- a/assets/shop/prefab/rewardNode.prefab +++ b/assets/shop/prefab/rewardNode.prefab @@ -24,16 +24,16 @@ "__id__": 5 }, { - "__id__": 19 + "__id__": 31 }, { - "__id__": 21 + "__id__": 33 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 24 + "__id__": 36 }, "_opacity": 255, "_color": { @@ -218,12 +218,15 @@ }, { "__id__": 15 + }, + { + "__id__": 18 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 18 + "__id__": 30 }, "_opacity": 255, "_color": { @@ -254,8 +257,8 @@ 0, 0, 1, - 0.1, - 0.1, + 1, + 1, 1 ] }, @@ -708,6 +711,451 @@ "fileId": "2cfv2rf4ZHfJ7M7Sfctb2n", "sync": false }, + { + "__type__": "cc.Node", + "_name": "infinite_health", + "_objFlags": 0, + "_parent": { + "__id__": 5 + }, + "_children": [ + { + "__id__": 19 + }, + { + "__id__": 22 + } + ], + "_active": false, + "_components": [ + { + "__id__": 28 + } + ], + "_prefab": { + "__id__": 29 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 137, + "height": 121 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 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": "icon1", + "_objFlags": 0, + "_parent": { + "__id__": 18 + }, + "_children": [], + "_active": false, + "_components": [ + { + "__id__": 20 + } + ], + "_prefab": { + "__id__": 21 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 40, + "height": 56 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 11.361, + -125.613, + 0, + 0, + 0, + 0, + 1, + 0.7, + 0.7, + 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__": 19 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "ff947612-64d1-4ad2-add0-b7d8fbd5df4f" + }, + "_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": "3e7r+fwbFI7Y1WOygYANcq", + "sync": false + }, + { + "__type__": "cc.Node", + "_name": "icon2", + "_objFlags": 0, + "_parent": { + "__id__": 18 + }, + "_children": [ + { + "__id__": 23 + } + ], + "_active": false, + "_components": [ + { + "__id__": 26 + } + ], + "_prefab": { + "__id__": 27 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 40, + "height": 56 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + -37.185, + -125.613, + 0, + 0, + 0, + 0, + 1, + 0.7, + 0.7, + 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": "icon2", + "_objFlags": 0, + "_parent": { + "__id__": 22 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 24 + } + ], + "_prefab": { + "__id__": 25 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 40, + "height": 56 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 128.22, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 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.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 23 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "ff947612-64d1-4ad2-add0-b7d8fbd5df4f" + }, + "_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": "2fibc7/3VM9rg71+aW4urO", + "sync": false + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 22 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "ff947612-64d1-4ad2-add0-b7d8fbd5df4f" + }, + "_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": "33/wdzCEVKY7xMAYSF3jg2", + "sync": false + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 18 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "591a3b58-c345-4c24-84a2-f4faa8acdda1" + }, + "_type": 0, + "_sizeMode": 1, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "c8zThuucNB3oD49yFreXPz", + "sync": false + }, { "__type__": "cc.PrefabInfo", "root": { @@ -730,7 +1178,7 @@ "_active": false, "_components": [], "_prefab": { - "__id__": 20 + "__id__": 32 }, "_opacity": 255, "_color": { @@ -801,11 +1249,11 @@ "_active": false, "_components": [ { - "__id__": 22 + "__id__": 34 } ], "_prefab": { - "__id__": 23 + "__id__": 35 }, "_opacity": 255, "_color": { @@ -859,7 +1307,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 21 + "__id__": 33 }, "_enabled": true, "_materials": [ diff --git a/assets/shop/prefab/shop.prefab b/assets/shop/prefab/shop.prefab index 6be761c..d5f9b6c 100644 --- a/assets/shop/prefab/shop.prefab +++ b/assets/shop/prefab/shop.prefab @@ -8995,7 +8995,7 @@ "component": "", "_componentId": "48bfeZuYFZE2qmgxbW2IigB", "handler": "buyProduct", - "customEventData": "" + "customEventData": "unlimited_health_bundle_1" }, { "__type__": "cc.PrefabInfo", @@ -9528,7 +9528,7 @@ "component": "", "_componentId": "48bfeZuYFZE2qmgxbW2IigB", "handler": "buyProduct", - "customEventData": "" + "customEventData": "unlimited_health_bundle_2" }, { "__type__": "cc.PrefabInfo", @@ -10173,7 +10173,7 @@ "component": "", "_componentId": "48bfeZuYFZE2qmgxbW2IigB", "handler": "buyProduct", - "customEventData": "" + "customEventData": "unlimited_health_bundle_3" }, { "__type__": "cc.PrefabInfo",