FarmItem.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { AdFun } from "../../data/AdData";
  2. import { ProductType, VideoAdType } from "../../data/GameData";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class FarmItem extends cc.Component {
  6. @property({ displayName: '图标', type: cc.Sprite })
  7. private sp_icon: cc.Sprite = null;
  8. @property({ displayName: '名字描述', type: cc.Label })
  9. private lbl_nameDes: cc.Label = null;
  10. @property({ displayName: '描述', type: cc.Label })
  11. private lbl_des: cc.Label = null;
  12. @property({ displayName: '组合描述', type: cc.Label })
  13. private lbl_groupDes: cc.Label = null;
  14. @property({ displayName: '领奖按钮', type: cc.Node })
  15. private node_ungetBtn: cc.Node = null;
  16. @property({ displayName: '已领奖按钮', type: cc.Node })
  17. private node_getBtn: cc.Node = null;
  18. @property({ displayName: '未解锁按钮', type: cc.Node })
  19. private node_unluckBtn: cc.Node = null;
  20. @property({ displayName: '红点', type: cc.Node })
  21. private node_redPoint: cc.Node = null;
  22. private data = null;
  23. private isUpdate = false;
  24. public setItemData(data) {
  25. this.InitUI(data);
  26. }
  27. private async InitUI(data) {
  28. this.data = data;
  29. let plantPath = '';
  30. let namePath = '';
  31. if (gData.farmMapData.chooseType == ProductType.nzw) {
  32. plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  33. namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  34. }
  35. else {
  36. plantPath = 'game/coregame/texture/factory_icons/factory_';
  37. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  38. }
  39. let max = gData.farmMapData.maxUnluckValue;
  40. if (data.picture <= max) {
  41. let state = gData.gameData.getFarmMapRewardState(this.getIndex());
  42. if (state == 1) {
  43. this.node_getBtn.active = true;
  44. this.node_ungetBtn.active = false;
  45. this.node_unluckBtn.active = false;
  46. this.node_redPoint.active = false;
  47. } else {
  48. this.node_getBtn.active = false;
  49. this.node_ungetBtn.active = true;
  50. this.node_unluckBtn.active = false;
  51. this.node_redPoint.active = true;
  52. }
  53. this.isUpdate = true;
  54. this.lbl_nameDes.node.active = true;
  55. this.lbl_des.node.active = true;
  56. this.lbl_groupDes.node.active = false;
  57. this.lbl_nameDes.string = `${data.name} ${data.time}秒成熟`;
  58. this.lbl_des.string = `最高收获${data.menuRedBagCoin/100}红包币`;
  59. this.sp_icon.spriteFrame = await mk.loader.load(plantPath + data.picture, cc.SpriteFrame);
  60. } else if (data.picture - 1 == max) {
  61. this.node_getBtn.active = false;
  62. this.node_ungetBtn.active = false;
  63. this.node_unluckBtn.active = true;
  64. this.lbl_nameDes.node.active = false;
  65. this.lbl_des.node.active = false;
  66. this.lbl_groupDes.node.active = true;
  67. this.node_redPoint.active = false;
  68. let times = gData.gameData.getProductMakeTimesById(data.picture - 1);
  69. let plantName = gData.gameData.getProductMap(data.picture - 1).name;
  70. let des = this.getDesByType();
  71. this.lbl_groupDes.string = `${des}${this.data.value}次${plantName}后解锁\n(${times}/${data.value})`;;
  72. this.sp_icon.spriteFrame = await mk.loader.load('module/farmMap/texture/gift', cc.SpriteFrame);
  73. } else {
  74. this.node_getBtn.active = false;
  75. this.node_ungetBtn.active = false;
  76. this.node_unluckBtn.active = true;
  77. this.lbl_nameDes.node.active = false;
  78. this.lbl_des.node.active = false;
  79. this.lbl_groupDes.node.active = true;
  80. this.node_redPoint.active = false;
  81. this.lbl_groupDes.string = "神秘物种,等待发现";
  82. this.sp_icon.spriteFrame = await mk.loader.load('module/farmMap/texture/gift', cc.SpriteFrame);
  83. }
  84. }
  85. getIndex() {
  86. let index: any = {};
  87. index.i = 0;
  88. index.j = 0;
  89. switch (this.data.tab) {
  90. case '农作物':
  91. index.i = 0;
  92. index.j = this.data.picture - 10001;
  93. break;
  94. case '动物':
  95. index.i = 1;
  96. index.j = this.data.picture - 20001;
  97. break;
  98. case '爆米花厂':
  99. index.i = 2;
  100. index.j = this.data.picture - 20004;
  101. break;
  102. case '糕点铺':
  103. index.i = 3;
  104. index.j = this.data.picture - 20013;
  105. break;
  106. case '制糖厂':
  107. index.i = 4;
  108. index.j = this.data.picture - 20010;
  109. break;
  110. case '炼乳厂':
  111. index.i = 5;
  112. index.j = this.data.picture - 20007;
  113. break;
  114. case '功夫面馆':
  115. index.i = 6;
  116. index.j = this.data.picture - 20025;
  117. break;
  118. case '快餐店':
  119. index.i = 7;
  120. index.j = this.data.picture - 20019;
  121. break;
  122. }
  123. return index;
  124. }
  125. getDesByType() {
  126. let des = ''
  127. switch (this.data.tab) {
  128. case '农作物':
  129. des = '种植';
  130. break;
  131. case '动物':
  132. des = '养殖';
  133. break;
  134. case '爆米花厂':
  135. case '糕点铺':
  136. case '制糖厂':
  137. case '炼乳厂':
  138. case '功夫面馆':
  139. case '快餐店':
  140. des = '制作';
  141. break;
  142. }
  143. return des;
  144. }
  145. private clickUnGetRewardBtn() {
  146. mk.audio.playEffect("button");
  147. mk.ad.videoAdType = VideoAdType.video_init_6;
  148. mk.ad.watchAd(async (success) => {
  149. if (success) {
  150. await gData.adData.watchVideo(AdFun.farmMap);
  151. if(gData.farmMapData.init_award)
  152. {
  153. gData.farmMapData.isStateChange = true;
  154. this.node_getBtn.active = true;
  155. this.node_ungetBtn.active = false;
  156. this.node_unluckBtn.active = false;
  157. this.node_redPoint.active = false;
  158. gData.gameData.setFarmMapRewardState(this.getIndex(), 1);
  159. }
  160. gData.gameData.popTableScreenADLogic(15);
  161. }
  162. })
  163. }
  164. private clickUnluckBtn() {
  165. mk.audio.playEffect("button");
  166. mk.tip.pop('未解锁');
  167. }
  168. private clickGetRewardBtn() {
  169. mk.audio.playEffect("button");
  170. mk.tip.pop('已领取');
  171. }
  172. }