StoreContent.js 3.8 KB

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