StoreContent.js 4.1 KB

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