Quellcode durchsuchen

添加点击领取道具

SunnyLinSD vor 6 Jahren
Ursprung
Commit
280ae5aef4

+ 2 - 2
assets/prefabs/level_home_prop_item.prefab

@@ -114,7 +114,7 @@
     "_position": {
       "__type__": "cc.Vec2",
       "x": 0.2,
-      "y": -10
+      "y": -8
     },
     "_skewX": 0,
     "_skewY": 0,
@@ -204,7 +204,7 @@
     "_scaleY": 1,
     "_position": {
       "__type__": "cc.Vec2",
-      "x": -0.2,
+      "x": 0,
       "y": -33.9
     },
     "_skewX": 0,

+ 1 - 1
assets/scripts/levelHome/LevelHome.js

@@ -271,7 +271,7 @@ cc.Class({
         .then((buildingItems) => {
 
             for (const buildingId in buildingItems) {
-
+                
                 let itemScript;
                 let filterList = this.buildings.filter( item => item.buildingInfo.buildingId === parseInt(buildingId) ) || [];
                 if (filterList.length > 0) { itemScript = filterList[0]; }

+ 1 - 1
assets/scripts/levelHome/LevelHomeItem.js

@@ -385,7 +385,7 @@ cc.Class({
             let propNode = cc.instantiate(this.propPrefab)
             this.propScript = propNode.getComponent('LevelHomePropItem')
             this.isHasProp = true;
-            this.propScript.init(propData, () => {
+            this.propScript.init(this.buildingInfo.buildingId, propData, () => {
                 this.propScript = null;
                 this.isHasProp = false; 
             });

+ 14 - 3
assets/scripts/levelHome/LevelHomePropItem.js

@@ -1,5 +1,5 @@
 
-const itemData = require("../data/item");
+const HomeApi = require("../net/HomeApi");
 const DWTool = require("../utils/DWTool");
 
 cc.Class({
@@ -12,8 +12,8 @@ cc.Class({
         nameRichText: cc.RichText,
     },
 
-    init(propData, pickupCallback) {
-        console.log(propData);
+    init(buildingId, propData, pickupCallback) {
+        this.buildingId = buildingId;
         DWTool.loadResSpriteFrame(`./item/${propData.id}`)
         .then((spriteFrame) => {
             this.propSprite.spriteFrame = spriteFrame;
@@ -36,6 +36,17 @@ cc.Class({
 
         this.node.y = -26;
         this.node.x = 150;
+
+        this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
+            HomeApi.itemCollect(this.buildingId, () => {
+
+                
+                this.pickupCallback();
+                this.node.destroy();
+            }, (err) => {
+                console.log(err);
+            })
+        }, 1000, true), this);
     },
 
     showAnimation() {

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

@@ -208,6 +208,16 @@ class HomeApi {
         Api.httpGet(this.setRequestBody('/item/getBuildingItems.do', {}, success, fail));
     }
 
+    /**
+     * 收集产出的道具
+     * @param {*} buildingId 
+     * @param {*} success 
+     * @param {*} fail 
+     */
+    static itemCollect(buildingId, success, fail) {
+        Api.httpPost(this.setRequestBody('/item/collect.do', {'buildingId':buildingId}, success, fail))
+    }
+
     // 生成一个 RequestBody, 总是要写重复代码, 太恶心了
     static setRequestBody(url, data, success, fail) {
         let requestBody = {