StarScrollView.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const ListViewAdapter = require('../utils/TapTapScrollViewAdapter');
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. content: cc.Node,
  7. item: cc.Prefab,
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. onLoad () {},
  11. start () {
  12. },
  13. init(starData) {
  14. let buyGold = starData.buyGold;
  15. let starTypeCount = starData.starTypeCount;
  16. this._userStars = starData.userStars;
  17. this.listAdapter = new ListViewAdapter(this);
  18. this.listAdapter.buyGold = buyGold;
  19. this.listAdapter.start = starTypeCount;
  20. this.listAdapter.updateItems(this._userStars, this.item, 'StarItem');
  21. // for(let i = 0; i < userStars.length; ++i) {
  22. // let starItem = cc.instantiate(this.item);
  23. // starItem.getComponent('StarItem').init(userStars[i], buyGold, starTypeCount);
  24. // this.content.addChild(starItem);
  25. // }
  26. this.listAdapter.isBuying = false;
  27. GameEvent.on("Star_Buy_success", this, (areaType, buyGold, starTypeCount) => {
  28. this.listAdapter.buyGold = buyGold;
  29. this.listAdapter.starTypeCount = starTypeCount;
  30. // ///说明满足明星和房间的条件 已经解锁 那么只需要判断金币进行预约了
  31. // if (this._isStarLocked == false && this._isRoomLocked == false) {
  32. // /// 如果金币满足
  33. // this.setUpUseBtnBg(TapTapTool.compare(GameModule.userInfo.gold, this._buyGold));
  34. // this.starUseTitleRichText.string = `<color=#ffffff>签约</c><br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._buyGold)}</c>`;
  35. // }
  36. /// 如果是明星所需种类
  37. for (let i = 0; i < this._userStars.length; ++ i) {
  38. let starData = this._userStars[i];
  39. if (starData.itemId == 102) {
  40. this.listAdapter.starTypeCount = starTypeCount;
  41. /// 如果是明星需要个数
  42. } else if (starData.itemId == 101) {
  43. /// 地区需要明星多少个
  44. } else {
  45. /// 如果该地区与需要的这个地区匹配
  46. if (starData.itemId == areaType) {
  47. starData.areaStarCount += 1;
  48. }
  49. }
  50. }
  51. GameEvent.fire('StarItem_updateUI');
  52. });
  53. //// 明星放入房间
  54. GameEvent.on(GameNotificationKey.StarEnterRoom, this, (starId, roomId) => {
  55. for (let i = 0; i < this._userStars.length; ++ i) {
  56. let starData = this._userStars[i];
  57. if (starData.starId == starId) {
  58. starData.starRoomCount += 1;
  59. break;
  60. }
  61. }
  62. GameEvent.fire('StarItem_updateUI');
  63. });
  64. /// 单个明星离开的id
  65. GameEvent.on(GameNotificationKey.StarLeaveRoom, this, (starId) => {
  66. for (let i = 0; i < this._userStars.length; ++ i) {
  67. let starData = this._userStars[i];
  68. if (starData.starId == starId) {
  69. starData.starRoomCount -= 1;
  70. break;
  71. }
  72. }
  73. GameEvent.fire('StarItem_updateUI');
  74. });
  75. /// 所有的明星都收回
  76. GameEvent.on (GameNotificationKey.AllStarLeaveRoom, this, () => {
  77. for (let i = 0; i < this._userStars.length; ++ i) {
  78. let starData = this._userStars[i];
  79. starData.starRoomCount = 0;
  80. }
  81. GameEvent.fire('StarItem_updateUI');
  82. });
  83. },
  84. onDestroy() {
  85. GameEvent.off(GameNotificationKey.AllStarLeaveRoom, this);
  86. GameEvent.off(GameNotificationKey.StarLeaveRoom, this);
  87. GameEvent.off(GameNotificationKey.StarEnterRoom, this);
  88. GameEvent.off('Star_Buy_success', this);
  89. },
  90. onScroll() {
  91. if (this.listAdapter != undefined) {
  92. this.listAdapter.update();
  93. }
  94. },
  95. // update (dt) {
  96. // if (this.listAdapter != undefined) {
  97. // this.listAdapter.update(dt);
  98. // }
  99. // },
  100. });