123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- const StoreApi = require('../net/StoreApi');
- const DWTool = require("../utils/DWTool");
- const GameModule = require("../utils/GameModule");
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- cc.Class({
- extends: cc.Component,
- properties: {
- /// 四个button Sprite
- // topBtnArr: [cc.Button],
- topBtnSpriteArr: [cc.Sprite],
- titleRichText: cc.RichText,
- contentArr: [cc.Node],
- tabSlectedSpriteFrames: [cc.SpriteFrame],
- tabNormalSpriteFrames: [cc.SpriteFrame],
- userIdLabel: cc.Label,
- coinRedNode: cc.Node,
- diamandRedNode: cc.Node,
- _tabIndex: 1,
- tabIndex: {
- get: function () {
- return this._tabIndex;
- },
- set: function (value) {
- this._tabIndex = value;
- }
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.titleRichText.string = `<img src='skill_diamond'/><outline color=#ffffff width=2><b><color=#6E3011>${GameModule.userInfo.diamond}</c></b></outline>`;
- this._componentsString = ['StoreRecommend', 'StoreDiamond', 'StoreCoin', 'StoreGift'];
- this.contentArr[0].getComponent(this._componentsString[0]).init(this);
- this._lastSelectedIndex = 0;
- GameEvent.on('store_buy_coin_updateDiamond', this, () => {
- this.titleRichText.string = `<img src='skill_diamond'/><outline color=#ffffff width=2><b><color=#6E3011>${GameModule.userInfo.diamond}</c></b></outline>`;
- });
- this.handelShowRedDot();
- GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot);
- this.userIdLabel.string = `ID ${Global.user.uid}`
- },
- start () {
- },
- onDestroy () {
- GameEvent.off('store_buy_coin_updateDiamond', this);
- GameEvent.off(GameNotificationKey.GameRedDotUpdate. this);
- },
- update (dt) {
- },
- handelShowRedDot() {
- if (Global._redTypes == null || Global._redTypes == undefined || Global._redTypes.length == 0) {
- this.coinRedNode.active = false;
- this.diamandRedNode.active = false;
- return;
- }
- let redTypes = Global._redTypes;
-
- this.coinRedNode.active = redTypes.indexOf(GameRedDot.storeCoin) != -1;
- let diamandActive = redTypes.indexOf(GameRedDot.storeDiamond) != -1
- this.diamandRedNode.active = diamandActive;
- },
- closeBtnAction() {
- GameModule.audioMng.playClickButton();
- this.node.destroy();
- },
- //// 点击第几个tab eventData 1 推荐 2 砖石 3 金币 4 礼包
- tabButtonAction(event, eventData) {
- GameModule.audioMng.playClickButton();
- let index = eventData - 1;
- /// 说明点击的一样,那什么都不用做嘛
- if (index === this._lastSelectedIndex) {
- return
- }
- if (index >= 0 && index < this._componentsString.length) {
- this.contentArr[index].getComponent(this._componentsString[index]).init(this);
- this.contentArr[index].active = true;
- this.contentArr[this._lastSelectedIndex].active = false;
- this.topBtnSpriteArr[this._lastSelectedIndex].spriteFrame = this.tabNormalSpriteFrames[this._lastSelectedIndex];
- this.topBtnSpriteArr[index].spriteFrame = this.tabSlectedSpriteFrames[index];
- this._lastSelectedIndex = index;
- }
- },
- /// 网络请求
- getShopsByType(typeId) {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- StoreApi.getShopsByType(typeId, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- })
- },
- });
|