Explorar el Código

支持显示道具

SunnyLinSD hace 6 años
padre
commit
0d422ef5ab

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 199 - 135
assets/prefabs/level_home_item.prefab


+ 271 - 0
assets/prefabs/level_home_prop_item.prefab

@@ -0,0 +1,271 @@
+[
+  {
+    "__type__": "cc.Prefab",
+    "_name": "",
+    "_objFlags": 0,
+    "_native": "",
+    "data": {
+      "__id__": 1
+    },
+    "optimizationPolicy": 0,
+    "asyncLoadAssets": false
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "level_home_prop_item",
+    "_objFlags": 0,
+    "_parent": null,
+    "_children": [
+      {
+        "__id__": 2
+      },
+      {
+        "__id__": 5
+      }
+    ],
+    "_tag": -1,
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 8
+      }
+    ],
+    "_prefab": {
+      "__id__": 9
+    },
+    "_id": "",
+    "_opacity": 255,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_cascadeOpacityEnabled": true,
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 70,
+      "height": 90
+    },
+    "_rotationX": 0,
+    "_rotationY": 0,
+    "_scaleX": 1,
+    "_scaleY": 1,
+    "_position": {
+      "__type__": "cc.Vec2",
+      "x": 0,
+      "y": 0
+    },
+    "_skewX": 0,
+    "_skewY": 0,
+    "_localZOrder": 0,
+    "_globalZOrder": 0,
+    "_opacityModifyRGB": false,
+    "groupIndex": 0
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "New Sprite",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 1
+    },
+    "_children": [],
+    "_tag": -1,
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 3
+      }
+    ],
+    "_prefab": {
+      "__id__": 4
+    },
+    "_id": "",
+    "_opacity": 255,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_cascadeOpacityEnabled": true,
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 117,
+      "height": 90
+    },
+    "_rotationX": 0,
+    "_rotationY": 0,
+    "_scaleX": 0.6,
+    "_scaleY": 0.6,
+    "_position": {
+      "__type__": "cc.Vec2",
+      "x": 0.2,
+      "y": -10
+    },
+    "_skewX": 0,
+    "_skewY": 0,
+    "_localZOrder": 0,
+    "_globalZOrder": 0,
+    "_opacityModifyRGB": false,
+    "groupIndex": 0
+  },
+  {
+    "__type__": "cc.Sprite",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 2
+    },
+    "_enabled": true,
+    "_spriteFrame": {
+      "__uuid__": "c88453bc-0295-4040-9c7f-4bc39693c6db"
+    },
+    "_type": 0,
+    "_sizeMode": 1,
+    "_fillType": 0,
+    "_fillCenter": {
+      "__type__": "cc.Vec2",
+      "x": 0,
+      "y": 0
+    },
+    "_fillStart": 0,
+    "_fillRange": 0,
+    "_isTrimmedMode": true,
+    "_srcBlendFactor": 770,
+    "_dstBlendFactor": 771,
+    "_atlas": null
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__uuid__": "b4e10a0b-2964-468e-9f6d-36f620391617"
+    },
+    "fileId": "d19hG3vshN+7rs4vd9oLZD",
+    "sync": false
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "New RichText",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 1
+    },
+    "_children": [],
+    "_tag": -1,
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 6
+      }
+    ],
+    "_prefab": {
+      "__id__": 7
+    },
+    "_id": "",
+    "_opacity": 255,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_cascadeOpacityEnabled": true,
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 9,
+      "height": 20
+    },
+    "_rotationX": 0,
+    "_rotationY": 0,
+    "_scaleX": 1,
+    "_scaleY": 1,
+    "_position": {
+      "__type__": "cc.Vec2",
+      "x": -0.2,
+      "y": -33.9
+    },
+    "_skewX": 0,
+    "_skewY": 0,
+    "_localZOrder": 0,
+    "_globalZOrder": 0,
+    "_opacityModifyRGB": false,
+    "groupIndex": 0
+  },
+  {
+    "__type__": "cc.RichText",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 5
+    },
+    "_enabled": true,
+    "_N$string": "<b><color=#ffffff>0</c></b>",
+    "_N$horizontalAlign": 1,
+    "_N$fontSize": 16,
+    "_N$font": null,
+    "_N$maxWidth": 0,
+    "_N$lineHeight": 20,
+    "_N$imageAtlas": null,
+    "_N$handleTouchEvent": true
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__uuid__": "b4e10a0b-2964-468e-9f6d-36f620391617"
+    },
+    "fileId": "bajOwS8JlEqoHRBqwymKQB",
+    "sync": false
+  },
+  {
+    "__type__": "adb216TXydKNYGBcS+QD5uV",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "propSprite": {
+      "__id__": 3
+    },
+    "nameRichText": {
+      "__id__": 6
+    }
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__uuid__": "b4e10a0b-2964-468e-9f6d-36f620391617"
+    },
+    "fileId": "9bz2vnqPtGBKmpFoer+GZH",
+    "sync": false
+  }
+]

+ 7 - 0
assets/prefabs/level_home_prop_item.prefab.meta

@@ -0,0 +1,7 @@
+{
+  "ver": "1.0.0",
+  "uuid": "b4e10a0b-2964-468e-9f6d-36f620391617",
+  "optimizationPolicy": "AUTO",
+  "asyncLoadAssets": false,
+  "subMetas": {}
+}

