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,
contentNode: cc.Node,
_tabIndex: 1,
tabIndex: {
get: function () {
return this._tabIndex;
},
set: function (value) {
this._tabIndex = value;
}
},
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.node.height = Global.winSize.height;
if (Global.winSize.height <= 1000) {
this.contentNode.height = 800;
}
this.titleRichText.string = `${GameModule.userInfo.diamond}`;
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 = `${GameModule.userInfo.diamond}`;
});
this.handelStoreShowRedDot();
GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelStoreShowRedDot);
this.userIdLabel.string = `ID ${Global.user.uid}`
},
start () {
},
onDestroy () {
GameEvent.off('store_buy_coin_updateDiamond', this);
GameEvent.off(GameNotificationKey.GameRedDotUpdate, this);
},
update (dt) {
},
handelStoreShowRedDot() {
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});
});
})
},
});