StoreContent.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const StoreApi = require('../net/StoreApi');
  2. const DWTool = require("../utils/DWTool");
  3. const GameModule = require("../utils/GameModule");
  4. const GameRedDot = require('../utils/GameEnum').GameRedDot;
  5. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. /// 四个button Sprite
  10. // topBtnArr: [cc.Button],
  11. topBtnSpriteArr: [cc.Sprite],
  12. titleRichText: cc.RichText,
  13. contentArr: [cc.Node],
  14. tabSlectedSpriteFrames: [cc.SpriteFrame],
  15. tabNormalSpriteFrames: [cc.SpriteFrame],
  16. userIdLabel: cc.Label,
  17. coinRedNode: cc.Node,
  18. diamandRedNode: cc.Node,
  19. contentNode: cc.Node,
  20. _tabIndex: 1,
  21. tabIndex: {
  22. get: function () {
  23. return this._tabIndex;
  24. },
  25. set: function (value) {
  26. this._tabIndex = value;
  27. }
  28. },
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad () {
  32. this.node.height = Global.winSize.height;
  33. if (Global.winSize.height <= 1000) {
  34. this.contentNode.height = 800;
  35. }
  36. this.titleRichText.string = `<img src='skill_diamond'/><outline color=#ffffff width=2><b><color=#6E3011>${GameModule.userInfo.diamond}</c></b></outline>`;
  37. this._componentsString = ['StoreRecommend', 'StoreDiamond', 'StoreCoin', 'StoreGift'];
  38. this.contentArr[0].getComponent(this._componentsString[0]).init(this);
  39. this._lastSelectedIndex = 0;
  40. GameEvent.on('store_buy_coin_updateDiamond', this, () => {
  41. this.titleRichText.string = `<img src='skill_diamond'/><outline color=#ffffff width=2><b><color=#6E3011>${GameModule.userInfo.diamond}</c></b></outline>`;
  42. });
  43. this.handelStoreShowRedDot();
  44. GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelStoreShowRedDot);
  45. this.userIdLabel.string = `ID ${Global.user.uid}`
  46. },
  47. start () {
  48. },
  49. onDestroy () {
  50. GameEvent.off('store_buy_coin_updateDiamond', this);
  51. GameEvent.off(GameNotificationKey.GameRedDotUpdate, this);
  52. },
  53. update (dt) {
  54. },
  55. handelStoreShowRedDot() {
  56. if (Global._redTypes == null || Global._redTypes == undefined || Global._redTypes.length == 0) {
  57. this.coinRedNode.active = false;
  58. this.diamandRedNode.active = false;
  59. return;
  60. }
  61. let redTypes = Global._redTypes;
  62. this.coinRedNode.active = redTypes.indexOf(GameRedDot.storeCoin) != -1;
  63. let diamandActive = redTypes.indexOf(GameRedDot.storeDiamond) != -1
  64. this.diamandRedNode.active = diamandActive;
  65. },
  66. closeBtnAction() {
  67. GameModule.audioMng.playClickButton();
  68. this.node.destroy();
  69. },
  70. //// 点击第几个tab eventData 1 推荐 2 砖石 3 金币 4 礼包
  71. tabButtonAction(event, eventData) {
  72. GameModule.audioMng.playClickButton();
  73. let index = eventData - 1;
  74. /// 说明点击的一样,那什么都不用做嘛
  75. if (index === this._lastSelectedIndex) {
  76. return
  77. }
  78. if (index >= 0 && index < this._componentsString.length) {
  79. this.contentArr[index].getComponent(this._componentsString[index]).init(this);
  80. this.contentArr[index].active = true;
  81. this.contentArr[this._lastSelectedIndex].active = false;
  82. this.topBtnSpriteArr[this._lastSelectedIndex].spriteFrame = this.tabNormalSpriteFrames[this._lastSelectedIndex];
  83. this.topBtnSpriteArr[index].spriteFrame = this.tabSlectedSpriteFrames[index];
  84. this._lastSelectedIndex = index;
  85. }
  86. },
  87. /// 网络请求
  88. getShopsByType(typeId) {
  89. return new Promise((resolve, reject) => {
  90. // 获取目标用户的建筑
  91. StoreApi.getShopsByType(typeId, (respondData) => {
  92. resolve(respondData);
  93. }, (code, msg) => {
  94. reject({code, msg});
  95. });
  96. })
  97. },
  98. });