greg пре 4 година
родитељ
комит
00f6928f75

+ 2 - 0
assets/resources/configs/Fence.json

@@ -1,6 +1,7 @@
 [
     {
         "id": 30001,
+        "name": "栅栏1",
         "prefab": "d3d/barriers/fences/Fence01",
         "idleAnimation": "Idle",
         "idleAnimationSpeed": 1,
@@ -14,6 +15,7 @@
     },
     {
         "id": 30101,
+        "name": "栅栏2",
         "prefab": "d3d/barriers/fences/Fence02",
         "idleAnimation": "Idle",
         "idleAnimationSpeed": 1,

+ 3 - 1
assets/resources/ui/ShopUI.prefab

@@ -4403,7 +4403,9 @@
     "WeaponList": {
       "__id__": 50
     },
-    "FenceListItemRenderPrefab": null,
+    "FenceListItemRenderPrefab": {
+      "__uuid__": "2e4fb7ee-ed49-4803-bf1d-a503fd5903f2"
+    },
     "FenceListContext": {
       "__id__": 37
     },

+ 112 - 236
assets/resources/ui/components/FenceListItemRender.prefab

@@ -29,29 +29,29 @@
         "__id__": 25
       },
       {
-        "__id__": 33
+        "__id__": 29
       },
       {
-        "__id__": 48
+        "__id__": 44
       },
       {
-        "__id__": 63
+        "__id__": 59
       },
       {
-        "__id__": 78
+        "__id__": 74
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 83
+        "__id__": 79
       },
       {
-        "__id__": 84
+        "__id__": 80
       }
     ],
     "_prefab": {
-      "__id__": 85
+      "__id__": 81
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -612,7 +612,7 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 16,
+      "x": -7,
       "y": -3,
       "z": 0
     },
@@ -784,80 +784,28 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "Level",
+    "_name": "HpLabel",
     "_objFlags": 0,
     "_parent": {
       "__id__": 1
     },
-    "_children": [
-      {
-        "__id__": 26
-      }
-    ],
-    "_active": true,
-    "_components": [
-      {
-        "__id__": 30
-      },
-      {
-        "__id__": 31
-      }
-    ],
-    "_prefab": {
-      "__id__": 32
-    },
-    "_lpos": {
-      "__type__": "cc.Vec3",
-      "x": -252,
-      "y": -44,
-      "z": 0
-    },
-    "_lrot": {
-      "__type__": "cc.Quat",
-      "x": 0,
-      "y": 0,
-      "z": 0,
-      "w": 1
-    },
-    "_lscale": {
-      "__type__": "cc.Vec3",
-      "x": 1,
-      "y": 1,
-      "z": 1
-    },
-    "_layer": 33554432,
-    "_euler": {
-      "__type__": "cc.Vec3",
-      "x": 0,
-      "y": 0,
-      "z": 0
-    },
-    "_id": ""
-  },
-  {
-    "__type__": "cc.Node",
-    "_name": "LevelLabel",
-    "_objFlags": 0,
-    "_parent": {
-      "__id__": 25
-    },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 27
+        "__id__": 26
       },
       {
-        "__id__": 28
+        "__id__": 27
       }
     ],
     "_prefab": {
-      "__id__": 29
+      "__id__": 28
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -2,
-      "y": 0.532,
+      "x": -261,
+      "y": 33.532,
       "z": 0
     },
     "_lrot": {
@@ -887,18 +835,18 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 26
+      "__id__": 25
     },
     "_enabled": true,
     "_priority": 0,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 24.47,
+      "width": 110.09,
       "height": 45.2
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
-      "x": 0.5,
+      "x": 0,
       "y": 0.5
     },
     "_id": ""
@@ -908,7 +856,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 26
+      "__id__": 25
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -922,7 +870,7 @@
     },
     "_sharedMaterial": null,
     "_useOriginalSize": true,
-    "_string": "15\n",
+    "_string": "HP:150000\n",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 22,
@@ -954,78 +902,6 @@
       "serializable": false
     }
   },
