英雄和卡片 联动完成

This commit is contained in:
2024-12-08 11:18:03 +08:00
parent aebe98577c
commit 59f965dc1c
4 changed files with 999 additions and 254 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,20 +18,21 @@ export class HeroCard extends ecs.Entity {
var icon_path = "game/heros/herois" var icon_path = "game/heros/herois"
var prefab: Prefab = oops.res.get(path, Prefab)!; var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab); var node = instantiate(prefab);
let slv = node.getChildByName("slv");
node.parent = parent; node.parent = parent;
node.getChildByName("name").getComponent(Label).string = HeroInfo[uuid].name node.getChildByName("name").getComponent(Label).string = HeroInfo[uuid].name
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("Mask").getChildByName("hero").getComponent(Sprite); const sprite = node.getChildByName("Mask").getChildByName("hero").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path); sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path);
}); });
node.getChildByName("lv").getComponent(Label).string = smc.heros[uuid].lv.toString(); node.getChildByName("lv").getComponent(Label).string = smc.heros[uuid].lv.toString()+"级";
if(smc.heros[uuid].slv>=1) node.getChildByName("slv").getChildByName("s1").active=true; if(smc.heros[uuid].slv>=1) {slv.getChildByName("s1").active=true} else {slv.getChildByName("s1").active=false};
if(smc.heros[uuid].slv>=2) node.getChildByName("slv").getChildByName("s2").active=true; if(smc.heros[uuid].slv>=2) {slv.getChildByName("s2").active=true} else {slv.getChildByName("s2").active=false};
if(smc.heros[uuid].slv>=3) node.getChildByName("slv").getChildByName("s3").active=true; if(smc.heros[uuid].slv>=3) {slv.getChildByName("s3").active=true} else {slv.getChildByName("s3").active=false};
if(smc.heros[uuid].slv>=4) node.getChildByName("slv").getChildByName("s4").active=true; if(smc.heros[uuid].slv>=4) {slv.getChildByName("s4").active=true} else {slv.getChildByName("s4").active=false};
if(smc.heros[uuid].slv>=5) node.getChildByName("slv").getChildByName("s5").active=true; if(smc.heros[uuid].slv>=5) {slv.getChildByName("s5").active=true} else {slv.getChildByName("s5").active=false};
let hcc = node.getComponent(HeroCardComp)!; let hcc = node.getComponent(HeroCardComp)!;
hcc.hcc_uuid = uuid; hcc.h_uuid = uuid;
this.add(hcc); this.add(hcc);
} }
/** 模块资源释放 */ /** 模块资源释放 */

View File

@@ -1,8 +1,9 @@
import { _decorator } from "cc"; import { _decorator, Label } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroHomeComp } from "../map/HeroHomeComp"; import { HeroHomeComp } from "../map/HeroHomeComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@@ -10,11 +11,11 @@ const { ccclass, property } = _decorator;
@ccclass('HeroCardComp') @ccclass('HeroCardComp')
@ecs.register('HeroCardComp', false) @ecs.register('HeroCardComp', false)
export class HeroCardComp extends CCComp { export class HeroCardComp extends CCComp {
hcc_home: HeroHomeComp = null!; hcc_home: HeroHomeComp = null!;
hcc_uuid: number = 0; h_uuid: number = 0;
onLoad() { onLoad() {
oops.message.on("hero_card_show_info", this.check_show, this); oops.message.on("hero_card_show_info", this.check_show, this);
oops.message.on("hero_card_update_info", this.update_data, this);
} }
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start() { start() {
@@ -23,19 +24,29 @@ export class HeroCardComp extends CCComp {
} }
show_info(){ show_info(){
this.hcc_home.hero_show(this.hcc_uuid) this.hcc_home.hero_show(this.h_uuid)
oops.message.dispatchEvent("hero_card_show_info",{uuid:this.hcc_uuid}) oops.message.dispatchEvent("hero_card_show_info",{uuid:this.h_uuid})
} }
check_show(event: string, args: any){ check_show(event: string, args: any){
// console.log("hero_card check_show",args) // console.log("hero_card check_show",args)
this.show_bg(false) this.show_bg(false)
if(args.uuid==this.hcc_uuid){ if(args.uuid==this.h_uuid){
this.show_bg(true) this.show_bg(true)
} }
} }
show_bg(val:boolean){ show_bg(val:boolean){
this.node.getChildByName("show").active=val this.node.getChildByName("show").active=val
} }
update_data(event: string, args: any){
if(args.uuid!=this.h_uuid) return
let slv = this.node.getChildByName("slv")
this.node.getChildByName("lv").getComponent(Label).string=smc.heros[this.h_uuid].lv.toString()+"级"
if(smc.heros[this.h_uuid].slv>=1) {slv.getChildByName("s1").active=true} else {slv.getChildByName("s1").active=false};
if(smc.heros[this.h_uuid].slv>=2) {slv.getChildByName("s2").active=true} else {slv.getChildByName("s2").active=false};
if(smc.heros[this.h_uuid].slv>=3) {slv.getChildByName("s3").active=true} else {slv.getChildByName("s3").active=false};
if(smc.heros[this.h_uuid].slv>=4) {slv.getChildByName("s4").active=true} else {slv.getChildByName("s4").active=false};
if(smc.heros[this.h_uuid].slv>=5) {slv.getChildByName("s5").active=true} else {slv.getChildByName("s5").active=false};
}
/** 全局消息逻辑处理 */ /** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) { // private onHandler(event: string, args: any) {
// switch (event) { // switch (event) {

View File

@@ -111,6 +111,8 @@ export class HeroHomeComp extends CCComp {
attr2.getChildByName("cep").getChildByName("val").getComponent(Label).string = this.hero.cep attr2.getChildByName("cep").getChildByName("val").getComponent(Label).string = this.hero.cep
attr2.getChildByName("doep").getChildByName("val").getComponent(Label).string = this.hero.doep attr2.getChildByName("doep").getChildByName("val").getComponent(Label).string = this.hero.doep
attr2.getChildByName("dep").getChildByName("val").getComponent(Label).string = this.hero.dep attr2.getChildByName("dep").getChildByName("val").getComponent(Label).string = this.hero.dep
oops.message.dispatchEvent("hero_card_update_info",{uuid:this.h_uuid})
} }
lv_selcet(e:any,val:any){ lv_selcet(e:any,val:any){
let active = this.node.getChildByName("menu").getChildByName("active") let active = this.node.getChildByName("menu").getChildByName("active")
@@ -152,6 +154,7 @@ export class HeroHomeComp extends CCComp {
smc.vmdata.gold -= (UpGold.LvUp*this.role.lv) smc.vmdata.gold -= (UpGold.LvUp*this.role.lv)
this.role.lv++ this.role.lv++
this.update_data() this.update_data()
} }
slv_up(){ slv_up(){
if(this.role.slv>=5){ if(this.role.slv>=5){