|
@@ -85,6 +85,34 @@ cc.Class({
|
|
|
this.bottomScript = bottomNode.getComponent('LevelHomeBottom'); this.bottomScript.init(this.cityId);
|
|
|
this.scrollView.content.addChild(bottomNode);
|
|
|
|
|
|
+
|
|
|
+ this.setEventLisenter();
|
|
|
+
|
|
|
+ // 监听小游戏隐藏到后台事件
|
|
|
+ if (CC_WECHATGAME) {
|
|
|
+ wx.onHide(() => {
|
|
|
+ this.wxHide = true
|
|
|
+ // 离线收益计算重置
|
|
|
+ this.showOffLineUI = true
|
|
|
+ let lastTime = new Date().getTime()
|
|
|
+ cc.sys.localStorage.setItem('offlineLastTime', lastTime);
|
|
|
+
|
|
|
+ // 退出前立刻调用一次上报
|
|
|
+ GameModule.userInfo.doReport()
|
|
|
+ })
|
|
|
+
|
|
|
+ wx.onShow(() => {
|
|
|
+ if (this.wxHide) {
|
|
|
+ this.refreshTheme();
|
|
|
+ this.getNetworkData();
|
|
|
+ this.wxHide = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ setEventLisenter() {
|
|
|
+
|
|
|
this.scrollView.node.on("scrolling", (event) => {
|
|
|
|
|
|
if (this.scrollView._isOutOfBoundary()) {
|
|
@@ -124,29 +152,17 @@ cc.Class({
|
|
|
|
|
|
GameEvent.on(GameNotificationKey.ResetLevelHomePaddingBottom, this, () => {
|
|
|
this.resetPaddingBottom();
|
|
|
- })
|
|
|
-
|
|
|
- // 监听小游戏隐藏到后台事件
|
|
|
- if (CC_WECHATGAME) {
|
|
|
- wx.onHide(() => {
|
|
|
- this.wxHide = true
|
|
|
- // 离线收益计算重置
|
|
|
- this.showOffLineUI = true
|
|
|
- let lastTime = new Date().getTime()
|
|
|
- cc.sys.localStorage.setItem('offlineLastTime', lastTime);
|
|
|
-
|
|
|
- // 退出前立刻调用一次上报
|
|
|
- GameModule.userInfo.doReport()
|
|
|
- })
|
|
|
+ });
|
|
|
|
|
|
- wx.onShow(() => {
|
|
|
- if (this.wxHide) {
|
|
|
- this.refreshTheme();
|
|
|
- this.getNetworkData();
|
|
|
- this.wxHide = false
|
|
|
+ GameEvent.on(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, this, (props) => {
|
|
|
+ for (const key in props) {
|
|
|
+ if (temp.hasOwnProperty(key)) {
|
|
|
+ const element = props[key];
|
|
|
+ console.log(element);
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -189,15 +205,10 @@ cc.Class({
|
|
|
this.scrollView.scrollToBottom(0.0);
|
|
|
},
|
|
|
|
|
|
- // 用来访问好友家园时, 重置scrollView位置
|
|
|
- onEnable() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
getNetworkData(callback) {
|
|
|
|
|
|
- // 获取目标用户的建筑
|
|
|
- HomeApi.getUserBuildings(this.uid, this.cityId, (responseData) => {
|
|
|
+ this.getUserBuildings()
|
|
|
+ .then((responseData) => {
|
|
|
|
|
|
// 清空数据
|
|
|
this.buildingInfos = [];
|
|
@@ -252,9 +263,48 @@ cc.Class({
|
|
|
// 离线收益处理
|
|
|
this.configOffIncome(sortArray, offlineGrossIncome)
|
|
|
|
|
|
+ return this.getBuildingItems();
|
|
|
+ })
|
|
|
+ .then((buildingItems) => {
|
|
|
+
|
|
|
+ for (const buildingId in buildingItems) {
|
|
|
|
|
|
- }, (error) => {
|
|
|
- console.log("error: " + error);
|
|
|
+ let itemScript;
|
|
|
+ let filterList = this.buildings.filter( item => item.buildingInfo.buildingId === parseInt(buildingId) ) || [];
|
|
|
+ if (filterList.length > 0) { itemScript = filterList[0]; }
|
|
|
+
|
|
|
+ if (buildingItems.hasOwnProperty(buildingId)) {
|
|
|
+ let prop = buildingItems[buildingId];
|
|
|
+ itemScript.configProp(prop);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getUserBuildings() {
|
|
|
+
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ // 获取目标用户的建筑
|
|
|
+ HomeApi.getUserBuildings(this.uid, this.cityId, (responseData) => {
|
|
|
+ resolve(responseData);
|
|
|
+ }, (error) => {
|
|
|
+ reject(error);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getBuildingItems() {
|
|
|
+
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ HomeApi.getBuildingItems((buildingItems) => {
|
|
|
+ resolve(buildingItems);
|
|
|
+ }, (err) => {
|
|
|
+ reject(err);
|
|
|
+ })
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -345,6 +395,9 @@ cc.Class({
|
|
|
clearInterval(this.residentTipShowTimer);
|
|
|
}
|
|
|
GameEvent.off(GameNotificationKey.showCatFlyAnimation, this);
|
|
|
+ GameEvent.off(GameNotificationKey.ReloadLevelHomeData, this);
|
|
|
+ GameEvent.off(GameNotificationKey.ResetLevelHomePaddingBottom, this);
|
|
|
+ GameEvent.off(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, this);
|
|
|
},
|
|
|
|
|
|
});
|