Browse Source

取消当前武器槽

greg 4 years ago
parent
commit
adaaa9b40b

+ 7 - 7
assets/d3d/gunFire/zhuodan.fbx.meta

@@ -80,12 +80,12 @@
         "events": []
       }
     },
-    "a55e7": {
+    "adacb": {
       "importer": "gltf-embeded-image",
-      "uuid": "7c735b05-1052-417a-bab4-49dbefdbb9fc@a55e7",
+      "uuid": "7c735b05-1052-417a-bab4-49dbefdbb9fc@adacb",
       "displayName": "",
-      "id": "a55e7",
-      "name": "5555.png.image",
+      "id": "adacb",
+      "name": "file2.image",
       "ver": "1.0.2",
       "imported": true,
       "files": [
@@ -118,7 +118,7 @@
         "premultiplyAlpha": false,
         "anisotropy": 1,
         "isUuid": true,
-        "imageUuidOrDatabaseUri": "7c735b05-1052-417a-bab4-49dbefdbb9fc@a55e7"
+        "imageUuidOrDatabaseUri": "7c735b05-1052-417a-bab4-49dbefdbb9fc@adacb"
       }
     },
     "826f3": {
@@ -141,8 +141,8 @@
   "userData": {
     "imageMetas": [
       {
-        "name": "5555.png",
-        "uri": "7c735b05-1052-417a-bab4-49dbefdbb9fc@a55e7"
+        "name": "file2",
+        "uri": "7c735b05-1052-417a-bab4-49dbefdbb9fc@adacb"
       }
     ],
     "animationImportSettings": [

+ 8 - 5
assets/resources/ui/components/WeaponCell.prefab

@@ -639,7 +639,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0.039,
-      "y": 2.978,
+      "y": -2.982,
       "z": 0
     },
     "_lrot": {
@@ -676,7 +676,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 22.25,
-      "height": 45.2
+      "height": 25.2
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -704,7 +704,7 @@
     },
     "_sharedMaterial": null,
     "_useOriginalSize": true,
-    "_string": "15\n",
+    "_string": "15",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 20,
@@ -1342,7 +1342,7 @@
   },
   {
     "__type__": "cc.UITransformComponent",
-    "_name": "",
+    "_name": "Selected<UITransformComponent>",
     "_objFlags": 0,
     "node": {
       "__id__": 38
@@ -1363,7 +1363,7 @@
   },
   {
     "__type__": "cc.SpriteComponent",
-    "_name": "",
+    "_name": "Selected<SpriteComponent>",
     "_objFlags": 0,
     "node": {
       "__id__": 38
@@ -1441,6 +1441,9 @@
       "__id__": 1
     },
     "_enabled": true,
+    "useing": {
+      "__id__": 38
+    },
     "levelLabel": {
       "__id__": 21
     },

+ 60 - 61
assets/scripts/games/models/GameModel.ts

@@ -30,22 +30,16 @@ export class GameModel extends DataModel {
     /**
      * 当前武器格子
      */
-    private __currentWeaponCell: WeaponCell;
+    currentWeaponCell: WeaponCell;
 
     constructor() {
         super();
     }
 
     /**
- * 设置默认属性
- */
+     * 设置默认属性
+     */
     SetDefaultPropertys(): void {
-        //默认武器
-        this.__currentWeaponCell = new WeaponCell();
-        this.__currentWeaponCell.cellId = -1;
-        this.__currentWeaponCell.lastOutputTime = director.getCurrentTime();
-        this.__currentWeaponCell.weaponId = 10101;
-
         //默认关卡
         this.currentLevel = 1;
         //默认栅栏
@@ -65,6 +59,8 @@ export class GameModel extends DataModel {
             weaponCell.lastOutputTime = 0;
             this.__weaponCells.push(weaponCell);
         }
+        //默认武器
+        this.currentWeaponCell=this.__weaponCells[0];
 
         //保存到本地
         this.SaveToLoacl();
@@ -101,9 +97,6 @@ export class GameModel extends DataModel {
                 result += weaponCell.weaponConfig.earnings;
             }
         });
-        if (this.__currentWeaponCell.weaponId >= 0) {
-            result += this.__currentWeaponCell.weaponConfig.earnings;
-        }
         return result;
     }
 
@@ -113,7 +106,7 @@ export class GameModel extends DataModel {
     get earningsInterval(): number {
         return GameConfigManager.getGlobalValue("earningsInterval");
     }
-
+    
     /**
      * 收益间隔时间
      */
@@ -162,16 +155,19 @@ export class GameModel extends DataModel {
         this.DataChanged = true;
     }
 
-    /**
-     * 设置当前武器ID
-     */
-    set currentWeaponId(value: number) {
-        this.__currentWeaponCell.weaponId = value;
-        this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
-    }
+    // /**
+    //  * 设置当前武器ID
+    //  */
+    // set currentWeaponId(value: number) {
+    //     this.__currentWeaponCell.weaponId = value;
+    //     this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
+    // }
 
     get currentWeaponId(): number {
-        return this.__currentWeaponCell.weaponId;
+        if(this.currentWeaponCell==null){
+            return -1;
+        }
+        return this.currentWeaponCell.weaponId;
     }
 
     /**
@@ -213,10 +209,18 @@ export class GameModel extends DataModel {
             weChat.branchAnalytics(branchIdType.Synthetic, String(level))
         }
 
-        //如果比手上的好
-        if (this.__currentWeaponCell.weaponConfig && newWeaponConfig.level > this.__currentWeaponCell.weaponConfig.level) {
-            this.EquipWeapon(targetCellId);
-            return;
+        if(this.currentWeaponCell!=null){
+            if(this.currentWeaponCell==sourceCell){
+                this.currentWeaponCell=null;
+                this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
+            }else if(this.currentWeaponCell==targetCell){
+                this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
+                //如果比手上的好
+                if(this.currentWeaponCell.weaponConfig && newWeaponConfig.level > this.currentWeaponCell.weaponConfig.level){
+                    this.EquipWeapon(targetCell);
+                    return;
+                }
+            }
         }
         this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
 
@@ -244,41 +248,33 @@ export class GameModel extends DataModel {
      * @param cellId 
      */
     public RemoveWeapon(cellId: number): void {
-        for (let index = 0; index < this.__weaponCells.length; index++) {
-            const element = this.__weaponCells[index];
-            if (element.cellId == cellId) {
-                element.weaponId = -1;
-                this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
-                return;
-            }
+        let cell:WeaponCell=this.FindCell(cellId);
+        cell.weaponId=-1;
+        if(cell==this.currentWeaponCell){
+            this.currentWeaponCell=null;
+            this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
         }
+        this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
     }
 
-    /**
-     * 卸下武器
-     */
-    public UnequipWeapon(cellId: number): void {
-        let id: number = this.__currentWeaponCell.weaponId;
-        this.currentWeaponId = -1;
-        this.__currentWeaponCell.lastOutputTime = 0;
-        this.AddWeapon(cellId, id);
-    }
+    // /**
+    //  * 卸下武器
+    //  */
+    // public UnequipWeapon(cellId: number): void {
+    //     let id: number = this.__currentWeaponCell.weaponId;
+    //     this.currentWeaponId = -1;
+    //     this.__currentWeaponCell.lastOutputTime = 0;
+    //     this.AddWeapon(cellId, id);
+    // }
 
     /**
      * 装配武器
      * @param weaponId 
      */
-    public EquipWeapon(sourceCellId: number): void {
-        let cell: WeaponCell = this.FindCell(sourceCellId);
-        if (cell == null) {
-            throw new Error("找不到武器槽:" + sourceCellId);
-        }
-        let oldWeaponId = this.currentWeaponId;
-        this.currentWeaponId = cell.weaponId;
-        this.__currentWeaponCell.lastOutputTime = cell.lastOutputTime;
-        cell.weaponId = oldWeaponId;
-        cell.lastOutputTime = 0;
+    public EquipWeapon(sourceCell:WeaponCell): void {
+        this.currentWeaponCell=sourceCell;
         this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.WeaponCell);
+        this.DispatchEvent(DataModelEventType.PROPERTY_CHANGED, GamePropertys.currentWeaponId);
     }
 
     /**
@@ -432,15 +428,7 @@ export class GameModel extends DataModel {
 
     protected OnReadByLocal(data: any): void {
         let currentTime: number = director.getCurrentTime();
-        //当前武器格
-        this.__currentWeaponCell = new WeaponCell();
-        for (const key in data.currentWeaponCell) {
-            if (Object.prototype.hasOwnProperty.call(data.currentWeaponCell, key) && Object.prototype.hasOwnProperty.call(this.__currentWeaponCell, key)) {
-                const element = data.currentWeaponCell[key];
-                this.__currentWeaponCell[key] = element;
-            }
-        }
-        this.__currentWeaponCell.lastOutputTime = currentTime;
+        
         //武器格子
         let weaponCells: any[] = data.weaponCells;
         this.__weaponCells = [];
@@ -458,6 +446,13 @@ export class GameModel extends DataModel {
                 this.__weaponCells.push(weaponCell);
             });
         }
+
+        //当前武器格
+        if(data.currentWeaponCellId>0){
+            this.currentWeaponCell=this.FindCell(data.currentWeaponCellId);
+            this.currentWeaponCell.lastOutputTime = currentTime;
+        }
+
         //自动合成Buffer剩余时间
         if (data.autoSynthesisTime > 0) {
             let buffer: AutoSyntheticBuffer = new AutoSyntheticBuffer("AutoSynthesis", data.autoSynthesisTime);
@@ -472,7 +467,11 @@ export class GameModel extends DataModel {
 
     protected OnSaveToLocal(data: any): void {
         data.weaponCells = this.__weaponCells;
-        data.currentWeaponCell = this.__currentWeaponCell;
+        if(this.currentWeaponCell!=null){
+            data.currentWeaponCellId = this.currentWeaponCell.cellId;
+        }else{
+            data.currentWeaponCellId=-1;
+        }
         //自动合成Buffer剩余时间
         let buffers: IBuffer[] = BufferManager.GetBufferGroup("AutoSynthesis");
         if (buffers != null && buffers.length > 0) {

+ 34 - 20
assets/scripts/games/ui/prepares/PrepareMediator.ts

@@ -193,9 +193,7 @@ export class PrepareMediator extends GUIMediator {
             let modelNode: Node = find("ModelView", this.node);
             this.modelView = modelNode.getComponent(ModelComponent);
         }
-        this.modelView.node.active = true;
 
-        let weaponConfig: any = GameConfigManager.GetWeaponConfig(GameModel.single.currentWeaponId);
         if (this.modelPrefab) {
             this.modelView.mesh = null;
             let target=this.modelView.materials[0];
@@ -207,26 +205,38 @@ export class PrepareMediator extends GUIMediator {
             loader.release(deps);
             this.modelPrefab=null;
         }
-        loader.loadRes(weaponConfig.prefab, Prefab, (err, prefab) => {
-            if (err) {
-                console.error("加载武器出错");
+
+        //武器为空
+        if(GameModel.single.currentWeaponId<0){
+            this.modelView.node.active = false;
+            this.gunNameLabel.string="";
+            this.weaponInfoLabel.string="";
+            return;
+        }else{
+            this.modelView.node.active = true;
+            let weaponConfig: any = GameConfigManager.GetWeaponConfig(GameModel.single.currentWeaponId);
+            loader.loadRes(weaponConfig.prefab, Prefab, (err, prefab) => {
+                if (err) {
+                    console.error("加载武器出错");
+                }
+                this.modelPrefab = prefab;
+                this.prefabInstance = instantiate(prefab);
+                this.prefabModelComponent = this.prefabInstance.getComponentInChildren(ModelComponent);
+                //更换贴图
+                let source = this.prefabModelComponent.materials[0];
+                let target = this.modelView.materials[0];
+                let texture = source.getProperty("mainTexture");
+                target.setProperty("mainTexture", texture);
+                //更换模型
+                this.modelView.mesh = this.prefabModelComponent.mesh;
+            });
+            if (this.gunNameLabel != null) {
+                this.gunNameLabel.string = weaponConfig.name;
             }
-            this.modelPrefab = prefab;
-            this.prefabInstance = instantiate(prefab);
-            this.prefabModelComponent = this.prefabInstance.getComponentInChildren(ModelComponent);
-            //更换贴图
-            let source = this.prefabModelComponent.materials[0];
-            let target = this.modelView.materials[0];
-            let texture = source.getProperty("mainTexture");
-            target.setProperty("mainTexture", texture);
-            //更换模型
-            this.modelView.mesh = this.prefabModelComponent.mesh;
-        });
-        if (this.gunNameLabel != null) {
-            this.gunNameLabel.string = weaponConfig.name;
+            //描述
+            this.weaponInfoLabel.string=weaponConfig.desc;
         }
-        //描述
-        this.weaponInfoLabel.string=weaponConfig.desc;
+        
     }
 
     OnHide(): void {
@@ -417,6 +427,10 @@ export class PrepareMediator extends GUIMediator {
     }
 
     StartGame(): void {
+        if(GameModel.single.currentWeaponCell==null||GameModel.single.currentWeaponId<0){
+            NoticeManager.ShowPrompt("请装配武器后再试!");
+            return;
+        }
         GUIManager.single.Show(UIConst.FREE_FENCE_UI);
         // if(GameConfigManager.GetNextFenceID(GameModel.single.currentFenceId)>0){
             // GUIManager.single.Show(UIConst.FREE_FENCE_UI);

+ 1 - 1
assets/scripts/games/ui/prepares/WeaponCellListView.ts

@@ -200,7 +200,7 @@ export class WeaponCellListView extends BaseView{
                     GameModel.single.RemoveWeapon(this.currentSelect.cellId);
                 }else if(this.HitNode(this.mediator.equipWeaponNode,this.tempPos))
                 {//装配武器
-                    GameModel.single.EquipWeapon(this.currentSelect.cellId);
+                    GameModel.single.EquipWeapon(this.currentSelect);
                 }
             }else{
                 if(this.startNode!=target){

+ 11 - 0
assets/scripts/games/ui/prepares/WeaponCellScript.ts

@@ -10,6 +10,12 @@ const { ccclass, property } = _decorator;
 @ccclass('WeaponCellScript')
 export class WeaponCellScript extends Component {
     
+
+    @property({
+        type:Node
+    })
+    useing:Node=null;
+
     @property({
         type:LabelComponent
     })
@@ -163,6 +169,11 @@ export class WeaponCellScript extends Component {
             this.imgState3.active=true;
             this.imgState2.active=true;
         }
+        if(GameModel.single.currentWeaponCell==this.weaponCell){
+            this.useing.active=true;
+        }else{
+            this.useing.active=false;
+        }
     }
 
     update (deltaTime: number) {