+ 83 - 30
assets/scripts/levelHome/LevelHome.js

@@ -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);
     },
 
 });

+ 21 - 0
assets/scripts/levelHome/LevelHomeItem.js

@@ -135,8 +135,12 @@ cc.Class({
 
         coinWrap: cc.Node,
 
+        propWrap: cc.Node,
+
         coinPrefab: cc.Prefab,
 
+        propPrefab: cc.Prefab,
+
         countDown: {
             get: function () {
                 if (!this._countDown) {
@@ -187,6 +191,7 @@ cc.Class({
         this._currentTime = 0;
         this.isFirstLoad = true;
         this.humanList = [];
+        this.isHasProp = false;
         this.updateSkeletion.node.active = false;
 
         this._rateProgressWidth = this.rateProgressBar.barSprite.node.width;
@@ -374,6 +379,22 @@ cc.Class({
         }
     },
 
+    configProp(propData) {
+
+        if (!this.isHasProp) {
+            let propNode = cc.instantiate(this.propPrefab)
+            this.propScript = propNode.getComponent('LevelHomePropItem')
+            this.isHasProp = true;
+            this.propScript.init(propData, () => {
+                this.propScript = null;
+                this.isHasProp = false; 
+            });
+            this.propWrap.addChild(propNode);  
+        } else {
+            this.propScript.updateProp(propData)
+        }
+    },
+
     /**
      * Public Method, 用来设置建筑背景图
      * @param {number} cityId 城市id 

+ 99 - 0
assets/scripts/levelHome/LevelHomePropItem.js

@@ -0,0 +1,99 @@
+
+const itemData = require("../data/item");
+const DWTool = require("../utils/DWTool");
+
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+       
+        propSprite: cc.Sprite,
+
+        nameRichText: cc.RichText,
+    },
+
+    init(propData, pickupCallback) {
+        console.log(propData);
+        DWTool.loadResSpriteFrame(`./item/${propData.id}`)
+        .then((spriteFrame) => {
+            this.propSprite.spriteFrame = spriteFrame;
+        }).catch((err) => {
+            console.log(err);
+        });
+
+        this.nameRichText.string = `<b><color=#ffffff>X${propData.count}</c></b>`;
+
+        this.pickupCallback = pickupCallback;
+    },
+
+    updateProp(propData) {
+        console.log(propData);
+        this.nameRichText.string = `<b><color=#ffffff>X${propData.count}</c></b>`;
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+    onLoad () {
+
+        this.node.y = -26;
+        this.node.x = 150;
+    },
+
+    showAnimation() {
+
+        if (this.isPlaying) { return; }
+
+        this.node.stopAllActions();
+
+        this.node.active = true;
+        this.isPlayed = true;
+        this.isPlaying = true;
+
+        let jumpHeight = 175;
+        let duration = 0.3;
+
+        let animationArray = [];
+
+        let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
+        let moveAction2 = cc.moveBy(duration, 0, -95).easing(cc.easeCubicActionIn());
+
+        animationArray.push(moveAction1);
+        animationArray.push(moveAction2);
+
+        while(jumpHeight > 0.1) {
+            jumpHeight = jumpHeight - (jumpHeight / 3);
+            duration = duration - (duration / 3);
+            let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
+            let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
+            animationArray.push(upAction);
+            animationArray.push(downAction);
+        }
+
+        let callback = cc.callFunc(() => {
+            this.isPlaying = false;
+        });
+
+        animationArray.push(callback);
+
+        this.node.runAction(cc.sequence(animationArray));
+    },
+
+    updateAnimation() {
+        if (this.isPlaying) { return; }
+
+        this.node.active = true
+
+        this.node.y = -28;
+
+        this.node.stopAllActions();
+        
+        this.isPlaying = true;
+
+        let upAction = cc.moveBy(0.1, 0, 30);
+        let downAction = cc.moveBy(0.1, 0, -30);
+
+        let callback = cc.callFunc(() => {
+            this.isPlaying = false;
+        });
+        this.coinNode.runAction(cc.sequence(upAction, downAction, callback));
+    },
+});

+ 9 - 0
assets/scripts/levelHome/LevelHomePropItem.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "adb21e93-5f27-4a35-8181-712f900f9b95",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 9 - 0
assets/scripts/net/HomeApi.js

@@ -198,6 +198,15 @@ class HomeApi {
         };
         Api.httpPost(this.setRequestBody(url, data, success, fail));
     }
+    
+    /**
+     * 获取道具产出列表
+     * @param {*} success 
+     * @param {*} fail 
+     */
+    static getBuildingItems(success, fail) {
+        Api.httpGet(this.setRequestBody('/item/getBuildingItems.do', {}, success, fail));
+    }
 
     // 生成一个 RequestBody, 总是要写重复代码, 太恶心了
     static setRequestBody(url, data, success, fail) {

+ 3 - 0
assets/scripts/utils/GameEnum.js

@@ -209,6 +209,9 @@ const GameNotificationKey = cc.Enum({
     HandleOfflineIncomeAnim: 'HandleOfflineIncomeAnim',
 
     LevelHomeSpeedUp: 'LevelHomeSpeedUp',
+
+    // 接受到levelhomeitem里的道具更新
+    ReceiveLevelHomeItemPropUpdate: 'ReceiveLevelHomeItemPropUpdate',
 });
 
 var LevelHomeFriendItemStyle = cc.Enum({

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio