PlantItem.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /** 可生产物品item */
  2. import { BitmapFontC } from "../../../game/component/BitmapFontC";
  3. import { ProductType } from "../../../game/data/GameData";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class PlantItem extends cc.Component {
  7. @property({ type: cc.Node, tooltip: "布局" }) mainNode: cc.Node = null;
  8. @property({ type: cc.Node, tooltip: "未解锁" }) lockNode: cc.Node = null;
  9. @property({ type: cc.Sprite, tooltip: "作物图标" }) plantIcon: cc.Sprite = null;
  10. @property({ type: cc.Sprite, tooltip: "名字图标" }) nameIcon: cc.Sprite = null;
  11. @property({ type: BitmapFontC, tooltip: "获得数量文本" }) awardLabel: BitmapFontC = null;
  12. @property({ type: BitmapFontC, tooltip: "成熟时间文本" }) timeLabel: BitmapFontC = null;
  13. @property({ type: cc.Label, tooltip: "未开条件" }) labUnlock: cc.Label = null;
  14. @property({ type: cc.Label, tooltip: '进度文本' }) lbl_progress: cc.Label = null;
  15. @property({ type: cc.Node }) node_plant: cc.Node = null;
  16. @property({ type: cc.Node }) node_product: cc.Node = null;
  17. @property({ type: cc.Node, tooltip: '文字动画' }) node_ani: cc.Node = null;
  18. private data = null;
  19. /**
  20. * list_data
  21. * @param list_data 数据列表
  22. */
  23. public async setItemData(list_data) {
  24. await this.initItem(list_data);
  25. }
  26. update() {
  27. if (gData.plantData.init_itemIndex == this.data.picture) {
  28. this.initItem(this.data);
  29. gData.plantData.init_itemIndex = -1;
  30. }
  31. if (gData.plantData.init_lock == this.data.picture) {
  32. this.initItem(this.data);
  33. gData.plantData.init_lock = -1;
  34. }
  35. }
  36. /**
  37. * 数据分发
  38. * @param list_data 数据列表
  39. */
  40. private async initItem(list_data) {
  41. this.data = list_data;
  42. let plantPath = '';
  43. let namePath = '';
  44. if (this.data.tab == ProductType.nzw) {
  45. plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  46. namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  47. this.node_plant.active = true;
  48. this.node_product.active = false;
  49. }
  50. else {
  51. plantPath = 'game/coregame/texture/factory_icons/factory_';
  52. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  53. this.node_plant.active = false;
  54. this.node_product.active = true;
  55. }
  56. this.plantIcon.spriteFrame = await mk.loader.load(plantPath + list_data.picture, cc.SpriteFrame);
  57. this.nameIcon.spriteFrame = await mk.loader.load(namePath + list_data.picture, cc.SpriteFrame);
  58. this.awardLabel.string = (list_data.menuRedBagCoin / 100).toString();
  59. this.timeLabel.string = list_data.time;
  60. let unlock = false;
  61. let times = 0;
  62. //根据上个商品种植次数
  63. if (list_data.unlock == 1) {
  64. times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
  65. if (times >= list_data.value) {
  66. unlock = true;
  67. }
  68. }
  69. //根据农场等级
  70. else if (list_data.unlock == 2) {
  71. if (gData.gameData.playerProp.completeFarmTaskTimes >= list_data.value) {
  72. unlock = true;
  73. }
  74. }
  75. this.mainNode.active = unlock;
  76. this.lockNode.active = !unlock;
  77. if (!unlock) {
  78. let des = this.getDesByType();
  79. let plantName = gData.gameData.getProductMap(this.data.picture - 1).name;
  80. if (list_data.picture - 1 == gData.gameData.getMaxProduct(this.data.tab)) {
  81. this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`;
  82. this.lbl_progress.string = `${times}/${this.data.value}`;
  83. this.labUnlock.node.active = true;
  84. }
  85. else {
  86. this.labUnlock.node.active = false;
  87. }
  88. }
  89. }
  90. async clickMake() {
  91. mk.audio.playEffect('button');
  92. if (gData.gameData.leftTimes <= 0) {
  93. mk.ui.openPanel('module/speedUpUI/productReward');
  94. return;
  95. }
  96. if (gData.gameData.isProducting) {
  97. mk.tip.pop('点击太快了');
  98. return;
  99. }
  100. if (this.data.tab == ProductType.nzw) {
  101. gData.farmSystem.plant(this.data.picture);
  102. gData.gameData.nextMake = null;
  103. gData.gameData.setNextProduct(false);
  104. // if (gData.gameData.playerProp.gradeLevel < 2) {
  105. // mk.tip.pop('生产次数+1');
  106. // }
  107. }
  108. else {
  109. gData.factorySystem.make(this.data.picture);
  110. }
  111. let flyRed = await gData.gameData.updateNewTaskProgress(true);
  112. if (flyRed) {
  113. if (gData.gameData.playerProp.userFarmTaskInfo) {
  114. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  115. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  116. let addAni = cc.instantiate(this.node_ani);
  117. addAni.parent = this.node_ani.parent;
  118. addAni.getComponent(cc.Label).string = `百元红包:${com}/${count}`;
  119. cc.tween(addAni).delay(0.7).call(()=>{
  120. addAni.opacity = 255;
  121. }).by(0.8, {y : 100}).to(0.4, {opacity : 0}).call(()=>{
  122. addAni.destroy();
  123. }).start();
  124. }
  125. let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition());
  126. gData.gameData.gameStyle.dpFlyRedAni(pos);
  127. }
  128. }
  129. getDesByType() {
  130. let des = ''
  131. switch (this.data.tab) {
  132. case '农作物':
  133. des = '种植';
  134. break;
  135. case '动物':
  136. des = '养殖';
  137. break;
  138. case '爆米花厂':
  139. case '糕点铺':
  140. case '制糖厂':
  141. case '炼乳厂':
  142. case '功夫面馆':
  143. case '快餐店':
  144. des = '制作';
  145. break;
  146. }
  147. return des;
  148. }
  149. }