-  {
-    "__type__": "cc.UITransformComponent",
-    "_name": "Level<UITransformComponent>",
-    "_objFlags": 0,
-    "node": {
-      "__id__": 25
-    },
-    "_enabled": true,
-    "_priority": 0,
-    "_contentSize": {
-      "__type__": "cc.Size",
-      "width": 34,
-      "height": 34
-    },
-    "_anchorPoint": {
-      "__type__": "cc.Vec2",
-      "x": 0.5,
-      "y": 0.5
-    },
-    "_id": ""
-  },
-  {
-    "__type__": "cc.SpriteComponent",
-    "_name": "Level<SpriteComponent>",
-    "_objFlags": 0,
-    "node": {
-      "__id__": 25
-    },
-    "_enabled": true,
-    "_srcBlendFactor": 2,
-    "_dstBlendFactor": 4,
-    "_color": {
-      "__type__": "cc.Color",
-      "r": 255,
-      "g": 255,
-      "b": 255,
-      "a": 255
-    },
-    "_sharedMaterial": null,
-    "_spriteFrame": {
-      "__uuid__": "19b502d6-daf1-4a35-a9b0-e32919962a2a@f9941"
-    },
-    "_type": 0,
-    "_fillType": 0,
-    "_sizeMode": 0,
-    "_fillCenter": {
-      "__type__": "cc.Vec2",
-      "x": 0,
-      "y": 0
-    },
-    "_fillStart": 0,
-    "_fillRange": 0,
-    "_isTrimmedMode": true,
-    "_useGrayscale": false,
-    "_atlas": null,
-    "_id": ""
-  },
-  {
-    "__type__": "cc.PrefabInfo",
-    "root": {
-      "__id__": 1
-    },
-    "asset": {
-      "__id__": 0
-    },
-    "fileId": "adcxKqx9pFmrTHU8vsCQ2l",
-    "sync": false,
-    "_synced": {
-      "default": false,
-      "serializable": false
-    }
-  },
   {
     "__type__": "cc.Node",
     "_name": "FreeBuyButton",
@@ -1035,29 +911,29 @@
     },
     "_children": [
       {
-        "__id__": 34
+        "__id__": 30
       },
       {
-        "__id__": 38
+        "__id__": 34
       }
     ],
     "_active": false,
     "_components": [
       {
-        "__id__": 42
+        "__id__": 38
       },
       {
-        "__id__": 43
+        "__id__": 39
       },
       {
-        "__id__": 44
+        "__id__": 40
       },
       {
-        "__id__": 46
+        "__id__": 42
       }
     ],
     "_prefab": {
-      "__id__": 47
+      "__id__": 43
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1092,20 +968,20 @@
     "_name": "Label",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 33
+      "__id__": 29
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 35
+        "__id__": 31
       },
       {
-        "__id__": 36
+        "__id__": 32
       }
     ],
     "_prefab": {
-      "__id__": 37
+      "__id__": 33
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1140,7 +1016,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 34
+      "__id__": 30
     },
     "_enabled": true,
     "_priority": 0,
@@ -1161,7 +1037,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 34
+      "__id__": 30
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1212,20 +1088,20 @@
     "_name": "goldIcon",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 33
+      "__id__": 29
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 39
+        "__id__": 35
       },
       {
-        "__id__": 40
+        "__id__": 36
       }
     ],
     "_prefab": {
-      "__id__": 41
+      "__id__": 37
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1260,7 +1136,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 38
+      "__id__": 34
     },
     "_enabled": true,
     "_priority": 0,
@@ -1281,7 +1157,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 38
+      "__id__": 34
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1332,7 +1208,7 @@
     "_name": "FreeBuyButton<UITransformComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 33
+      "__id__": 29
     },
     "_enabled": true,
     "_priority": 0,
@@ -1353,7 +1229,7 @@
     "_name": "FreeBuyButton<SpriteComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 33
+      "__id__": 29
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1389,12 +1265,12 @@
     "_name": "FreeBuyButton<ButtonComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 33
+      "__id__": 29
     },
     "_enabled": true,
     "clickEvents": [
       {
-        "__id__": 45
+        "__id__": 41
       }
     ],
     "_interactable": true,
