StarHandbookItem.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const DWTool = require("../utils/DWTool");
  2. const ArtistManager = require("../utils/ArtistManager");
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. starDarkNode: cc.Node,
  8. starHeadNode: cc.Node,
  9. countNode: cc.Node,
  10. countLabel: cc.Label,
  11. isUnlocked: {
  12. get: function() {
  13. if (!this._isUnlocked) {
  14. this._isUnlocked = false;
  15. }
  16. return this._isUnlocked;
  17. },
  18. set: function(value) {
  19. this._isUnlocked = value;
  20. if (this._isUnlocked) {
  21. this.starHeadNode.active = true;
  22. this.countNode.active = true;
  23. this.starDarkNode.active = false;
  24. } else {
  25. this.starHeadNode.active = false;
  26. this.countNode.active = false;
  27. this.starDarkNode.active = true;
  28. }
  29. }
  30. },
  31. },
  32. // LIFE-CYCLE CALLBACKS:
  33. onLoad () {
  34. this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  35. this.showStarDesc();
  36. }, 1000, true), this);
  37. GameEvent.on(GameNotificationKey.StarEnterRoom, this, (starId) => {
  38. this.starEnterRoom(starId);
  39. });
  40. GameEvent.on(GameNotificationKey.StarLeaveRoom, this, (starId) => {
  41. this.starLeaveRoom(starId);
  42. });
  43. GameEvent.on(GameNotificationKey.AllStarLeaveRoom, this, this.allStarLeaveRoom);
  44. },
  45. onDestroy() {
  46. GameEvent.off(GameNotificationKey.StarEnterRoom, this);
  47. GameEvent.off(GameNotificationKey.StarLeaveRoom, this);
  48. GameEvent.off(GameNotificationKey.AllStarLeaveRoom, this);
  49. },
  50. start () {
  51. },
  52. configData(starInfo) {
  53. this.starInfo = starInfo;
  54. if (starInfo.starCount > 0 ) {
  55. this.isUnlocked = true;
  56. this.countLabel.string = `${starInfo.starRoomCount}/${starInfo.starCount}`;
  57. } else {
  58. this.isUnlocked = false;
  59. }
  60. let imageId = 50000 + starInfo.starId;
  61. ArtistManager.loadStarBlackAvatarSpriteFrame(imageId, this.starDarkNode.getComponent('cc.Sprite'));
  62. ArtistManager.loadStarAvatarSpriteFrame(imageId, this.starHeadNode.getComponent('cc.Sprite'));
  63. },
  64. showStarDesc() {
  65. if (this.isUnlocked) {
  66. GameEvent.fire('show_star_desc', this.starInfo);
  67. }
  68. },
  69. starEnterRoom(starId) {
  70. if (this.starInfo.starId == starId) {
  71. this.countLabel.string = `${this.starInfo.starRoomCount}/${this.starInfo.starCount}`;
  72. }
  73. },
  74. starLeaveRoom(starId) {
  75. if (this.starInfo.starId == starId) {
  76. this.countLabel.string = `${this.starInfo.starRoomCount}/${this.starInfo.starCount}`;
  77. }
  78. },
  79. allStarLeaveRoom() {
  80. // if (this.starInfo.starCount > 0 ) {
  81. // this.isUnlocked = true;
  82. // this.countLabel.string = `0/${this.starInfo.starCount}`;
  83. // } else {
  84. // this.isUnlocked = false;
  85. // }
  86. this.countLabel.string = `0/${this.starInfo.starCount}`;
  87. }
  88. // update (dt) {},
  89. });