From dda758bc4c09cc2fa089136e6964b4c6eaac0579 Mon Sep 17 00:00:00 2001 From: "YZ\\249929363" <249929363@qq.com> Date: Thu, 3 Jul 2025 17:46:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=AD=E4=B9=B0=E4=BD=93?= =?UTF-8?q?=E5=8A=9B=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=89=80=E6=9C=89=E9=87=91?= =?UTF-8?q?=E5=B8=81=E4=B8=8D=E8=B6=B3=E7=9A=84=E5=9C=B0=E6=96=B9=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=BC=B9=E5=87=BA=E5=95=86=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scene/GameScene.fire | 2 +- assets/Script/JiaZai.ts | 3 + assets/Script/Map.ts | 51 +++- assets/Script/heathnum.ts | 42 +++ assets/Script/module/Config/GameConfig.ts | 2 +- assets/prefab/pop/heathpop.prefab | 153 ++++++++--- assets/shop/prefab/shop.prefab | 296 +++------------------- 7 files changed, 252 insertions(+), 297 deletions(-) diff --git a/assets/Scene/GameScene.fire b/assets/Scene/GameScene.fire index 436fd3e..4a52cee 100644 --- a/assets/Scene/GameScene.fire +++ b/assets/Scene/GameScene.fire @@ -11753,7 +11753,7 @@ "__id__": 313 } ], - "_active": false, + "_active": true, "_components": [], "_prefab": null, "_opacity": 255, diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index 75a1881..6411b4a 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -268,6 +268,9 @@ stopHeathTimeCutDown() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); if (cc.fx.GameConfig.GM_INFO.hp < 1) { MiniGameSdk.API.showToast("体力值不足"); + setTimeout(() => { + this.openHeath(); + }, 500); return; } if (this.node.getChildByName("Load").getChildByName("startBtn").getComponent("btnControl")._touch) { diff --git a/assets/Script/Map.ts b/assets/Script/Map.ts index 8b7e778..83ecdcf 100644 --- a/assets/Script/Map.ts +++ b/assets/Script/Map.ts @@ -1332,10 +1332,10 @@ export default class MapConroler extends cc.Component { if (wincoin) { wincoin.updateWinCoin(); } else { - console.warn("JiaZai 组件未找到"); + console.log("JiaZai 组件未找到"); } } else { - console.warn("JiaZai 节点未找到"); + console.log("JiaZai 节点未找到"); } this.check_NewMode(); setTimeout(() => { @@ -1464,7 +1464,11 @@ export default class MapConroler extends cc.Component { // console.log("自身金币:",cc.fx.GameConfig.GM_INFO.coin,"消耗金币:",coin); if (cc.fx.GameConfig.GM_INFO.coin < Math.abs(coin)) { MiniGameSdk.API.showToast("金币不足,无法加时间"); - this.reviewState = false; + setTimeout(() => { + this.openShop(); + this.reviewState = false; + }, 500); + return; } else { @@ -1665,7 +1669,11 @@ export default class MapConroler extends cc.Component { if (cc.fx.GameConfig.GM_INFO.freezeAmount < 1) { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); - freezeBtn.getComponent("btnControl").setTouch(true); + setTimeout(() => { + this.openShop(); + freezeBtn.getComponent("btnControl").setTouch(true); + }, 500); + return; } this.node.parent.parent.getChildByName("propWindow").active = true; @@ -1783,7 +1791,11 @@ export default class MapConroler extends cc.Component { if (cc.fx.GameConfig.GM_INFO.hammerAmount < 1) { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); - hammerBtn.getComponent("btnControl").setTouch(true); + setTimeout(() => { + this.openShop(); + hammerBtn.getComponent("btnControl").setTouch(true); + }, 500); + return; } this.node.parent.parent.getChildByName("propWindow").active = true; @@ -1822,6 +1834,9 @@ export default class MapConroler extends cc.Component { buyMagic() { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); + setTimeout(() => { + this.openShop(); + }, 500); return; } cc.fx.GameTool.buyProp(2003, this.handleBuySuccess.bind(this, "magicAmount")); @@ -1830,6 +1845,9 @@ export default class MapConroler extends cc.Component { buyHammer() { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); + setTimeout(() => { + this.openShop(); + }, 500); return; } cc.fx.GameTool.buyProp(2002, this.handleBuySuccess.bind(this, "hammerAmount")); @@ -1838,11 +1856,28 @@ export default class MapConroler extends cc.Component { buyFreeze() { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); + setTimeout(() => { + this.openShop(); + }, 500); return; } cc.fx.GameTool.buyProp(2001, this.handleBuySuccess.bind(this, "freezeAmount")); } + openShop(){ + const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点 + if (winCOIN) { + const wincoin = winCOIN.getComponent(SceneManager); + if (wincoin) { + wincoin.openShop(); + } else { + console.log("JiaZai 组件未找到"); + } + } else { + console.log("JiaZai 节点未找到"); + } + } + //使用魔法棒随机消除两个方块 useMagic() { if (this.node.parent.getChildByName("Ice").active == true || this.hammer == true @@ -1855,7 +1890,11 @@ export default class MapConroler extends cc.Component { if (cc.fx.GameConfig.GM_INFO.magicAmount < 1) { if (cc.fx.GameConfig.GM_INFO.coin < 1500) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); - magicBtn.getComponent("btnControl").setTouch(true); + setTimeout(() => { + this.openShop(); + magicBtn.getComponent("btnControl").setTouch(true); + }, 500); + return; } this.node.parent.parent.getChildByName("propWindow").active = true; diff --git a/assets/Script/heathnum.ts b/assets/Script/heathnum.ts index b3d3fbc..1b81d1e 100644 --- a/assets/Script/heathnum.ts +++ b/assets/Script/heathnum.ts @@ -1,5 +1,6 @@ import NumberToImage from "./NumberToImage"; import JiaZai from "./JiaZai"; +import { MiniGameSdk } from "./Sdk/MiniGameSdk"; const { ccclass, property } = cc._decorator; @@ -49,6 +50,47 @@ export default class NewClass extends cc.Component { this.closePop(); } + //购买体力 + buyHeath(){ + //获取当前体力 + let curHeath = cc.fx.GameConfig.GM_INFO.hp; + //获取当前金币 + let curCoin = cc.fx.GameConfig.GM_INFO.coin; + if(curCoin >= 1000){ + cc.fx.GameTool.changeCoin(-1000); + cc.fx.GameTool.setUserHealth(5, (data) => { + cc.fx.GameTool.getHealth(null); + const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 + if (parentNode) { + const jiazaiComp = parentNode.getComponent(JiaZai); + if (jiazaiComp) { + jiazaiComp.setHealthInfo(); + jiazaiComp.updateCoin(); + } + } + this.closePop(); + }) + } + else{ + MiniGameSdk.API.showToast("金币不足,无法购买体力"); + setTimeout(() => { + this.openShop(); + }, 500); + } + } + + //金币不够购买金币 + openShop(){ + //获取场景中的 JiaZai 组件 + const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 + if (parentNode) { + const jiazaiComp = parentNode.getComponent(JiaZai); + if (jiazaiComp) { + jiazaiComp.openShop(); + } + } + } + //关闭弹窗 closePop() { //销毁预制体 diff --git a/assets/Script/module/Config/GameConfig.ts b/assets/Script/module/Config/GameConfig.ts index bbf780b..a0d54cb 100644 --- a/assets/Script/module/Config/GameConfig.ts +++ b/assets/Script/module/Config/GameConfig.ts @@ -200,7 +200,7 @@ export class GameConfig { useravatar:"", //用户头像地址 guide: true, //是否有引导 url: "https://api.sparkus.cn",//访问域名 - coin: 0, //用户金币 + coin: 10000, //用户金币 success: false, //用户游戏成功与否 matchId: null, //用于埋点上传的ID gameState:false, diff --git a/assets/prefab/pop/heathpop.prefab b/assets/prefab/pop/heathpop.prefab index 249ffde..1b41eee 100644 --- a/assets/prefab/pop/heathpop.prefab +++ b/assets/prefab/pop/heathpop.prefab @@ -30,14 +30,14 @@ "_active": true, "_components": [ { - "__id__": 70 + "__id__": 72 }, { - "__id__": 71 + "__id__": 73 } ], "_prefab": { - "__id__": 72 + "__id__": 74 }, "_opacity": 255, "_color": { @@ -570,22 +570,22 @@ "__id__": 41 }, { - "__id__": 52 + "__id__": 54 }, { - "__id__": 55 + "__id__": 57 }, { - "__id__": 63 + "__id__": 65 }, { - "__id__": 66 + "__id__": 68 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 69 + "__id__": 71 }, "_opacity": 255, "_color": { @@ -1576,10 +1576,13 @@ "_components": [ { "__id__": 50 + }, + { + "__id__": 51 } ], "_prefab": { - "__id__": 51 + "__id__": 53 }, "_opacity": 255, "_color": { @@ -1612,7 +1615,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -1951,6 +1954,90 @@ }, "_id": "" }, + { + "__type__": "cc.Button", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 41 + }, + "_enabled": true, + "_normalMaterial": null, + "_grayMaterial": null, + "duration": 0.1, + "zoomScale": 1.1, + "clickEvents": [ + { + "__id__": 52 + } + ], + "_N$interactable": true, + "_N$enableAutoGrayEffect": false, + "_N$transition": 3, + "transition": 3, + "_N$normalColor": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_N$pressedColor": { + "__type__": "cc.Color", + "r": 211, + "g": 211, + "b": 211, + "a": 255 + }, + "pressedColor": { + "__type__": "cc.Color", + "r": 211, + "g": 211, + "b": 211, + "a": 255 + }, + "_N$hoverColor": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "hoverColor": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_N$disabledColor": { + "__type__": "cc.Color", + "r": 124, + "g": 124, + "b": 124, + "a": 255 + }, + "_N$normalSprite": null, + "_N$pressedSprite": null, + "pressedSprite": null, + "_N$hoverSprite": null, + "hoverSprite": null, + "_N$disabledSprite": null, + "_N$target": { + "__id__": 41 + }, + "_id": "" + }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 1 + }, + "component": "", + "_componentId": "6624fhcuF5DF67gzSViWhRV", + "handler": "buyHeath", + "customEventData": "" + }, { "__type__": "cc.PrefabInfo", "root": { @@ -1973,11 +2060,11 @@ "_active": true, "_components": [ { - "__id__": 53 + "__id__": 55 } ], "_prefab": { - "__id__": 54 + "__id__": 56 }, "_opacity": 255, "_color": { @@ -2031,7 +2118,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 52 + "__id__": 54 }, "_enabled": true, "_materials": [ @@ -2080,20 +2167,20 @@ }, "_children": [ { - "__id__": 56 + "__id__": 58 }, { - "__id__": 59 + "__id__": 61 } ], "_active": true, "_components": [ { - "__id__": 61 + "__id__": 63 } ], "_prefab": { - "__id__": 62 + "__id__": 64 }, "_opacity": 255, "_color": { @@ -2147,17 +2234,17 @@ "_name": "tili_x", "_objFlags": 0, "_parent": { - "__id__": 55 + "__id__": 57 }, "_children": [], "_active": true, "_components": [ { - "__id__": 57 + "__id__": 59 } ], "_prefab": { - "__id__": 58 + "__id__": 60 }, "_opacity": 255, "_color": { @@ -2211,7 +2298,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 56 + "__id__": 58 }, "_enabled": true, "_materials": [ @@ -2256,13 +2343,13 @@ "_name": "huifuyidian", "_objFlags": 0, "_parent": { - "__id__": 55 + "__id__": 57 }, "_children": [], "_active": true, "_components": [], "_prefab": { - "__id__": 60 + "__id__": 62 }, "_opacity": 255, "_color": { @@ -2327,7 +2414,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 55 + "__id__": 57 }, "_enabled": true, "_materials": [ @@ -2378,11 +2465,11 @@ "_active": false, "_components": [ { - "__id__": 64 + "__id__": 66 } ], "_prefab": { - "__id__": 65 + "__id__": 67 }, "_opacity": 255, "_color": { @@ -2436,7 +2523,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 63 + "__id__": 65 }, "_enabled": true, "_materials": [ @@ -2487,11 +2574,11 @@ "_active": true, "_components": [ { - "__id__": 67 + "__id__": 69 } ], "_prefab": { - "__id__": 68 + "__id__": 70 }, "_opacity": 255, "_color": { @@ -2545,7 +2632,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 68 }, "_enabled": true, "_materials": [ @@ -2639,14 +2726,14 @@ }, "switchNode": [ { - "__id__": 52 + "__id__": 54 }, { - "__id__": 55 + "__id__": 57 } ], "timeNode": { - "__id__": 59 + "__id__": 61 }, "switchButtons": [ { diff --git a/assets/shop/prefab/shop.prefab b/assets/shop/prefab/shop.prefab index e5ff4fc..d6b2350 100644 --- a/assets/shop/prefab/shop.prefab +++ b/assets/shop/prefab/shop.prefab @@ -31,22 +31,19 @@ }, { "__id__": 193 - }, - { - "__id__": 199 - }, - { - "__id__": 203 } ], "_active": true, "_components": [ { - "__id__": 207 + "__id__": 199 + }, + { + "__id__": 200 } ], "_prefab": { - "__id__": 208 + "__id__": 201 }, "_opacity": 255, "_color": { @@ -70,8 +67,8 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - 0, - 0, + 540, + 960, 0, 0, 0, @@ -129,7 +126,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 1080, - "height": 2340 + "height": 1920 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -220,8 +217,8 @@ "_alignFlags": 45, "_left": 0, "_right": 0, - "_top": -210, - "_bottom": -210, + "_top": 0, + "_bottom": 0, "_verticalCenter": 0, "_horizontalCenter": 0, "_isAbsLeft": true, @@ -276,7 +273,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 1080, - "height": 2340 + "height": 1920 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -359,8 +356,8 @@ "_alignFlags": 45, "_left": 0, "_right": 0, - "_top": -210, - "_bottom": -210, + "_top": 0, + "_bottom": 0, "_verticalCenter": 0, "_horizontalCenter": 0, "_isAbsLeft": true, @@ -7327,246 +7324,6 @@ "fileId": "efF/+2Hu1I7J8/LZABlnv9", "sync": false }, - { - "__type__": "cc.Node", - "_name": "New Sprite", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 200 - }, - { - "__id__": 201 - } - ], - "_prefab": { - "__id__": 202 - }, - "_opacity": 150, - "_color": { - "__type__": "cc.Color", - "r": 0, - "g": 0, - "b": 0, - "a": 255 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 1080, - "height": 200 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_trs": { - "__type__": "TypedArray", - "ctor": "Float64Array", - "array": [ - 0, - 1062.507, - 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__": 199 - }, - "_enabled": true, - "_materials": [ - { - "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" - } - ], - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, - "_spriteFrame": { - "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" - }, - "_type": 0, - "_sizeMode": 0, - "_fillType": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_atlas": null, - "_id": "" - }, - { - "__type__": "cc.BlockInputEvents", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 199 - }, - "_enabled": true, - "_id": "" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "9dgIB3VNlAC4rOLKR63X1h", - "sync": false - }, - { - "__type__": "cc.Node", - "_name": "New Sprite", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 204 - }, - { - "__id__": 205 - } - ], - "_prefab": { - "__id__": 206 - }, - "_opacity": 150, - "_color": { - "__type__": "cc.Color", - "r": 0, - "g": 0, - "b": 0, - "a": 255 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 1080, - "height": 200 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.5, - "y": 0.5 - }, - "_trs": { - "__type__": "TypedArray", - "ctor": "Float64Array", - "array": [ - 0, - -1059.951, - 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__": 203 - }, - "_enabled": true, - "_materials": [ - { - "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" - } - ], - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, - "_spriteFrame": { - "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" - }, - "_type": 0, - "_sizeMode": 0, - "_fillType": 0, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_atlas": null, - "_id": "" - }, - { - "__type__": "cc.BlockInputEvents", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 203 - }, - "_enabled": true, - "_id": "" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "c5IbgSqWhDerwgA0hdz30t", - "sync": false - }, { "__type__": "48bfeZuYFZE2qmgxbW2IigB", "_name": "", @@ -7586,6 +7343,33 @@ }, "_id": "" }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 1080, + "_originalHeight": 1920, + "_id": "" + }, { "__type__": "cc.PrefabInfo", "root": {