更新获得奖励弹窗

This commit is contained in:
YZ\249929363 2025-07-17 10:42:59 +08:00
parent 371d0a519d
commit 5b04762c74
9 changed files with 519 additions and 83 deletions

View File

@ -95,18 +95,26 @@ export default class JiaZai extends cc.Component {
} }
JiaZai.cachedShopPrefab = prefab; JiaZai.cachedShopPrefab = prefab;
}); });
}); bundle.load('prefab/RewardWindow', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
}
// 预加载 reward 预制体
if (!JiaZai.cachedRewardPrefab) {
cc.assetManager.loadBundle('reward', (err: Error, bundle: cc.AssetManager.Bundle) => {
if (err) { if (err) {
cc.error(err.message || err); cc.error(err.message || err);
return; 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();
});
});
}
if (cc.fx.GameConfig.GM_INFO.first) { if (cc.fx.GameConfig.GM_INFO.first) {
//console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid); //console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid);
@ -142,11 +150,8 @@ export default class JiaZai extends cc.Component {
}, 1000); }, 1000);
} }
//console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen); //console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen);
AudioManager._instance.playMusicGame(); AudioManager._instance.playMusicGame();
this.getOrder();
} }
start() { start() {
@ -296,6 +301,7 @@ export default class JiaZai extends cc.Component {
uploadToCloud(level: number) { uploadToCloud(level: number) {
if (typeof wx !== 'undefined') { if (typeof wx !== 'undefined') {
//@ts-ignore
wx.setUserCloudStorage({ wx.setUserCloudStorage({
KVDataList: [ KVDataList: [
{ key: 'level', value: String(level) } { key: 'level', value: String(level) }
@ -397,6 +403,26 @@ export default class JiaZai extends cc.Component {
// //console.log("shopNode parent:", this.shopNode.parent); // //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() { closeShop() {
if (this.shopNode) { if (this.shopNode) {

View File

@ -1582,6 +1582,7 @@ export default class MapConroler extends cc.Component {
} }
uploadToCloud(level: number) { uploadToCloud(level: number) {
if (typeof wx !== 'undefined') { if (typeof wx !== 'undefined') {
//@ts-ignore
wx.setUserCloudStorage({ wx.setUserCloudStorage({
KVDataList: [ KVDataList: [
{ key: 'level', value: String(level) } { key: 'level', value: String(level) }

View File

@ -1,3 +1,4 @@
import NumberToImage from "./NumberToImage";
const { ccclass, property, requireComponent } = cc._decorator; const { ccclass, property, requireComponent } = cc._decorator;
@ -8,12 +9,159 @@ export default class Reward extends cc.Component {
@property(cc.Prefab) @property(cc.Prefab)
rewardNode: cc.Prefab = null; rewardNode: cc.Prefab = null;
actionOver: boolean;
speedTime: number = 50;
private originalTimeScale: number = 1; // 记录原始时间缩放比例
onLoad() { onLoad() {
// 为节点添加点击事件监听器
this.speedTime = 50;
} }
start() { 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);
}
}
}

View File

@ -8,7 +8,7 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 1790, "width": 1852,
"height": 1765, "height": 1765,
"platformSettings": {}, "platformSettings": {},
"subMetas": {} "subMetas": {}

View File

@ -23,6 +23,9 @@
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 6
},
{ {
"__id__": 7 "__id__": 7
}, },
@ -55,8 +58,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 540,
0, 960,
0, 0,
0, 0,
0, 0,
@ -95,13 +98,10 @@
}, },
{ {
"__id__": 4 "__id__": 4
},
{
"__id__": 5
} }
], ],
"_prefab": { "_prefab": {
"__id__": 6 "__id__": 5
}, },
"_opacity": 150, "_opacity": 150,
"_color": { "_color": {
@ -182,16 +182,6 @@
"_atlas": null, "_atlas": null,
"_id": "" "_id": ""
}, },
{
"__type__": "cc.BlockInputEvents",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_id": ""
},
{ {
"__type__": "cc.Widget", "__type__": "cc.Widget",
"_name": "", "_name": "",
@ -270,6 +260,16 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.BlockInputEvents",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": { "root": {

View File

@ -24,19 +24,16 @@
"__id__": 5 "__id__": 5
}, },
{ {
"__id__": 8 "__id__": 19
}, },
{ {
"__id__": 11 "__id__": 21
},
{
"__id__": 14
} }
], ],
"_active": true, "_active": true,
"_components": [], "_components": [],
"_prefab": { "_prefab": {
"__id__": 17 "__id__": 24
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -48,8 +45,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 0, "width": 360,
"height": 0 "height": 360
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -167,7 +164,7 @@
"defaultAnimation": "animation", "defaultAnimation": "animation",
"_preCacheMode": 0, "_preCacheMode": 0,
"_cacheMode": 0, "_cacheMode": 0,
"loop": true, "loop": false,
"premultipliedAlpha": false, "premultipliedAlpha": false,
"timeScale": 1, "timeScale": 1,
"_accTime": 0, "_accTime": 0,
@ -178,7 +175,7 @@
"_animationName": "animation", "_animationName": "animation",
"_animationQueue": [], "_animationQueue": [],
"_headAniInfo": null, "_headAniInfo": null,
"_playTimes": 0, "_playTimes": 1,
"_isAniComplete": true, "_isAniComplete": true,
"_N$skeletonData": { "_N$skeletonData": {
"__uuid__": "62ae7eaa-1552-4465-9696-f6220311642a" "__uuid__": "62ae7eaa-1552-4465-9696-f6220311642a"
@ -204,20 +201,93 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "coin", "_name": "icon",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 1 "__id__": 1
}, },
"_children": [], "_children": [
"_active": true,
"_components": [
{ {
"__id__": 6 "__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": { "_prefab": {
"__id__": 7 "__id__": 8
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -248,9 +318,9 @@
0, 0,
0, 0,
1, 1,
1.5, 1.6,
1.5, 1.6,
1 10
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
@ -271,7 +341,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 5 "__id__": 6
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -308,7 +378,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "40yFZaE/dBDrxorfDNFUMC", "fileId": "315emM+4FE3ahxG+gJrlde",
"sync": false "sync": false
}, },
{ {
@ -316,17 +386,17 @@
"_name": "freeze", "_name": "freeze",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 1 "__id__": 5
}, },
"_children": [], "_children": [],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 9 "__id__": 10
} }
], ],
"_prefab": { "_prefab": {
"__id__": 10 "__id__": 11
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -351,15 +421,15 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
0, 22.703,
0, 0,
0, 0,
0, 0,
0, 0,
1, 1,
0.6, 0.7,
0.6, 0.7,
1 6
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
@ -380,7 +450,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 8 "__id__": 9
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -417,7 +487,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "c5266WhWxF3plZF/PuHtKD", "fileId": "3crJ0GPJBL/rvs/pHPjNL1",
"sync": false "sync": false
}, },
{ {
@ -425,17 +495,17 @@
"_name": "hammer", "_name": "hammer",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 1 "__id__": 5
}, },
"_children": [], "_children": [],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 12 "__id__": 13
} }
], ],
"_prefab": { "_prefab": {
"__id__": 13 "__id__": 14
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -466,9 +536,9 @@
0, 0,
0, 0,
1, 1,
0.6, 0.7,
0.6, 0.7,
1 6
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
@ -489,7 +559,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 11 "__id__": 12
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -526,7 +596,7 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "72MartNEJAL6ekj/G4vmuw", "fileId": "68PN+eHZ5Bbo8mITd+YvXp",
"sync": false "sync": false
}, },
{ {
@ -534,17 +604,17 @@
"_name": "magic", "_name": "magic",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 1 "__id__": 5
}, },
"_children": [], "_children": [],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 15 "__id__": 16
} }
], ],
"_prefab": { "_prefab": {
"__id__": 16 "__id__": 17
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -568,16 +638,16 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
5.527, 6.895,
-7.6, -3.438,
0, 0,
0, 0,
0, 0,
0, 0,
1, 1,
0.6, 0.7,
0.6, 0.7,
1 6
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
@ -598,7 +668,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 14 "__id__": 15
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
@ -635,7 +705,198 @@
"asset": { "asset": {
"__id__": 0 "__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 "sync": false
}, },
{ {

View File

@ -4626,7 +4626,7 @@
"__id__": 125 "__id__": 125
} }
], ],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 128 "__id__": 128
@ -4844,7 +4844,7 @@
"__id__": 18 "__id__": 18
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 131 "__id__": 131
@ -4951,7 +4951,7 @@
"__id__": 18 "__id__": 18
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 134 "__id__": 134
@ -5058,7 +5058,7 @@
"__id__": 18 "__id__": 18
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 137 "__id__": 137
@ -5241,7 +5241,7 @@
"__id__": 249 "__id__": 249
} }
], ],
"_active": false, "_active": true,
"_components": [], "_components": [],
"_prefab": { "_prefab": {
"__id__": 260 "__id__": 260