RedPointControl.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { ProductType } from "../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export class RedPointControl extends cc.Component {
  5. @property({type: cc.Node, displayName: '红点节点'})
  6. private node_redPoint: cc.Node = null;
  7. start()
  8. {
  9. //this.changeStatus();
  10. gData.farmMapData.isStateChange = false;
  11. }
  12. update(dt)
  13. {
  14. if(gData.farmMapData.isStateChange)
  15. {
  16. this.changeStatus();
  17. mk.event.emit("initFarmMapUi");
  18. }
  19. if(gData.farmMapData.isInit)
  20. {
  21. gData.farmMapData.isInit = false;
  22. this.changeStatus();
  23. }
  24. }
  25. lateUpdate()
  26. {
  27. gData.farmMapData.isStateChange = false;
  28. }
  29. private changeStatus()
  30. {
  31. for (let key in ProductType) {
  32. let max = gData.gameData.getMaxProductExtra(ProductType[key]);
  33. if (max) {
  34. let list_data = gData.gameData.getProductArrByType(ProductType[key]);
  35. for (let i = 0; i != list_data.length; ++i) {
  36. if (list_data[i].picture <= max) {
  37. let state = gData.gameData.getFarmMapRewardState(this.getIndex(list_data[i]));
  38. if (state == 0) {
  39. this.node_redPoint.active = true;
  40. return;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. this.node_redPoint.active = false;
  47. }
  48. getIndex(data) {
  49. let index: any = {};
  50. index.i = 0;
  51. index.j = 0;
  52. switch (data.tab) {
  53. case '农作物':
  54. index.i = 0;
  55. index.j = data.picture - 10001;
  56. break;
  57. case '动物':
  58. index.i = 1;
  59. index.j = data.picture - 20001;
  60. break;
  61. case '爆米花厂':
  62. index.i = 2;
  63. index.j = data.picture - 20004;
  64. break;
  65. case '糕点铺':
  66. index.i = 3;
  67. index.j = data.picture - 20013;
  68. break;
  69. case '制糖厂':
  70. index.i = 4;
  71. index.j = data.picture - 20010;
  72. break;
  73. case '炼乳厂':
  74. index.i = 5;
  75. index.j = data.picture - 20007;
  76. break;
  77. case '功夫面馆':
  78. index.i = 6;
  79. index.j = data.picture - 20025;
  80. break;
  81. case '快餐店':
  82. index.i = 7;
  83. index.j = data.picture - 20019;
  84. break;
  85. }
  86. return index;
  87. }
  88. }