@@ -1442,7 +1318,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 33
+      "__id__": 29
     },
     "_id": ""
   },
@@ -1452,7 +1328,7 @@
       "__id__": 1
     },
     "component": "",
-    "_componentId": "28650QIQf9OHqY5dQxD7SPy",
+    "_componentId": "7f54eOO7GhEQa2eM1dQkx8p",
     "handler": "VideoBuy",
     "customEventData": ""
   },
@@ -1461,7 +1337,7 @@
     "_name": "GlodBuyButton<WidgetComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 33
+      "__id__": 29
     },
     "_enabled": true,
     "_alignFlags": 34,
@@ -1508,29 +1384,29 @@
     },
     "_children": [
       {
-        "__id__": 49
+        "__id__": 45
       },
       {
-        "__id__": 53
+        "__id__": 49
       }
     ],
     "_active": false,
     "_components": [
       {
-        "__id__": 57
+        "__id__": 53
       },
       {
-        "__id__": 58
+        "__id__": 54
       },
       {
-        "__id__": 59
+        "__id__": 55
       },
       {
-        "__id__": 61
+        "__id__": 57
       }
     ],
     "_prefab": {
-      "__id__": 62
+      "__id__": 58
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1565,20 +1441,20 @@
     "_name": "Label",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 48
+      "__id__": 44
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 50
+        "__id__": 46
       },
       {
-        "__id__": 51
+        "__id__": 47
       }
     ],
     "_prefab": {
-      "__id__": 52
+      "__id__": 48
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1613,7 +1489,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 49
+      "__id__": 45
     },
     "_enabled": true,
     "_priority": 0,
@@ -1634,7 +1510,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 49
+      "__id__": 45
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1685,20 +1561,20 @@
     "_name": "goldIcon",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 48
+      "__id__": 44
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 54
+        "__id__": 50
       },
       {
-        "__id__": 55
+        "__id__": 51
       }
     ],
     "_prefab": {
-      "__id__": 56
+      "__id__": 52
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -1733,7 +1609,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 53
+      "__id__": 49
     },
     "_enabled": true,
     "_priority": 0,
@@ -1754,7 +1630,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 53
+      "__id__": 49
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1805,7 +1681,7 @@
     "_name": "DiamondBuyButton<UITransformComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 48
+      "__id__": 44
     },
     "_enabled": true,
     "_priority": 0,
@@ -1826,7 +1702,7 @@
     "_name": "DiamondBuyButton<SpriteComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 48
+      "__id__": 44
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -1862,12 +1738,12 @@
     "_name": "DiamondBuyButton<ButtonComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 48
+      "__id__": 44
     },
     "_enabled": true,
     "clickEvents": [
       {
-        "__id__": 60
+        "__id__": 56
       }
     ],
     "_interactable": true,
@@ -1915,7 +1791,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 48
+      "__id__": 44
     },
     "_id": ""
   },
@@ -1925,7 +1801,7 @@
       "__id__": 1
     },
     "component": "",
-    "_componentId": "28650QIQf9OHqY5dQxD7SPy",
+    "_componentId": "7f54eOO7GhEQa2eM1dQkx8p",
     "handler": "GlodBuy",
     "customEventData": ""
   },
@@ -1934,7 +1810,7 @@
     "_name": "GlodBuyButton<WidgetComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 48
+      "__id__": 44
     },
     "_enabled": true,
     "_alignFlags": 34,
@@ -1981,29 +1857,29 @@
     },
     "_children": [
       {
-        "__id__": 64
+        "__id__": 60
       },
       {
-        "__id__": 68
+        "__id__": 64
       }
     ],
     "_active": false,
     "_components": [
       {
-        "__id__": 72
+        "__id__": 68
       },
       {
-        "__id__": 73
+        "__id__": 69
       },
       {
-        "__id__": 74
+        "__id__": 70
       },
       {
-        "__id__": 76
+        "__id__": 72
       }
     ],
     "_prefab": {
-      "__id__": 77
+      "__id__": 73
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -2038,20 +1914,20 @@
     "_name": "Label",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 63
+      "__id__": 59
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 65
+        "__id__": 61
       },
       {
-        "__id__": 66
+        "__id__": 62
       }
     ],
     "_prefab": {
-      "__id__": 67
+      "__id__": 63
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -2086,7 +1962,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 64
+      "__id__": 60
     },
     "_enabled": true,
     "_priority": 0,
