colorBlock_iaa/assets/Script/heathnum.ts

134 lines
4.2 KiB
TypeScript

import NumberToImage from "./NumberToImage";
import JiaZai from "./JiaZai";
import { MiniGameSdk } from "./Sdk/MiniGameSdk";
import { MiniGameManager } from "./Sdk/MiniGameManager";
// prefab/pop/heathpop
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
//商店界面
@property(cc.Node)
heath: cc.Node = null;
//体力数量
@property(cc.Node)
heatht: cc.Node = null;
//切换的节点
@property([cc.Node])
switchNode: cc.Node[] = [];
//倒计时健康回复
@property(cc.Node)
timeNode: cc.Node = null;
//切换的按钮数组 // 删除此按钮数组内的 金币买体力 改成分享
@property([cc.Node])
switchButtons: cc.Node[] = [];
//金币花费数
// @property(cc.Node)
// coin: cc.Node = null;
btn_Touch: boolean = true;
onLoad() {
this.btn_Touch = true;
if (cc.fx.GameTool.canObtainByShare("health")) {
// 分享
this.switchButtons[2].getChildByName("share_img").active = true;
this.switchButtons[2].getChildByName("ad_img").active = false;
} else {
// 视频
this.switchButtons[2].getChildByName("share_img").active = true;
this.switchButtons[2].getChildByName("ad_img").active = false;
}
}
start() {
this.btn_Touch = true;
this.openPop();
}
//打开商店界面
openPop() {
// console.log("打开heath弹窗", cc.fx.GameConfig.GM_INFO.hp);
//NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 30, 15, "time_", this.coin, true);
}
startGame() {
// 获取场景中的 JiaZai 组件
const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
if (jiazaiNode) {
const jiazaiComp = jiazaiNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.startGame();
} else {
console.warn("JiaZai 组件未找到");
}
} else {
console.warn("JiaZai 节点未找到");
}
this.closePop();
}
onShare() {
if (!this.btn_Touch) {
return;
}
this.btn_Touch = false;
//获取当前体力
// let curHeath = cc.fx.GameConfig.GM_INFO.hp;
//获取当前金币
// let curCoin = cc.fx.GameConfig.GM_INFO.coin;
// if (curCoin >= 1000) {
// cc.fx.GameConfig.GM_INFO.hp = 1; // 测试时不通过微信分享使用
var callback = function () {
//// 分享成功后才执行以下代码
console.log("分享得体力");
this.switchButtons[1].active = false;
cc.fx.GameConfig.GM_INFO.hp = 1;
cc.fx.GameConfig.GM_INFO.min_Time = 0;
// NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 40, 20, "month_", this.heatht, true);
const parentNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
if (parentNode) {
const jiazaiComp = parentNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.setHealthInfo(false);
}
}
this.switchButtons[0].active = true;
cc.fx.GameTool.setUserHealth(0, (data) => {
cc.fx.GameTool.getHealth(null);
})
}
if (cc.fx.GameTool.canObtainByShare("health")) {
cc.fx.GameTool.shareToWX(callback)
} else {
cc.fx.GameTool.onShowVideo(callback)
}
}
//关闭弹窗
closePop() {
this.btn_Touch = true;
//销毁预制体
// console.log("关闭heath弹窗");
//关闭计时器
// 获取场景中的 JiaZai 组件
const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
if (jiazaiNode) {
const jiazaiComp = jiazaiNode.getComponent(JiaZai);
if (jiazaiComp) {
jiazaiComp.stopHeathTimeCutDown();
} else {
console.warn("JiaZai 组件未找到");
}
} else {
console.warn("JiaZai 节点未找到");
}
this.heath.destroy();
}
// update (dt) {}
}