StarScrollView.js 4.6 KB

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