@@ -2107,7 +1983,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 64
+      "__id__": 60
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -2158,20 +2034,20 @@
     "_name": "goldIcon",
     "_objFlags": 0,
     "_parent": {
-      "__id__": 63
+      "__id__": 59
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 69
+        "__id__": 65
       },
       {
-        "__id__": 70
+        "__id__": 66
       }
     ],
     "_prefab": {
-      "__id__": 71
+      "__id__": 67
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -2206,7 +2082,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 68
+      "__id__": 64
     },
     "_enabled": true,
     "_priority": 0,
@@ -2227,7 +2103,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 68
+      "__id__": 64
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -2278,7 +2154,7 @@
     "_name": "GlodBuyButton<UITransformComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 63
+      "__id__": 59
     },
     "_enabled": true,
     "_priority": 0,
@@ -2299,7 +2175,7 @@
     "_name": "GlodBuyButton<SpriteComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 63
+      "__id__": 59
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -2335,12 +2211,12 @@
     "_name": "GlodBuyButton<ButtonComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 63
+      "__id__": 59
     },
     "_enabled": true,
     "clickEvents": [
       {
-        "__id__": 75
+        "__id__": 71
       }
     ],
     "_interactable": true,
@@ -2388,7 +2264,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 63
+      "__id__": 59
     },
     "_id": ""
   },
@@ -2398,7 +2274,7 @@
       "__id__": 1
     },
     "component": "",
-    "_componentId": "28650QIQf9OHqY5dQxD7SPy",
+    "_componentId": "7f54eOO7GhEQa2eM1dQkx8p",
     "handler": "GlodBuy",
     "customEventData": ""
   },
@@ -2407,7 +2283,7 @@
     "_name": "GlodBuyButton<WidgetComponent>",
     "_objFlags": 0,
     "node": {
-      "__id__": 63
+      "__id__": 59
     },
     "_enabled": true,
     "_alignFlags": 34,
@@ -2456,17 +2332,17 @@
     "_active": false,
     "_components": [
       {
-        "__id__": 79
+        "__id__": 75
       },
       {
-        "__id__": 80
+        "__id__": 76
       },
       {
-        "__id__": 81
+        "__id__": 77
       }
     ],
     "_prefab": {
-      "__id__": 82
+      "__id__": 78
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -2501,7 +2377,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 78
+      "__id__": 74
     },
     "_enabled": true,
     "_priority": 0,
@@ -2522,7 +2398,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 78
+      "__id__": 74
     },
     "_enabled": true,
     "_srcBlendFactor": 2,
@@ -2558,7 +2434,7 @@
     "_name": "",
     "_objFlags": 0,
     "node": {
-      "__id__": 78
+      "__id__": 74
     },
     "_enabled": true,
     "_opacity": 100,
@@ -2611,29 +2487,29 @@
     "icon": {
       "__id__": 10
     },
-    "levelLabel": {
-      "__id__": 28
+    "hpLabel": {
+      "__id__": 27
     },
     "nameLabel": {
       "__id__": 20
     },
     "freeBuyButton": {
-      "__id__": 44
+      "__id__": 40
     },
     "freeBuyButtonLabel": {
-      "__id__": 36
+      "__id__": 32
     },
     "diamondBuyButton": {
-      "__id__": 59
+      "__id__": 55
     },
     "diamondBuyButtonLabel": {
-      "__id__": 51
+      "__id__": 47
     },
     "GlodBuyButton": {
-      "__id__": 74
+      "__id__": 70
     },
     "GlodBuyButtonLabel": {
-      "__id__": 66
+      "__id__": 62
     },
     "_id": ""
   },

+ 94 - 2
assets/scripts/games/ui/shops/FenceItemRenderScript.ts

