RedPointControl.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }
  11. update(dt)
  12. {
  13. if(gData.farmMapData.isStateChange)
  14. {
  15. this.changeStatus();
  16. }
  17. if(gData.farmMapData.isInit)
  18. {
  19. gData.farmMapData.isInit = false;
  20. this.changeStatus();
  21. }
  22. }
  23. private changeStatus()
  24. {
  25. for (let key in ProductType) {
  26. let max = gData.gameData.getMaxProduct(ProductType[key]);
  27. if (max) {
  28. let list_data = gData.gameData.getProductArrByType(ProductType[key]);
  29. for (let i = 0; i != list_data.length; ++i) {
  30. if (list_data[i].picture <= max) {
  31. let state = gData.gameData.getFarmMapRewardState(this.getIndex(list_data[i]));
  32. if (state == 0) {
  33. this.node_redPoint.active = true;
  34. return;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. this.node_redPoint.active = false;
  41. }
  42. getIndex(data) {
  43. let index: any = {};
  44. index.i = 0;
  45. index.j = 0;
  46. switch (data.tab) {
  47. case '农作物':
  48. index.i = 0;
  49. index.j = data.picture - 10001;
  50. break;
  51. case '动物':
  52. index.i = 1;
  53. index.j = data.picture - 20001;
  54. break;
  55. case '爆米花厂':
  56. index.i = 2;
  57. index.j = data.picture - 20004;
  58. break;
  59. case '糕点铺':
  60. index.i = 3;
  61. index.j = data.picture - 20013;
  62. break;
  63. case '制糖厂':
  64. index.i = 4;
  65. index.j = data.picture - 20010;
  66. break;
  67. case '炼乳厂':
  68. index.i = 5;
  69. index.j = data.picture - 20007;
  70. break;
  71. case '功夫面馆':
  72. index.i = 6;
  73. index.j = data.picture - 20025;
  74. break;
  75. case '快餐店':
  76. index.i = 7;
  77. index.j = data.picture - 20019;
  78. break;
  79. }
  80. return index;
  81. }
  82. }