import { popupContent } from "./PopupContent"; import PopupAnimator, { ActivityPopupAnimationType as PopupType } from "./ActivityPopupAnimator"; import Utils from "./module/Pay/Utils"; import { MiniGameSdk } from "./Sdk/MiniGameSdk"; const { ccclass, property } = cc._decorator; @ccclass export default class RedeemCode extends cc.Component { onDisable() { this.unschedule(this.playPopupEntrance); PopupAnimator.cancel(popupContent(this.node, ["New Sprite(Splash)"])); } onEnable() { this.unschedule(this.playPopupEntrance); PopupAnimator.prepareOpen(popupContent(this.node, ["New Sprite(Splash)"])); this.scheduleOnce(this.playPopupEntrance, 0); } private playPopupEntrance() { if (cc.isValid(this.node, true) && this.node.activeInHierarchy) PopupAnimator.openPrepared(popupContent(this.node, ["New Sprite(Splash)"])); } @property(cc.Button) onBtn: cc.Button = null; @property(cc.EditBox) editBoxCode: cc.EditBox = null; start() { } onConfirm() { cc.fx.AudioManager._instance.playEffect("anniu_little", null); const account = this.editBoxCode ? this.editBoxCode.string.trim() : ""; // 判断用户输入的值是否为空 if (!account) { console.log("兑换码不能为空"); return; } // 如果不为空,发送给服务器 console.log("发送兑换码到服务器:", account); // let res = { code: 1, data: { reward: { 1001: 1000, 2001: 1, 2002: 1, 2003: 1 } } } Utils.getRedeemInfo((res) => { if (res.code === 1) { let rewards = res.data.reward; const rewardData = []; const canvasTemp = cc.find("Canvas"); let JiaZai = null; if (canvasTemp) { JiaZai = canvasTemp.getComponent("JiaZai"); } for (let itemId in rewards) { let itemNum = rewards[itemId]; cc.fx.GameTool.getPassCheckPorp(parseInt(itemId), itemNum, false, true); let typeStr = ''; let finalItemNum = itemNum; switch (parseInt(itemId)) { case 1001: // 金币 typeStr = 'coin'; break; case 2001: // 冰冻道具 typeStr = 'freeze'; break; case 2002: // 锤子道具 typeStr = 'hammer'; break; case 2003: // 魔棒道具 typeStr = 'magic'; break; case 3001: // 无限体力 900秒 typeStr = 'infinite_health'; finalItemNum = 900; break; case 3002: // 无限体力 1800秒 typeStr = 'infinite_health'; finalItemNum = 1800; break; case 3003: // 无限体力 3600秒 typeStr = 'infinite_health'; finalItemNum = 3600; break; default: typeStr = 'infinite_health'; // 默认类型 finalItemNum = itemNum * 900; break; } // let itemIdType = this.getItemIdType(itemId, itemNum); rewardData.push({ type: typeStr, count: finalItemNum }); } // 领取物品弹窗 console.log("rewardData", rewardData) if (JiaZai && rewardData.length > 0) { JiaZai.openRewardWindow(rewardData); } JiaZai.updateCoin(); const data = { code: account, } cc.fx.GameTool.shushu_Track("redeem", data); setTimeout(() => { this.onClose(); }, 1000); } else { MiniGameSdk.API.showToast(res.msg); } }, account) } onClose(event?: cc.Event) { this.unschedule(this.playPopupEntrance); const content = popupContent(this.node, ["New Sprite(Splash)"]); if (!content || (Array.isArray(content) && !content.length)) { this.finishPopupOnClose(event); return; } PopupAnimator.close(content, PopupType.Bounce, () => this.finishPopupOnClose(event)); } finishPopupOnClose(event?: cc.Event) { if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null); this.node.destroy(); } // update (dt) {} }