@@ -1,4 +1,9 @@
-import { _decorator, Component, Node, SpriteComponent, LabelComponent, ButtonComponent } from 'cc';
+import { _decorator, Component, Node, SpriteComponent, LabelComponent, ButtonComponent, loader, SpriteFrame } from 'cc';
+import { NoticeManager } from '../../../engines/notices/NoticeManager';
+import StringUtils from '../../../engines/utils/StringUtils';
+import { PlatformManager } from '../../../Platform/PlatformManager';
+import GameConfigManager from '../../models/GameConfigManager';
+import { GameModel } from '../../models/GameModel';
 const { ccclass, property } = _decorator;
 
 @ccclass('FenceItemRenderScript')
@@ -11,7 +16,7 @@ export class FenceItemRenderScript extends Component {
     @property({
         type:LabelComponent
     })
-    levelLabel:LabelComponent=null;
+    hpLabel:LabelComponent=null;
 
     @property({
         type:LabelComponent
@@ -49,6 +54,7 @@ export class FenceItemRenderScript extends Component {
     })
     GlodBuyButtonLabel:LabelComponent=null;
 
+    private data:any;
 
     start () {
         // Your initialization goes here.
@@ -56,7 +62,93 @@ export class FenceItemRenderScript extends Component {
 
 
     UpdateItemRender(data:any):void{
+        this.data=data;
+        let config:any=GameConfigManager.GetFenceConfig(data.id);
+        //图标
+        loader.loadRes(config.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
+            if(err!=null){
+                console.log("加载图标出错:"+config.icon);
+                return;
+            }
+            this.icon.spriteFrame=asset;
+        })
+        //等级
+        this.hpLabel.string="HP:"+config.hp.toString();
+        //名称
+        this.nameLabel.string=config.name;
+        let price:number;
+
+        if(data.id<=GameModel.single.currentFenceId){
+            this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
+        }else{
+            //buyType 购买方式 0金币购买  1宝石购买 2看广告购买
+            if(data.buyType==0){//金币购买
+                this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
+                this.GlodBuyButton.node.active=true;
+                price=config.buyConsume;
+                this.GlodBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
+            }else if(data.buyType==1){//宝石购买
+                this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
+                this.diamondBuyButton.node.active=true;
+                price=config.buyConsume;
+                this.diamondBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
+            }else{//广告购买
+                this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
+                this.freeBuyButton.node.active=true;
+            }
+        }
+    }
+
+
+    /**
+     * 金币购买
+     */
+    GlodBuy():void{
+        if(this.BuyFence()){
+            NoticeManager.ShowPrompt("购买成功。");
+        }
+    }
+
+    /**
+     * 钻石购买
+     */
+    DiamondBuy():void{
+        if(this.BuyFence()){
+            NoticeManager.ShowPrompt("购买成功。");
+        }
+    }
+
+    /**
+     * 视频购买
+     */
+    VideoBuy():void{
+        PlatformManager.showRewardedVideo(()=>{
+            if(this.BuyFence()){
+                NoticeManager.ShowPrompt("购买成功。");
+            }
+        }, ()=>{
+            NoticeManager.ShowPrompt("购买失败。");
+        })
+    }
+
 
+    private BuyFence():boolean{
+        //金钱购买
+        if(this.data.buyType==0){
+            if(GameModel.single.gold<this.data.buyConsume){
+                NoticeManager.ShowPrompt("金币不足!");
+                return false;
+            }
+            GameModel.single.gold-=this.data.buyConsume;
+        }else if(this.data.buyType==1){//钻石购买
+            if(GameModel.single.diamond<this.data.buyConsume){
+                NoticeManager.ShowPrompt("钻石不足!");
+                return false;
+            }
+            GameModel.single.diamond-=this.data.buyConsume;
+        }
+        GameModel.single.currentFenceId=this.data.id;
+        return true;
     }
 
     // update (deltaTime: number) {

+ 5 - 1
assets/scripts/games/ui/shops/ShopItemRenderScript.ts

@@ -54,7 +54,7 @@ export class ShopItemRenderScript extends Component {
         type:LabelComponent
     })
     GlodBuyButtonLabel:LabelComponent=null;
-    
+
     @property({
         type:Node
     })
@@ -76,6 +76,10 @@ export class ShopItemRenderScript extends Component {
         let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.data.id);
         //图标
         loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
+            if(err!=null){
+                console.log("加载图标出错:"+weaponConfig.icon);
+                return;
+            }
             this.icon.spriteFrame=asset;
         })
         //等级

