123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- const StarApi = require('../net/StarApi');
- const GameModule = require('../utils/GameModule');
- const {GameNotificationKey, StarType} = require('../utils/GameEnum');
- const AlertManager = require('../utils/AlertManager');
- var Promise = require('../lib/es6-promise').Promise;
- cc.Class({
- extends: cc.Component,
- properties: {
- content: cc.Node,
- //
- starItemPrefab: cc.Prefab,
- scrollView: cc.ScrollView,
- starLayout: cc.Layout,
- //
- progressBar: cc.ProgressBar,
- countLabel: cc.Label,
- percentRichText: cc.RichText,
- //
- descNode: cc.Node,
- //底部信息
- discountRichText: cc.RichText,
- discount50Label: cc.Label,
- discount30Label: cc.Label,
- tab: [cc.Node],
- tabIndex: 0,
- recallAllNode: cc.Node
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.isFirst = true;
- if (GameGlobal.winSize.height <= 1000) {
- this.content.height = 800;
- }
- GameEvent.on('show_star_desc', this, (starInfo) => {
- this.showDescView(starInfo);
- });
- this.isRecalling = false;
- this.showGiftBag = _.debounce((array) => {
- AlertManager.showStarGiftBag(array);
- }, 1000, true);
- },
- onDestroy() {
- GameModule.audioMng.playClickButton();
- GameEvent.off('show_star_desc', this);
- },
- start () {
- this.getAllStars().then((respondData) => {
- // console.log(respondData);
- this.configData(respondData);
- }).catch((code) => {
- console.log(code);
- });
- },
- /// 网络请求
- getAllStars() {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- StarApi.getAllStars((respondData) => {
- resolve(respondData);
- }, (errCode, errMsg) => {
- reject(code);
- });
- })
- },
- configData(respondData) {
- this.respondData = respondData;
- if (respondData.userStars.length > 0) {
- // var isUnlockedCount = 0;
- // for (let i = 0; i < respondData.userStars.length; ++i) {
- // let star = respondData.userStars[i];
- // if (star.starCount > 0) {
- // isUnlockedCount++;
- // }
- // }
- //
- // let totalCount = respondData.userStars.length;
- // this.countLabel.string = `${isUnlockedCount}/${totalCount} 已收集的明星`;
- // let percent = (isUnlockedCount/totalCount * 100).toFixed(2);
- // this.percentRichText.string = `<b><outline color=#3d2e1d width=2><color=#ff9600 >${percent}%</color></outline></b>`;
- // this.progressBar.progress = isUnlockedCount/totalCount;
- this._sortStarData();
- this._initTab();
- }
- let percent = parseInt(this.respondData.starZk * 100);
- this.discountRichText.string = `<b><outline color=#3d2e1d width=2>${percent}%</outline></b>`;
- //遍历礼包折扣
- this.discount50Array = [];
- this.discount30Array = [];
- this.discount50 = 0;
- this.discount30 = 0;
- if (this.respondData.userShops.length > 0) {
- for (let i = 0; i < this.respondData.userShops.length; ++i) {
- let shop = this.respondData.userShops[i];
- if (shop.zk == 0.5) {
- this.discount50 += 1;
- this.discount50Array.push(shop);
- } else if (shop.zk == 0.3) {
- this.discount30 += 1;
- this.discount30Array.push(shop);
- }
- }
- }
- this.discount50Label.string = `x ${this.discount50}`;
- this.discount30Label.string = `x ${this.discount30}`;
- },
- //重新筛选数据
- _sortStarData() {
- this.commonStars = [];
- this.drawStars = [];
- this.giftStars = [];
- this.commonUnlocked = 0;
- this.drawUnlocked = 0;
- this.giftUnlocked = 0;
- for (let i = 0; i < this.respondData.userStars.length; ++i) {
- let star = this.respondData.userStars[i];
- switch (star.type) {
- case StarType.Common:
- this.commonStars.push(star);
- if (star.starCount > 0) {
- this.commonUnlocked++;
- }
- break;
- case StarType.Draw:
- this.drawStars.push(star);
- if (star.starCount > 0) {
- this.drawUnlocked++;
- }
- break;
- case StarType.Gift:
- this.giftStars.push(star);
- if (star.starCount > 0) {
- this.giftUnlocked++;
- }
- break;
- default:
- break;
- }
- }
- this.commonTabText = `普通明星\n${this.commonUnlocked}/${this.commonStars.length}`;
- this.drawTabText = `抽奖明星\n${this.drawUnlocked}/${this.drawStars.length}`;
- this.giftTabText = `礼包明星\n${this.giftUnlocked}/${this.giftStars.length}`;
- },
- /**
- * 初始化Tab
- */
- _initTab () {
- for(let i = 0; i < this.tab.length; i++) {
- this.tab[i] = this.tab[i].getComponent('StarHandbookTypeTab');
- if (i == 0) {
- this.tab[i].init(this.commonTabText);
- } else if (i == 1) {
- this.tab[i].init(this.drawTabText);
- } else {
- this.tab[i].init(this.giftTabText);
- }
- }
- this.handleTab(null, this.tabIndex);
- },
- handleTab(event, tabIndex) {
- this.tabIndex = parseInt(tabIndex);
- this.tab.forEach((item, index) => {
- if(this.tabIndex == index) {
- item.show();
- if (this.isFirst) {
- this.isFirst = false
- } else {
- GameModule.audioMng.playClickButton();
- }
- this._refreshListData();
- } else {
- item.hide();
- }
- });
- },
- _refreshListData() {
- this.starLayout.node.removeAllChildren();
- switch (this.tabIndex) {
- case 0:
- for (let i = 0; i < this.commonStars.length; ++i) {
- let star = this.commonStars[i];
- let item = cc.instantiate(this.starItemPrefab);
- item = item.getComponent('StarHandbookItem');
- item.configData(star);
- this.starLayout.node.addChild(item.node);
- let totalCount = this.commonStars.length;
- this.countLabel.string = `${this.commonUnlocked}/${totalCount} 已收集的明星`;
- let percent = (this.commonUnlocked/totalCount * 100).toFixed(2);
- this.percentRichText.string = `<b><outline color=#3d2e1d width=2><color=#ff9600 >${percent}%</color></outline></b>`;
- this.progressBar.progress = this.commonUnlocked/totalCount;
- }
- break;
- case 1:
- for (let i = 0; i < this.drawStars.length; ++i) {
- let star = this.drawStars[i];
- let item = cc.instantiate(this.starItemPrefab);
- item = item.getComponent('StarHandbookItem');
- item.configData(star);
- this.starLayout.node.addChild(item.node);
- let totalCount = this.drawStars.length;
- this.countLabel.string = `${this.drawUnlocked}/${totalCount} 已收集的明星`;
- let percent = (this.drawUnlocked/totalCount * 100).toFixed(2);
- this.percentRichText.string = `<b><outline color=#3d2e1d width=2><color=#ff9600 >${percent}%</color></outline></b>`;
- this.progressBar.progress = this.drawUnlocked/totalCount;
- }
- break;
- case 2:
- for (let i = 0; i < this.giftStars.length; ++i) {
- let star = this.giftStars[i];
- let item = cc.instantiate(this.starItemPrefab);
- item = item.getComponent('StarHandbookItem');
- item.configData(star);
- this.starLayout.node.addChild(item.node);
- let totalCount = this.giftStars.length;
- this.countLabel.string = `${this.giftUnlocked}/${totalCount} 已收集的明星`;
- let percent = (this.giftUnlocked/totalCount * 100).toFixed(2);
- this.percentRichText.string = `<b><outline color=#3d2e1d width=2><color=#ff9600 >${percent}%</color></outline></b>`;
- this.progressBar.progress = this.giftUnlocked/totalCount;
- }
- break;
- default:
- break;
- }
- },
- closeView() {
- this.node.destroy();
- },
- //显示描述信息
- showDescView(starInfo) {
- GameModule.audioMng.playClickButton();
- this.descNode.active = true;
- this.descNode.getComponent('StarHandbookDesc').configData(starInfo);
- },
- closeDescView() {
- GameModule.audioMng.playClickButton();
- this.descNode.active = false;
- },
- refreshData() {
- for (let i = 0; i < this.commonStars.length; ++i) {
- let star = this.commonStars[i];
- star.starRoomCount = 0;
- }
- for (let i = 0; i < this.drawStars.length; ++i) {
- let star = this.drawStars[i];
- star.starRoomCount = 0;
- }
- for (let i = 0; i < this.giftStars.length; ++i) {
- let star = this.giftStars[i];
- star.starRoomCount = 0;
- }
- },
- recallAllStar() {
- GameModule.audioMng.playClickButton();
- if (this.respondData.userStars.length <= 0) {
- return;
- }
- if (this.isRecalling) { return; }
- this.recallAllNode.active = true;
- },
- confirmRecallAll() {
- GameModule.audioMng.playClickButton();
- this.isRecalling = true;
- StarApi.recallAllStar((respondData) => {
- this.isRecalling = false;
- this.refreshData();
- GameEvent.fire(GameNotificationKey.AllStarLeaveRoom);
- this.recallAllNode.active = false;
- }, (code, msg) => {
- this.isRecalling = false;
- GameGlobal.commonAlert.showCommonErrorAlert(`收回失败 \n${msg}`);
- });
- },
- closeRecallAllNode() {
- GameModule.audioMng.playClickButton();
- this.recallAllNode.active = false;
- },
- //tabIndex:0为5折,1为3折数据
- showDiscountGift(event, tabIndex) {
- GameModule.audioMng.playClickButton();
- if (this.respondData == undefined) {
- return;
- }
- if (tabIndex == 0) {
- this.showGiftBag(this.discount50Array);
- } else {
- this.showGiftBag(this.discount30Array);
- }
- },
- // update (dt) {},
- });
|