Jelajahi Sumber

商城逻辑

greg 4 tahun lalu
induk
melakukan
df0c955e4c

+ 333 - 3
assets/resources/ui/components/ShopListItemRender.prefab

@@ -39,19 +39,22 @@
       },
       {
         "__id__": 57
+      },
+      {
+        "__id__": 71
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 71
+        "__id__": 81
       },
       {
-        "__id__": 72
+        "__id__": 82
       }
     ],
     "_prefab": {
-      "__id__": 73
+      "__id__": 83
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -2275,6 +2278,312 @@
       "serializable": false
     }
   },
+  {
+    "__type__": "cc.Node",
+    "_name": "LockState",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 1
+    },
+    "_children": [
+      {
+        "__id__": 72
+      }
+    ],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 77
+      },
+      {
+        "__id__": 78
+      },
+      {
+        "__id__": 79
+      }
+    ],
+    "_prefab": {
+      "__id__": 80
+    },
+    "_lpos": {
+      "__type__": "cc.Vec3",
+      "x": 227.5,
+      "y": 0,
+      "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": "Label",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 71
+    },
+    "_children": [],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 73
+      },
+      {
+        "__id__": 74
+      },
+      {
+        "__id__": 75
+      }
+    ],
+    "_prefab": {
+      "__id__": 76
+    },
+    "_lpos": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "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.UITransformComponent",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 72
+    },
+    "_enabled": true,
+    "_priority": 0,
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 100,
+      "height": 40
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.LabelComponent",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 72
+    },
+    "_enabled": true,
+    "_srcBlendFactor": 2,
+    "_dstBlendFactor": 4,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 156,
+      "g": 156,
+      "b": 156,
+      "a": 255
+    },
+    "_sharedMaterial": null,
+    "_useOriginalSize": true,
+    "_string": "未解锁",
+    "_horizontalAlign": 1,
+    "_verticalAlign": 1,
+    "_actualFontSize": 30,
+    "_fontSize": 30,
+    "_fontFamily": "Arial",
+    "_lineHeight": 40,
+    "_overflow": 1,
+    "_enableWrapText": false,
+    "_font": null,
+    "_isSystemFontUsed": true,
+    "_isItalic": false,
+    "_isBold": false,
+    "_isUnderline": false,
+    "_cacheMode": 0,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.WidgetComponent",
+    "_name": "Label<WidgetComponent>",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 72
+    },
+    "_enabled": true,
+    "_alignFlags": 18,
+    "_target": null,
+    "_left": 0,
+    "_right": 0,
+    "_top": 0,
+    "_bottom": 0,
+    "_horizontalCenter": 0,
+    "_verticalCenter": 0,
+    "_isAbsLeft": true,
+    "_isAbsRight": true,
+    "_isAbsTop": true,
+    "_isAbsBottom": true,
+    "_isAbsHorizontalCenter": true,
+    "_isAbsVerticalCenter": true,
+    "_originalWidth": 0,
+    "_originalHeight": 0,
+    "_alignMode": 2,
+    "_lockFlags": 0,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__id__": 0
+    },
+    "fileId": "85chJ26XFNhY5qoTNiHIYX",
+    "sync": false,
+    "_synced": {
+      "default": false,
+      "serializable": false
+    }
+  },
+  {
+    "__type__": "cc.UITransformComponent",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 71
+    },
+    "_enabled": true,
+    "_priority": 0,
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 271,
+      "height": 120
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.SpriteComponent",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 71
+    },
+    "_enabled": true,
+    "_srcBlendFactor": 2,
+    "_dstBlendFactor": 4,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_sharedMaterial": null,
+    "_spriteFrame": {
+      "__uuid__": "de2a68fd-64a1-43eb-bfb7-07e8100ada89@f9941"
+    },
+    "_type": 1,
+    "_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.WidgetComponent",
+    "_name": "GlodBuyButton<WidgetComponent>",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 71
+    },
+    "_enabled": true,
+    "_alignFlags": 34,
+    "_target": null,
+    "_left": 0,
+    "_right": 12,
+    "_top": 0,
+    "_bottom": 0,
+    "_horizontalCenter": 0,
+    "_verticalCenter": 0,
+    "_isAbsLeft": true,
+    "_isAbsRight": true,
+    "_isAbsTop": true,
+    "_isAbsBottom": true,
+    "_isAbsHorizontalCenter": true,
+    "_isAbsVerticalCenter": true,
+    "_originalWidth": 0,
+    "_originalHeight": 0,
+    "_alignMode": 2,
+    "_lockFlags": 0,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__id__": 0
+    },
+    "fileId": "c2AA0zSkdENaq6lW/lctYd",
+    "sync": false,
+    "_synced": {
+      "default": false,
+      "serializable": false
+    }
+  },
   {
     "__type__": "cc.UITransformComponent",
     "_name": "",
@@ -2304,6 +2613,27 @@
       "__id__": 1
     },
     "_enabled": true,