+ 41 - 4
assets/scripts/games/ui/shops/ShopMediator.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node, Prefab, LayoutComponent, instantiate, ScrollViewComponent, LabelComponent, ToggleComponent } from 'cc';
+import { _decorator, Component, Node, Prefab, LayoutComponent, instantiate, ScrollViewComponent, LabelComponent, ToggleComponent, JsonAsset } from 'cc';
 import { GUIManager } from '../../../engines/gui/GUIManager';
 import { GUIMediator } from '../../../engines/gui/GUIMediator';
 import { DataModelEventType } from '../../../engines/models/DataModelEventType';
@@ -7,6 +7,7 @@ import GameConfigManager from '../../models/GameConfigManager';
 import { GameModel } from '../../models/GameModel';
 import { GamePropertys } from '../../models/GamePropertys';
 import { UIConst } from '../UIConst';
+import { FenceItemRenderScript } from './FenceItemRenderScript';
 import { ShopItemRenderScript } from './ShopItemRenderScript';
 const { ccclass, property } = _decorator;
 
@@ -66,9 +67,12 @@ export class ShopMediator extends GUIMediator {
      */
     private include:number[]=[];
 
+
+    private showType:number=0;
+
     OnShow(data?:any):void{
         super.OnShow(data);
-        this.SwitchToggle(null,0,true);
+        this.SwitchToggle(null,this.showType,true);
         this.RefreshGlod();
         this.RefreshDiamond();
         this.AddEvent();
@@ -100,6 +104,8 @@ export class ShopMediator extends GUIMediator {
             this.CallNextFrame(this.RefreshGlod.bind(this));
         }else if(key==GamePropertys.diamond){
             this.CallNextFrame(this.RefreshDiamond.bind(this));
+        }else if(key==GamePropertys.currentFenceId){
+            this.CallNextFrame(this.RefreshFenceList.bind(this));
         }
     }
     
@@ -226,6 +232,7 @@ export class ShopMediator extends GUIMediator {
     }
 
     SwitchToggle(target:ToggleComponent,type:number,srollToZ:boolean):void{
+        this.showType=type;
         //枪械
         if(type==0){
             this.WeaponList.node.active=true;
@@ -241,8 +248,38 @@ export class ShopMediator extends GUIMediator {
     /**
      * 刷新栅栏列表
      */
-    private RefreshFenceList(srollToZ:boolean):void{
-
+    private RefreshFenceList(srollToZ:boolean=false):void{
+        let itemView:Node;
+        let jsonAsset:JsonAsset=GameConfigManager.GetConfig("Fence");
+        let jsonConfig:any=jsonAsset.json;
+        let dataList:any[]=jsonConfig;
+        if(dataList.length!=this.FenceListContext.node.children.length){
+            if(dataList.length<this.FenceListContext.node.children.length){
+                //删除多余的
+                while(dataList.length<this.FenceListContext.node.children.length){
+                    this.FenceListContext.node.removeChild(this.FenceListContext.node.children[0]);
+                }
+            }else{
+                //添加缺少的
+                while(dataList.length>this.FenceListContext.node.children.length){
+                    itemView=instantiate(this.FenceListItemRenderPrefab);
+                    this.FenceListContext.node.addChild(itemView);
+                }
+            }
+        }
+        let itemScript:FenceItemRenderScript;
+        let count:number=dataList.length;
+        for (let index = 0; index < count; index++) {
+            itemView=this.FenceListContext.node.children[index];
+            itemScript=itemView.getComponent(FenceItemRenderScript);
+            if(itemScript==null){
+                throw new Error("商城列表项未挂载FenceItemRenderScript脚本!");
+            }
+            itemScript.UpdateItemRender(dataList[index]);
+        }
+        if(srollToZ){
+            this.FenceList.scrollToTop(0.1);
+        }
     }
 
     start () {