CityItem.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const DWTool = require('../utils/DWTool');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. cityPic: cc.Sprite,
  6. incomeSpeedLabel: cc.Label,
  7. indexLabel: cc.Label,
  8. stateSprite: cc.Sprite,
  9. incomeLayout: cc.Node,
  10. line: cc.Node,
  11. currentIndicator: cc.Node,
  12. stateSelected: cc.SpriteFrame,
  13. stateLock: cc.SpriteFrame,
  14. stateUnlock: cc.SpriteFrame,
  15. },
  16. // onLoad () {},
  17. init(info, incomeSpeed) {
  18. this.info = info;
  19. this.indexLabel.string = info.id;
  20. switch (info.state) {
  21. case 1:
  22. this.stateFrame = this.stateSelected;
  23. this.picPath = info.picId + '_';
  24. this.indexLabel.node.active = true;
  25. this.currentIndicator.active = true;
  26. break;
  27. case 2:
  28. this.stateFrame = this.stateUnlock;
  29. this.picPath = info.picId + '_';
  30. this.indexLabel.node.active = true;
  31. this.currentIndicator.active = false;
  32. break;
  33. default:
  34. this.stateFrame = this.stateLock;
  35. this.picPath = info.picId;
  36. this.indexLabel.node.active = false;
  37. this.currentIndicator.active = false;
  38. break;
  39. }
  40. cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
  41. this.cityPic.spriteFrame = spriteFrame;
  42. this.currentIndicator.y = this.cityPic.node.height / 2 - this.currentIndicator.height / 2;
  43. });
  44. this.stateSprite.spriteFrame = this.stateFrame;
  45. if (incomeSpeed > 0) {
  46. this.incomeLayout.active = true;
  47. this.incomeSpeedLabel.string = `${DWTool.coinParse(incomeSpeed)}/天`;
  48. } else {
  49. this.incomeLayout.active = false;
  50. }
  51. if (this.node.x === -110) {
  52. this.line.x = -60;
  53. this.line.scaleX = 1;
  54. } else {
  55. this.line.x = 60;
  56. this.line.scaleX = -1;
  57. }
  58. if (info.state == 2) {
  59. this.line.active = true;
  60. } else {
  61. this.line.active = false;
  62. }
  63. },
  64. start() {
  65. },
  66. setState(state) {
  67. switch (state) {
  68. case 1:
  69. this.stateFrame = this.stateSelected;
  70. this.picPath = this.info.picId + '_';
  71. this.indexLabel.node.active = true;
  72. break;
  73. case 2:
  74. this.stateFrame = this.stateUnlock;
  75. this.picPath = this.info.picId + '_';
  76. this.indexLabel.node.active = true;
  77. break;
  78. default:
  79. this.stateFrame = this.stateLock;
  80. this.picPath = this.info.picId;
  81. this.indexLabel.node.active = false;
  82. break;
  83. }
  84. let end = cc.callFunc(() => {
  85. this.stateSprite.spriteFrame = this.stateFrame;
  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. this.stateSprite.spriteFrame = this.stateUnlock;
  104. cb();
  105. });
  106. },
  107. // update (dt) {},
  108. });