130 lines
4.2 KiB
TypeScript
130 lines
4.2 KiB
TypeScript
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 { 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;
|
|
|
|
/** 视图层对象 */
|
|
@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(e:any,args:any) {
|
|
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},
|
|
]
|
|
if(args!=0){
|
|
this.load_ui_heros()
|
|
}
|
|
}
|
|
load_ui_heros(){
|
|
for(let i=0;i<smc.vmdata.fight_heros.length;i++){
|
|
this.select_hero(smc.vmdata.fight_heros[i])
|
|
}
|
|
}
|
|
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
|
|
}
|
|
}
|
|
}
|
|
loads(){
|
|
let hc:number =HeroList.length
|
|
let parent= this.node.getChildByName("heros").getChildByName("view").getChildByName("content")
|
|
let height=Math.ceil(hc / 4)*135
|
|
parent.getComponent(UITransform).width=height
|
|
for (let i = 0; i < hc; i++) {
|
|
let hcc =ecs.getEntity<HeroSelect>(HeroSelect)
|
|
hcc.load(HeroList[i],parent)
|
|
}
|
|
}
|
|
show_uiheros(){
|
|
|
|
}
|
|
show_heros(){
|
|
this.node.getChildByName("heros").setPosition(0,290)
|
|
}
|
|
hide_heros(){
|
|
this.node.getChildByName("heros").setPosition(0,-800)
|
|
}
|
|
show_skills(){
|
|
this.node.getChildByName("skills").setPosition(0,400)
|
|
}
|
|
hide_skills(){
|
|
this.node.getChildByName("skills").setPosition(0,-800)
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |