Jelajahi Sumber

英雄数据处理

wujia 6 bulan lalu
induk
melakukan
f0a45792e8

+ 4 - 0
assets/script/game/data/RoleData.ts

@@ -33,6 +33,10 @@ class Data {
         }
     }
 
+    getData(){
+        return this._roles;
+    }
+
     getRoleDataByID(id: string | number): RoleServer {
         if (typeof id === 'number') {
             id = id.toString();

+ 24 - 2
assets/script/game/manager/RoleManager.ts

@@ -1,4 +1,5 @@
 import { LoginMgr } from "../common/LoginManager";
+import { RoleData } from "../data/RoleData";
 
 
 //角色管理器
@@ -11,7 +12,28 @@ export class RoleManager {
         return false;
     }
 
-    static getAllRoleByRace(){
-        let roles = {}
+    static getRolesRaceGroup(){
+        let roles = {};
+        let data = RoleData.getData();
+        for (const key in data) {
+            if (Object.prototype.hasOwnProperty.call(data, key)) {
+                const element = data[key];
+                if (roles[element.conf['Race']]) {
+                    roles[element.conf['Race']].push(element);
+                } else {
+                    roles[element.conf['Race']] = [];
+                    roles[element.conf['Race']].push(element);
+                }
+            }
+        }
+        for (const key in roles) {
+            if (Object.prototype.hasOwnProperty.call(roles, key)) {
+                const element = roles[key];
+                element.sort((a, b) => {
+                    return Number(a.id) < Number(b.id) ? -1 : 1;
+                });
+            }
+        }
+        return roles;
     }
 }

+ 13 - 8
assets/script/game/ui/hero/HeroList.ts

@@ -2,7 +2,8 @@ import { _decorator, Label, Node } from 'cc';
 import { BaseView } from '../../../framework/layer/BaseView';
 import List from '../../../framework/list/List';
 import { StringUtil } from '../../../framework/util/StringUtil';
-import { HeroListItem } from './HeroListItem';
+import { HeroListItem, heroListItemData } from './HeroListItem';
+import { RoleManager } from '../../manager/RoleManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('HeroList')
@@ -13,35 +14,39 @@ export class HeroList extends BaseView {
 	@property({ type: List, tooltip: "滑动容器" })
 	sv: List = null;
 
-	private _herosData = [];
+	private _herosData: Array<heroListItemData> = [];
 	protected onLoad() {
 		super.onLoad();
 		this.titleTx.string = StringUtil.getLanguageData('英雄列表');
+
+		let data = RoleManager.getRolesRaceGroup();
+
 		for (let index = 0; index < 4; index++) {
-			
+			let t: heroListItemData = { race: index, heros: data[index + 1], equips: {} }
+			this._herosData.push(t);
 		}
-		this.sv.numItems = 4;
+		this.sv.numItems = this._herosData.length;
 	}
 
 	protected onDestroy() {
-		
+
 	}
 
 	//UI开打时会调用,如果有初始化代码应该放到此函数
 	onOpen() {
-		
+
 	}
 
 	//UI关闭时会调用,该函数在onDestroy前调用
 	onClose() {
 
 	}
-	
+
 	//框架管理UI层级时会调用,可根据UI情况修改
 	onShow() {
 		super.onShow();
 	}
-	
+
 	//框架管理UI层级时会调用,可根据UI情况修改
 	onHide() {
 		super.onHide();

+ 2 - 2
assets/script/game/ui/hero/HeroListItem.ts

@@ -3,9 +3,9 @@ import { ResKeeper } from '../../../framework/res/ResKeeper';
 const { ccclass, property } = _decorator;
 
 export interface heroListItemData {
-	race: string;
+	race: number;
 	heros: [];
-	equips: [];
+	equips: {};
 }
 
 @ccclass('HeroListItem')

+ 6 - 8
assets/sub_bundle/hero/prefab/HeroList.prefab

@@ -232,7 +232,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 0,
+      "y": 568.5,
       "z": 0
     },
     "_lrot": {
@@ -286,7 +286,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 568.5,
+      "y": 0,
       "z": 0
     },
     "_lrot": {
@@ -10406,9 +10406,7 @@
     "fetterBtnTx": {
       "__id__": 410
     },
-    "heroNode": {
-      "__id__": 29
-    },
+    "herosNode": null,
     "heroModel": {
       "__id__": 30
     },
@@ -10446,7 +10444,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 680,
-      "height": 345
+      "height": 750
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -10530,7 +10528,7 @@
     "_anchorPoint": {
       "__type__": "cc.Vec2",
       "x": 0.5,
-      "y": 0.5
+      "y": 1
     },
     "_id": ""
   },
@@ -10772,7 +10770,7 @@
     "pageChangeEvent": {
       "__id__": 456
     },
-    "_virtual": true,
+    "_virtual": false,
     "cyclic": false,
     "lackCenter": false,
     "lackSlide": false,