import { AdFun } from "../../data/AdData"; import { ProductType, VideoAdType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class FarmItem extends cc.Component { @property({ displayName: '图标', type: cc.Sprite }) private sp_icon: cc.Sprite = null; @property({ displayName: '名字描述', type: cc.Label }) private lbl_nameDes: cc.Label = null; @property({ displayName: '描述', type: cc.Label }) private lbl_des: cc.Label = null; @property({ displayName: '组合描述', type: cc.Label }) private lbl_groupDes: cc.Label = null; @property({ displayName: '领奖按钮', type: cc.Node }) private node_ungetBtn: cc.Node = null; @property({ displayName: '已领奖按钮', type: cc.Node }) private node_getBtn: cc.Node = null; @property({ displayName: '未解锁按钮', type: cc.Node }) private node_unluckBtn: cc.Node = null; @property({ displayName: '红点', type: cc.Node }) private node_redPoint: cc.Node = null; private data = null; private isUpdate = false; public setItemData(data) { this.InitUI(data); } private async InitUI(data) { this.data = data; let plantPath = ''; let namePath = ''; if (gData.farmMapData.chooseType == ProductType.nzw) { plantPath = 'game/coregame/texture/plant_icons/plantIcon_'; namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_'; } else { plantPath = 'game/coregame/texture/factory_icons/factory_'; namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_'; } let max = gData.farmMapData.maxUnluckValue; if (data.picture <= max) { let state = gData.gameData.getFarmMapRewardState(this.getIndex()); if (state == 1) { this.node_getBtn.active = true; this.node_ungetBtn.active = false; this.node_unluckBtn.active = false; this.node_redPoint.active = false; } else { this.node_getBtn.active = false; this.node_ungetBtn.active = true; this.node_unluckBtn.active = false; this.node_redPoint.active = true; } this.isUpdate = true; this.lbl_nameDes.node.active = true; this.lbl_des.node.active = true; this.lbl_groupDes.node.active = false; this.lbl_nameDes.string = `${data.name} ${data.time}秒成熟`; this.lbl_des.string = `最高收获${data.menuRedBagCoin/100}红包币`; this.sp_icon.spriteFrame = await mk.loader.load(plantPath + data.picture, cc.SpriteFrame); } else if (data.picture - 1 == max) { this.node_getBtn.active = false; this.node_ungetBtn.active = false; this.node_unluckBtn.active = true; this.lbl_nameDes.node.active = false; this.lbl_des.node.active = false; this.lbl_groupDes.node.active = true; this.node_redPoint.active = false; let times = gData.gameData.getProductMakeTimesById(data.picture - 1); let plantName = gData.gameData.getProductMap(data.picture - 1).name; let des = this.getDesByType(); this.lbl_groupDes.string = `${des}${this.data.value}次${plantName}后解锁\n(${times}/${data.value})`;; this.sp_icon.spriteFrame = await mk.loader.load('module/farmMap/texture/gift', cc.SpriteFrame); } else { this.node_getBtn.active = false; this.node_ungetBtn.active = false; this.node_unluckBtn.active = true; this.lbl_nameDes.node.active = false; this.lbl_des.node.active = false; this.lbl_groupDes.node.active = true; this.node_redPoint.active = false; this.lbl_groupDes.string = "神秘物种,等待发现"; this.sp_icon.spriteFrame = await mk.loader.load('module/farmMap/texture/gift', cc.SpriteFrame); } } getIndex() { let index: any = {}; index.i = 0; index.j = 0; switch (this.data.tab) { case '农作物': index.i = 0; index.j = this.data.picture - 10001; break; case '动物': index.i = 1; index.j = this.data.picture - 20001; break; case '爆米花厂': index.i = 2; index.j = this.data.picture - 20004; break; case '糕点铺': index.i = 3; index.j = this.data.picture - 20013; break; case '制糖厂': index.i = 4; index.j = this.data.picture - 20010; break; case '炼乳厂': index.i = 5; index.j = this.data.picture - 20007; break; case '功夫面馆': index.i = 6; index.j = this.data.picture - 20025; break; case '快餐店': index.i = 7; index.j = this.data.picture - 20019; break; } return index; } getDesByType() { let des = '' switch (this.data.tab) { case '农作物': des = '种植'; break; case '动物': des = '养殖'; break; case '爆米花厂': case '糕点铺': case '制糖厂': case '炼乳厂': case '功夫面馆': case '快餐店': des = '制作'; break; } return des; } private clickUnGetRewardBtn() { mk.audio.playEffect("button"); mk.ad.videoAdType = VideoAdType.video_init_6; mk.ad.watchAd(async (success) => { if (success) { await gData.adData.watchVideo(AdFun.farmMap); if(gData.farmMapData.init_award) { gData.farmMapData.isStateChange = true; this.node_getBtn.active = true; this.node_ungetBtn.active = false; this.node_unluckBtn.active = false; this.node_redPoint.active = false; gData.gameData.setFarmMapRewardState(this.getIndex(), 1); } gData.gameData.popTableScreenADLogic(15); } }) } private clickUnluckBtn() { mk.audio.playEffect("button"); mk.tip.pop('未解锁'); } private clickGetRewardBtn() { mk.audio.playEffect("button"); mk.tip.pop('已领取'); } }