CityItem.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. cityPic: cc.Sprite,
  5. incomeSpeedLabel: cc.Label,
  6. indexLabel: cc.Label,
  7. stateSprite: cc.Sprite,
  8. incomeLayout: cc.Node,
  9. line: cc.Node,
  10. currentIndicator: cc.Node,
  11. },
  12. // onLoad () {},
  13. init(info, incomeSpeed) {
  14. this.info = info;
  15. this.indexLabel.string = info.id;
  16. switch (info.state) {
  17. case 1:
  18. this.statePath = 'selected';
  19. this.picPath = info.picId + '_';
  20. this.indexLabel.node.active = true;
  21. this.currentIndicator.active = true;
  22. break;
  23. case 2:
  24. this.statePath = 'unlocked';
  25. this.picPath = info.picId + '_';
  26. this.indexLabel.node.active = true;
  27. this.currentIndicator.active = false;
  28. break;
  29. default:
  30. this.statePath = 'lock';
  31. this.picPath = info.picId;
  32. this.indexLabel.node.active = false;
  33. this.currentIndicator.active = false;
  34. break;
  35. }
  36. cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
  37. this.cityPic.spriteFrame = spriteFrame;
  38. this.currentIndicator.y = this.cityPic.node.height / 2 - this.currentIndicator.height / 2;
  39. });
  40. cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => {
  41. this.stateSprite.spriteFrame = spriteFrame;
  42. });
  43. if (incomeSpeed > 0) {
  44. this.incomeLayout.active = true;
  45. this.incomeSpeedLabel.string = `${incomeSpeed}/天`;
  46. } else {
  47. this.incomeLayout.active = false;
  48. }
  49. if (this.node.x === -110) {
  50. this.line.x = -60;
  51. this.line.scaleX = 1;
  52. } else {
  53. this.line.x = 60;
  54. this.line.scaleX = -1;
  55. }
  56. if (info.state == 2) {
  57. this.line.active = true;
  58. } else {
  59. this.line.active = false;
  60. }
  61. },
  62. start() {
  63. },
  64. setState(state) {
  65. switch (state) {
  66. case 1:
  67. this.statePath = 'selected';
  68. this.picPath = this.info.picId + '_';
  69. this.indexLabel.node.active = true;
  70. break;
  71. case 2:
  72. this.statePath = 'unlocked';
  73. this.picPath = this.info.picId + '_';
  74. this.indexLabel.node.active = true;
  75. break;
  76. default:
  77. this.statePath = 'lock';
  78. this.picPath = this.info.picId;
  79. this.indexLabel.node.active = false;
  80. break;
  81. }
  82. let end = cc.callFunc(() => {
  83. cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => {
  84. this.stateSprite.spriteFrame = spriteFrame;
  85. });
  86. });
  87. this.stateSprite.node.runAction(cc.sequence(cc.scaleTo(0.2, 0, 0), end, cc.scaleTo(0.2, 1, 1)));
  88. cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
  89. this.cityPic.spriteFrame = spriteFrame;
  90. });
  91. if (state == 2) {
  92. this.line.active = true;
  93. } else {
  94. this.line.active = false;
  95. }
  96. },
  97. showFinishAnimation(cb) {
  98. this.line.active = true;
  99. this.line.getComponent('LineCtrl').showAnimation(() => {
  100. cc.loader.loadRes('./map/' + this.info.picId + '_', cc.SpriteFrame, (err, spriteFrame) => {
  101. this.cityPic.spriteFrame = spriteFrame;
  102. });
  103. cc.loader.loadRes('./map/' + 'unlocked', cc.SpriteFrame, (err, spriteFrame) => {
  104. this.stateSprite.spriteFrame = spriteFrame;
  105. });
  106. cb();
  107. });
  108. },
  109. // update (dt) {},
  110. });