PlantItem.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. private data = null;
  18. /**
  19. * list_data
  20. * @param list_data 数据列表
  21. */
  22. public async setItemData(list_data) {
  23. await this.initItem(list_data);
  24. }
  25. update() {
  26. if (gData.plantData.init_itemIndex == this.data.picture) {
  27. this.initItem(this.data);
  28. gData.plantData.init_itemIndex = -1;
  29. }
  30. if (gData.plantData.init_lock == this.data.picture) {
  31. this.initItem(this.data);
  32. gData.plantData.init_lock = -1;
  33. }
  34. }
  35. /**
  36. * 数据分发
  37. * @param list_data 数据列表
  38. */
  39. private async initItem(list_data) {
  40. this.data = list_data;
  41. let plantPath = '';
  42. let namePath = '';
  43. if (this.data.tab == ProductType.nzw) {
  44. plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  45. namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  46. this.node_plant.active = true;
  47. this.node_product.active = false;
  48. }
  49. else {
  50. plantPath = 'game/coregame/texture/factory_icons/factory_';
  51. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  52. this.node_plant.active = false;
  53. this.node_product.active = true;
  54. }
  55. this.plantIcon.spriteFrame = await mk.loader.load(plantPath + list_data.picture, cc.SpriteFrame);
  56. this.nameIcon.spriteFrame = await mk.loader.load(namePath + list_data.picture, cc.SpriteFrame);
  57. this.awardLabel.string = (list_data.menuRedBagCoin / 100).toString();
  58. this.timeLabel.string = list_data.time;
  59. let unlock = false;
  60. let times = 0;
  61. //根据上个商品种植次数
  62. if (list_data.unlock == 1) {
  63. times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
  64. if (times >= list_data.value) {
  65. unlock = true;
  66. }
  67. }
  68. //根据农场等级
  69. else if (list_data.unlock == 2) {
  70. if (gData.gameData.playerProp.completeFarmTaskTimes >= list_data.value) {
  71. unlock = true;
  72. }
  73. }
  74. this.mainNode.active = unlock;
  75. this.lockNode.active = !unlock;
  76. if (!unlock) {
  77. let des = this.getDesByType();
  78. let plantName = gData.gameData.getProductMap(this.data.picture - 1).name;
  79. if (list_data.picture - 1 == gData.gameData.getMaxProduct(this.data.tab)) {
  80. this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`;
  81. this.lbl_progress.string = `${times}/${this.data.value}`;
  82. this.labUnlock.node.active = true;
  83. }
  84. else {
  85. this.labUnlock.node.active = false;
  86. }
  87. }
  88. }
  89. async clickMake() {
  90. mk.audio.playEffect('button');
  91. if (gData.gameData.leftTimes <= 0) {
  92. mk.ui.openPanel('module/speedUpUI/productReward');
  93. return;
  94. }
  95. if (gData.gameData.isProducting) {
  96. mk.tip.pop('点击太快了');
  97. return;
  98. }
  99. let flyRed;
  100. if (this.data.tab == ProductType.nzw) {
  101. flyRed = await 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. flyRed = await gData.factorySystem.make(this.data.picture);
  110. }
  111. if (flyRed) {
  112. gData.plantData.init_ani = true;
  113. let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition());
  114. gData.gameData.gameStyle.dpFlyRedAni(pos);
  115. }
  116. }
  117. getDesByType() {
  118. let des = ''
  119. switch (this.data.tab) {
  120. case '农作物':
  121. des = '种植';
  122. break;
  123. case '动物':
  124. des = '养殖';
  125. break;
  126. case '爆米花厂':
  127. case '糕点铺':
  128. case '制糖厂':
  129. case '炼乳厂':
  130. case '功夫面馆':
  131. case '快餐店':
  132. des = '制作';
  133. break;
  134. }
  135. return des;
  136. }
  137. }