StarScrollView.js 4.6 KB

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