StarHandbookItem.js 3.1 KB

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