英雄上阵选择 基本完成

This commit is contained in:
2024-12-10 16:44:54 +08:00
parent 9cd72c108e
commit 5fdd6486de
26 changed files with 16811 additions and 12790 deletions

View File

@@ -1,13 +1,13 @@
import { instantiate, Label, Prefab, resources, Sprite, SpriteAtlas } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { HeroSetComp } from "./HeroSetComp";
import { HeroSelectComp } from "./HeroSelectComp";
import { smc } from "../common/SingletonModuleComp";
import { HeroInfo } from "../common/config/heroSet";
/** HeroSet 模块 */
@ecs.register(`HeroSet`)
export class HeroSet extends ecs.Entity {
/** HeroSelect 模块 */
@ecs.register(`HeroSelect`)
export class HeroSelect extends ecs.Entity {
protected init() {
// this.addComponents<ecs.Comp>();
@@ -31,7 +31,7 @@ export class HeroSet extends ecs.Entity {
if(smc.heros[uuid].slv>=3) {slv.getChildByName("s3").active=true} else {slv.getChildByName("s3").active=false};
if(smc.heros[uuid].slv>=4) {slv.getChildByName("s4").active=true} else {slv.getChildByName("s4").active=false};
if(smc.heros[uuid].slv>=5) {slv.getChildByName("s5").active=true} else {slv.getChildByName("s5").active=false};
let hcc = node.getComponent(HeroSetComp)!;
let hcc = node.getComponent(HeroSelectComp)!;
console.log(hcc)
hcc.h_uuid = uuid;
this.add(hcc);

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "675a0ae2-9928-4084-80ac-1b35115e3959",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -8,9 +8,9 @@ import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('HeroSetComp')
@ecs.register('HeroSetComp', false)
export class HeroSetComp extends CCComp {
@ccclass('HeroSelectComp')
@ecs.register('HeroSelectComp', false)
export class HeroSelectComp extends CCComp {
mhc_home: MissionHomeComp = null!;
h_uuid: number = 0;
onLoad() {
@@ -28,10 +28,10 @@ export class HeroSetComp extends CCComp {
}
}
select(){
this.mhc_home.select_hero(this.h_uuid)
if(smc.vmdata.fight_heros.indexOf(this.h_uuid)>=0){
smc.vmdata.fight_heros.splice(smc.vmdata.fight_heros.indexOf(this.h_uuid),1)
this.show_bg(false)
this.mhc_home.cancel_hero(this.h_uuid)
return
}
if(smc.vmdata.fight_heros.length>= 5){
@@ -39,6 +39,7 @@ export class HeroSetComp extends CCComp {
return
}
smc.vmdata.fight_heros.push(this.h_uuid)
this.mhc_home.select_hero(this.h_uuid)
this.show_bg(true)
}
check_show(event: string, args: any){

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e5696357-9e3c-44a0-b931-112175ad4315",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1 +0,0 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"03dbdc6b-b8d2-44e9-9477-1ef40669367a","files":[],"subMetas":{},"userData":{}}

View File

@@ -1 +0,0 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"51ececcc-7526-4b87-80c3-abff34028917","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,20 @@
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('UiHeroComp')
export class UiHeroComp extends Component {
h_uuid:number=0
start() {
console.log("UiHeroComp start",this.h_uuid)
console.log(this)
}
to_destroy(){
console.log("UiHeroComp to_destroy",this.h_uuid)
this.node.destroy()
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "44ef2827-b6e4-45fd-b3c2-9f8562884b81",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,8 +1,9 @@
import { instantiate, Prefab } from "cc";
import { instantiate, Prefab, resources, Sprite, SpriteAtlas } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { HCardComp } from "./HCardComp";
import { HeroInfo } from "../common/config/heroSet";
/** HCard 模块 */
@ecs.register(`HCard`)
@@ -13,8 +14,14 @@ export class HCard extends ecs.Entity {
// this.addComponents<ecs.Comp>();
}
load(uuid:number=1001,index:number=-1,parent:any) {
var path = "gui/element/hcard";
var path = "game/gui/hcard";
var icon_path = "game/heros/herois"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("Mask").getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path);
});
var prefab: Prefab = oops.res.get(path, Prefab)!;
console.log("load_hcard",prefab)
var node = instantiate(prefab);
node.parent = parent
var hcc = node.getComponent(HCardComp)!;

View File

@@ -211,6 +211,7 @@ export class MissionComp extends CCComp {
}
heros_call(){
let heros=smc.vmdata.fight_heros
console.log("heros_call",heros)
for(let i=0;i<heros.length;i++){
this.addHero(heros[i],i)
}
@@ -223,7 +224,7 @@ export class MissionComp extends CCComp {
for(let i=0;i<heros.length;i++){
let hcard = ecs.getEntity<HCard>(HCard)
// console.log("hcard:",hcard)
hcard.load(1001,i,node)
hcard.load(heros[i].HeroView.hero_uuid,i,node)
}
this.fight_start= true
}

View File

@@ -1,8 +1,12 @@
import { _decorator, UITransform } from "cc";
import { _decorator, instantiate, Prefab, UITransform } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroList } from "../common/config/heroSet";
import { HeroSet } from "../hero/HeroSet";
import { HeroInfo, HeroList } from "../common/config/heroSet";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { UiHeroComp } from "../hero/UiHeroComp";
import { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { HeroSelect } from "../hero/HeroSelect";
const { ccclass, property } = _decorator;
@@ -10,13 +14,37 @@ const { ccclass, property } = _decorator;
@ccclass('MissionHomeComp')
@ecs.register('MissionHome', false)
export class MissionHomeComp extends CCComp {
heros:any[]=[];
heros_pos:any=[
{uuid:0,px:-300},
{uuid:0,px:-200},
{uuid:0,px:-100},
{uuid:0,px:0},
{uuid:0,px:100},
]
/** 视图层逻辑代码分离演示 */
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
this.loads()
this.load_ui_heros()
}
start_mission() {
console.log("start_mission")
for(let i=0;i<this.heros.length;i++){
this.heros[i].to_destroy()
}
this.heros=[]
this.heros_pos=[
{uuid:0,px:-300},
{uuid:0,px:-200},
{uuid:0,px:-100},
{uuid:0,px:0},
{uuid:0,px:100},
]
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
@@ -25,17 +53,70 @@ export class MissionHomeComp extends CCComp {
// }
// }
select_hero(h_uuid:number){
console.log("select_hero",h_uuid)
for(let i=0;i<4;i++){
if(this.heros_pos[i].uuid==0){
this.heros_pos[i].uuid=h_uuid
this.call_hero(h_uuid,i)
break
}
}
console.log("select_hero",this.heros_pos)
}
cancel_hero(h_uuid:number){
console.log("cancel_hero",h_uuid)
for(let i=0;i<4;i++){
if(this.heros_pos[i].uuid==h_uuid){
this.heros_pos[i].uuid=0
this.destory_hero(h_uuid)
}
}
console.log("cancel_hero",this.heros_pos)
}
call_hero(h_uuid:number,index:number){
var path = "game/heros/uiheros/"+HeroInfo[h_uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!
node.setPosition(this.heros_pos[index].px,BoxSet.GAME_LINE,0);
let comp = node.getComponent(UiHeroComp)
console.log("call_hero",node)
comp.h_uuid = h_uuid
this.heros.push(comp)
console.log("call heros",this.heros)
}
destory_hero(h_uuid:number){
console.log("destory hero",this.heros)
for(let i=0;i<this.heros.length;i++){
if(this.heros[i].h_uuid==h_uuid){
this.heros[i].to_destroy()
this.heros.splice(i,1)
return
}
}
}
load_ui_heros(){
for(let i=0;i<smc.vmdata.fight_heros.length;i++){
this.select_hero(smc.vmdata.fight_heros[i])
}
}
loads(){
let hc:number =HeroList.length
let parent= this.node.getChildByName("heros").getChildByName("view").getChildByName("content")
parent.getComponent(UITransform).width=hc*150
for (let i = 0; i < hc; i++) {
let hcc =ecs.getEntity<HeroSet>(HeroSet)
let hcc =ecs.getEntity<HeroSelect>(HeroSelect)
hcc.load(HeroList[i],parent)
}
}
show_heros(){
this.node.getChildByName("heros").setPosition(0,290)
}
hide_heros(){
this.node.getChildByName("heros").setPosition(0,-400)
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();