CityItem.js 3.6 KB

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