/** 可生产物品item */ import { BitmapFontC } from "../../../game/component/BitmapFontC"; import { ProductType } from "../../../game/data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class PlantItem extends cc.Component { @property({ type: cc.Node, tooltip: "布局" }) mainNode: cc.Node = null; @property({ type: cc.Node, tooltip: "未解锁" }) lockNode: cc.Node = null; @property({ type: cc.Sprite, tooltip: "作物图标" }) plantIcon: cc.Sprite = null; @property({ type: cc.Sprite, tooltip: "名字图标" }) nameIcon: cc.Sprite = null; @property({ type: BitmapFontC, tooltip: "获得数量文本" }) awardLabel: BitmapFontC = null; @property({ type: BitmapFontC, tooltip: "成熟时间文本" }) timeLabel: BitmapFontC = null; @property({ type: cc.Label, tooltip: "未开条件" }) labUnlock: cc.Label = null; @property({ type: cc.Label, tooltip: '进度文本' }) lbl_progress: cc.Label = null; @property({ type: cc.Node }) node_plant: cc.Node = null; @property({ type: cc.Node }) node_product: cc.Node = null; private data = null; /** * list_data * @param list_data 数据列表 */ public async setItemData(list_data) { await this.initItem(list_data); } update() { if (gData.plantData.init_itemIndex == this.data.picture) { this.initItem(this.data); gData.plantData.init_itemIndex = -1; } if (gData.plantData.init_lock == this.data.picture) { this.initItem(this.data); gData.plantData.init_lock = -1; } } /** * 数据分发 * @param list_data 数据列表 */ private async initItem(list_data) { this.data = list_data; let plantPath = ''; let namePath = ''; if (this.data.tab == ProductType.nzw) { plantPath = 'game/coregame/texture/plant_icons/plantIcon_'; namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_'; this.node_plant.active = true; this.node_product.active = false; } else { plantPath = 'game/coregame/texture/factory_icons/factory_'; namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_'; this.node_plant.active = false; this.node_product.active = true; } this.plantIcon.spriteFrame = await mk.loader.load(plantPath + list_data.picture, cc.SpriteFrame); this.nameIcon.spriteFrame = await mk.loader.load(namePath + list_data.picture, cc.SpriteFrame); this.awardLabel.string = (list_data.menuRedBagCoin / 100).toString(); this.timeLabel.string = list_data.time; let unlock = false; let times = 0; //根据上个商品种植次数 if (list_data.unlock == 1) { times = gData.gameData.getProductMakeTimesById(list_data.picture - 1); if (times >= list_data.value) { unlock = true; } } //根据农场等级 else if (list_data.unlock == 2) { if (gData.gameData.playerProp.completeFarmTaskTimes >= list_data.value) { unlock = true; } } this.mainNode.active = unlock; this.lockNode.active = !unlock; if (!unlock) { let des = this.getDesByType(); let plantName = gData.gameData.getProductMap(this.data.picture - 1).name; if (list_data.picture - 1 == gData.gameData.getMaxProduct(this.data.tab)) { this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`; this.lbl_progress.string = `${times}/${this.data.value}`; this.labUnlock.node.active = true; } else { this.labUnlock.node.active = false; } } } async clickMake() { mk.audio.playEffect('button'); if (gData.gameData.leftTimes <= 0) { mk.ui.openPanel('module/speedUpUI/productReward'); return; } if (gData.gameData.isProducting) { mk.tip.pop('点击太快了'); return; } let flyRed; if (this.data.tab == ProductType.nzw) { flyRed = await gData.farmSystem.plant(this.data.picture); // gData.gameData.nextMake = null; // gData.gameData.setNextProduct(false); // if (gData.gameData.playerProp.gradeLevel < 2) { // mk.tip.pop('生产次数+1'); // } } else { flyRed = await gData.factorySystem.make(this.data.picture); } if (flyRed) { gData.plantData.init_ani = true; let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition()); gData.gameData.gameStyle.dpFlyRedAni(pos); } } getDesByType() { let des = '' switch (this.data.tab) { case '农作物': des = '种植'; break; case '动物': des = '养殖'; break; case '爆米花厂': case '糕点铺': case '制糖厂': case '炼乳厂': case '功夫面馆': case '快餐店': des = '制作'; break; } return des; } }