PlantItem.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. unlock = gData.gameData.getProductUnlockById(this.data.tab, this.data.picture);
  64. if (!unlock) {
  65. times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
  66. if (times >= list_data.value) {
  67. unlock = true;
  68. }
  69. }
  70. }
  71. //根据农场等级
  72. else if (list_data.unlock == 2) {
  73. if (gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >= list_data.value) {
  74. unlock = true;
  75. }
  76. }
  77. this.mainNode.active = unlock;
  78. this.lockNode.active = !unlock;
  79. if (!unlock) {
  80. let des = this.getDesByType();
  81. let plantName = gData.gameData.getProductMap(this.data.picture - 1).name;
  82. if (list_data.picture - 1 == gData.gameData.getMaxProductExtra(this.data.tab)) {
  83. this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`;
  84. this.lbl_progress.string = `${times}/${this.data.value}`;
  85. this.labUnlock.node.active = true;
  86. }
  87. else {
  88. this.labUnlock.node.active = false;
  89. }
  90. }
  91. }
  92. showTips()
  93. {
  94. mk.tip.pop("生产次数+5");
  95. }
  96. async clickMake() {
  97. mk.audio.playEffect('button');
  98. if (gData.gameData.leftTimes <= 0) {
  99. gData.gameData.popTipCallBack = this.showTips;
  100. mk.ui.openPanel('module/speedUpUI/productReward');
  101. return;
  102. }
  103. if (gData.gameData.isProducting) {
  104. //mk.tip.pop('点击太快了');
  105. return;
  106. }
  107. let flyRed;
  108. if (this.data.tab == ProductType.nzw) {
  109. flyRed = await gData.farmSystem.plant(this.data.picture, this.nameIcon.node);
  110. // gData.gameData.nextMake = null;
  111. // gData.gameData.setNextProduct(false);
  112. // if (gData.gameData.playerProp.gradeLevel < 2) {
  113. // mk.tip.pop('生产次数+1');
  114. // }
  115. }
  116. else {
  117. flyRed = await gData.factorySystem.make(this.data.picture, this.nameIcon.node);
  118. }
  119. if (flyRed) {
  120. if (gData.gameData.funOpenData[4] == "0") {
  121. return;
  122. }
  123. gData.plantData.init_ani = true;
  124. let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition());
  125. gData.gameData.gameStyle.dpFlyRedAni(pos);
  126. }
  127. }
  128. getDesByType() {
  129. let des = ''
  130. switch (this.data.tab) {
  131. case '农作物':
  132. des = '种植';
  133. break;
  134. case '动物':
  135. des = '养殖';
  136. break;
  137. case '爆米花厂':
  138. case '糕点铺':
  139. case '制糖厂':
  140. case '炼乳厂':
  141. case '功夫面馆':
  142. case '快餐店':
  143. des = '制作';
  144. break;
  145. }
  146. return des;
  147. }
  148. }