123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- const StarApi = require('../net/StarApi');
- const GameModule = require('../utils/GameModule');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const AlertManager = require('../utils/AlertManager');
- cc.Class({
- extends: cc.Component,
- properties: {
- content: cc.Node,
- //
- starItemPrefab: cc.Prefab,
- starLayout: cc.Layout,
- //
- progressBar: cc.ProgressBar,
- countLabel: cc.Label,
- percentRichText: cc.RichText,
- //
- descNode: cc.Node,
- //底部信息
- discountRichText: cc.RichText,
- discount50Label: cc.Label,
- discount30Label: cc.Label
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- if (Global.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];
- let item = cc.instantiate(this.starItemPrefab);
- item = item.getComponent('StarHandbookItem');
- item.configData(star);
- this.starLayout.node.addChild(item.node);
- 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;
- }
- 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}`;
- },
- 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.respondData.userStars.length; ++i) {
- let star = this.respondData.userStars[i];
- star.starRoomCount = 0;
- }
- },
- recallAllStar() {
- if (this.respondData.userStars.length <= 0) {
- return;
- }
- if (this.isRecalling) { return; }
- this.isRecalling = true;
- StarApi.recallAllStar((respondData) => {
- this.isRecalling = false;
- this.refreshData();
- GameEvent.fire(GameNotificationKey.AllStarLeaveRoom);
- }, (code, msg) => {
- this.isRecalling = false;
- Global.commonAlert.showCommonErrorAlert(`收回失败 \n${msg}`);
- });
- },
- //tabIndex:0为5折,1为3折数据
- showDiscountGift(event, tabIndex) {
- if (this.respondData == undefined) {
- return;
- }
- if (tabIndex == 0) {
- this.showGiftBag(this.discount50Array);
- } else {
- this.showGiftBag(this.discount30Array);
- }
- },
- // update (dt) {},
- });
|