+    "icon": {
+      "__id__": 14
+    },
+    "levelLabel": {
+      "__id__": 20
+    },
+    "nameLabel": {
+      "__id__": 27
+    },
+    "freeBuyButton": {
+      "__id__": 40
+    },
+    "diamondBuyButton": {
+      "__id__": 54
+    },
+    "GlodBuyButton": {
+      "__id__": 68
+    },
+    "lockState": {
+      "__id__": 71
+    },
     "_id": ""
   },
   {

+ 67 - 7
assets/scripts/games/ui/shops/ShopItemRenderScript.ts

@@ -1,14 +1,47 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Node, profiler, SpriteComponent, LabelComponent, ButtonComponent, loader, SpriteFrame } from 'cc';
+import GameConfigManager from '../../models/GameConfigManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('ShopItemRenderScript')
 export class ShopItemRenderScript extends Component {
-    /* class member could be defined like this */
-    // dummy = '';
+    
+    @property({
+        type:SpriteComponent
+    })
+    icon:SpriteComponent=null;
+
+    @property({
+        type:LabelComponent
+    })
+    levelLabel:LabelComponent=null;
+
+    @property({
+        type:LabelComponent
+    })
+    nameLabel:LabelComponent=null;
+
+    @property({
+        type:ButtonComponent
+    })
+    freeBuyButton:ButtonComponent=null;
+
+    @property({
+        type:ButtonComponent
+    })
+    diamondBuyButton:ButtonComponent=null;
+
+
+    @property({
+        type:ButtonComponent
+    })
+    GlodBuyButton:ButtonComponent=null;
+
+
+    @property({
+        type:Node
+    })
+    lockState:Node=null;
 
-    /* use `property` decorator if your want the member to be serializable */
-    // @property
-    // serializableDummy = 0;
     
     private data:any;
 
@@ -18,10 +51,37 @@ export class ShopItemRenderScript extends Component {
 
     UpdateItemRender(data:any):void{
         this.data=data;
+        this.RefreshItem();
     }
 
     private RefreshItem():void{
-
+        let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.data.id);
+        //图标
+        loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
+            this.icon.spriteFrame=asset;
+        })
+        //等级
+        this.levelLabel.string=weaponConfig.level;
+        //名称
+        this.nameLabel.string=weaponConfig.name;
+        //state 0 未解锁  1 已解锁
+        if(this.data.state==0){
+            this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
+            this.lockState.active=true;
+        }else{
+            this.lockState.active=false;
+            //buyType 购买方式 0金币购买  1宝石购买 2看广告购买
+            if(this.data.buyType==0){//金币购买
+                this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
+                this.GlodBuyButton.node.active=true;
+            }else if(this.data.buyType==1){//宝石购买
+                this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
+                this.diamondBuyButton.node.active=true;
+            }else{//广告购买
+                this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
+                this.freeBuyButton.node.active=true;
+            }
+        }
     }
 
     // update (deltaTime: number) {

+ 10 - 6
assets/scripts/games/ui/shops/ShopMediator.ts

@@ -108,17 +108,21 @@ export class ShopMediator extends GUIMediator {
                 id:element.id,
                 index:element.index
             }
-            //buyType 购买方式 0金币购买  1宝石购买
-            if(config.diamondPurchaseId==undefined||config.diamondPurchaseId.indexOf(element.id)<0){
+            //buyType 购买方式 0金币购买  1宝石购买 2 视频购买
+            if(config.diamondPurchaseId==undefined){
                 itemData.buyType=0;
-            }else{
+            }else if(config.diamondPurchaseId.indexOf(element.id)>=0){
                 itemData.buyType=1;
+            }else if(config.videoId==undefined){
+                itemData.buyType=0
+            }else if(config.videoId==element.id){
+                itemData.buyType=2;
             }
             //state 0 未解锁  1 已解锁
-            if(unlockLevel<0||weaponConfig.level>=unlockLevel){
-                itemData.state=1;
-            }else{
+            if(unlockLevel<0||weaponConfig.level<unlockLevel){
                 itemData.state=0;
+            }else{
+                itemData.state=1;
             }
             result.push(itemData);
         });