// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import JiaZai from "./JiaZai"; import Utils from "./module/Pay/Utils"; import NumberToImage from "./NumberToImage"; import SceneManager from "./SceneManager"; const { ccclass, property } = cc._decorator; @ccclass export default class NewClass extends cc.Component { @property(cc.Node) monthCardTime: cc.Node = null; //月卡按钮切换 @property(cc.Node) monthCardBtn: cc.Node = null; //月卡按钮 @property(cc.Node) monthCardBtn2: cc.Node = null; public juwai = false; // LIFE-CYCLE CALLBACKS: // onLoad () {} start() { Utils.getMonthlyCard((data) => { if (data.msg == "不在有效期") { this.monthCardBtn.active = true; this.monthCardBtn2.active = false; } else { this.monthCardBtn.active = false; this.monthCardBtn2.active = true; } }) } init() { Utils.getMonthlyCard((data) => { if (data.msg == "不在有效期") { this.monthCardBtn.active = true; this.monthCardBtn2.active = false; } else { this.monthCardBtn.active = false; this.monthCardBtn2.active = true; NumberToImage.numberToImageNodes(25, 35, 20, "month_", this.monthCardTime, true); } }) } //购买月卡 buyMonthCard() { Utils.setMonthlyCard(0, (data) => { console.log("购买月卡'✅ ", data.code); if (data.code == 1) { let rewardData = [ { type: "coin", count: 6000 }, ] cc.fx.GameConfig.GM_INFO.hp_Max = 7; cc.fx.GameConfig.GM_INFO.hp = 7; cc.fx.GameTool.changeCoin(6000); const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 const jiazaiComp = jiazaiNode.getComponent(JiaZai); if (jiazaiComp) { setTimeout(() => { jiazaiComp.setHealthInfo(false); jiazaiComp.startTimeCutDown(); jiazaiComp.updateCoin(); }, 300); } else { console.log("无法获取JiaZai组件"); } this.monthCardBtn.active = false; this.monthCardBtn2.active = true; this.monthCardTime.active = true; if (this.juwai == true) { if (jiazaiComp) { setTimeout(() => { jiazaiComp.openRewardWindow(rewardData, 1); }, 300); } console.log("月卡奖励juwai"); } else { // 尝试获取SceneManager组件 const jiazaiComp1 = jiazaiNode.getComponent(SceneManager); if (jiazaiComp1) { setTimeout(() => { jiazaiComp1.updateCoin(); // 确保openRewardWindow方法存在 if (typeof jiazaiComp1.openRewardWindow === 'function') { jiazaiComp1.openRewardWindow(rewardData); } else { console.error("SceneManager组件中没有openRewardWindow方法"); // 尝试使用JiaZai组件的openRewardWindow方法作为备选 const jiazaiComp2 = jiazaiNode.getComponent(JiaZai); if (jiazaiComp2 && typeof jiazaiComp2.openRewardWindow === 'function') { jiazaiComp2.openRewardWindow(rewardData); } } }, 300); console.log("月卡奖励junei"); } else { console.log("无法获取SceneManager组件,尝试获取JiaZai组件"); // 尝试获取JiaZai组件作为备选 const jiazaiComp2 = jiazaiNode.getComponent(JiaZai); if (jiazaiComp2) { setTimeout(() => { jiazaiComp2.updateCoin(); jiazaiComp2.openRewardWindow(rewardData); }, 300); } else { console.error("无法获取JiaZai组件和SceneManager组件"); } } } cc.fx.GameTool.setUserHealth(0, (data) => { cc.fx.GameTool.getHealth(null); }) } }) // update (dt) {} } closeMonthCard() { this.init(); //获取商城界面更新图标方法 let shop = cc.find("Canvas/shop"); if (shop) { let shopComp = shop.getComponent("shop"); if (shopComp) { shopComp.updateIcon(); } } this.node.active = false; } }