Files
heros/assets/script/game/map/MSCardComp.ts

87 lines
4.0 KiB
TypeScript

import { _decorator, Label } 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 { smc } from "../common/SingletonModuleComp";
import { MissionHomeComp } from "./MissionHomeComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { SkillSet } from "../common/config/SkillSet";
import { SChipComp } from "../hero/SChipComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('MSCardComp')
@ecs.register('MSCardComp', false)
export class MSCardComp extends CCComp {
mhc:MissionHomeComp
s_uuid: number = 0;
is_update: boolean = false;
is_select: boolean = false;
is_selected: boolean = false;
/** 视图层逻辑代码分离演示 */
start() {
oops.message.on(GameEvent.MSSelected, this.update_select, this);
this.mhc=this.node.parent.parent.parent.parent.getComponent(MissionHomeComp)
this.change()
}
change_set(){
this.is_update=!this.is_update
this.is_select=!this.is_select
this.change()
}
change(){
if(this.is_update){
this.node.getChildByName("update").active=true
}else{
this.node.getChildByName("update").active=false
}
if(this.is_select){
this.node.getChildByName("set").active=true
this.update_select()
}else{
this.node.getChildByName("set").active=false
}
}
update_data(){
if(smc.skills[this.s_uuid].slv>=1) {this.node.getChildByName("slv").getChildByName("s1").active=true} else {this.node.getChildByName("slv").getChildByName("s1").active=false};
if(smc.skills[this.s_uuid].slv>=2) {this.node.getChildByName("slv").getChildByName("s2").active=true} else {this.node.getChildByName("slv").getChildByName("s2").active=false};
if(smc.skills[this.s_uuid].slv>=3) {this.node.getChildByName("slv").getChildByName("s3").active=true} else {this.node.getChildByName("slv").getChildByName("s3").active=false};
if(smc.skills[this.s_uuid].slv>=4) {this.node.getChildByName("slv").getChildByName("s4").active=true} else {this.node.getChildByName("slv").getChildByName("s4").active=false};
if(smc.skills[this.s_uuid].slv>=5) {this.node.getChildByName("slv").getChildByName("s5").active=true} else {this.node.getChildByName("slv").getChildByName("s5").active=false};
this.node.getChildByName("update").getChildByName("cost").getComponent(Label).string =smc.skills[this.s_uuid].num.toString()+ " / "+(SkillSet[this.s_uuid].upcost*(1+smc.skills[this.s_uuid].slv)).toString()
let sc= this.node.getChildByName("update").getChildByName("schip").getComponent(SChipComp)
sc.update_data(this.s_uuid,0)
}
select(){
smc.mission.mskill=this.s_uuid
this.mhc.select_skill()
oops.message.dispatchEvent(GameEvent.MSSelected,{uuid:this.s_uuid})
}
update_select(){
console.log("update_select",smc.mission.mskill,this.s_uuid)
if(smc.mission.mskill ==this.s_uuid){
this.node.getChildByName("set").getChildByName("btn").active=false
}else{
this.node.getChildByName("set").getChildByName("btn").active=true
}
}
update_lv(){
if(smc.skills[this.s_uuid].num <= (SkillSet[this.s_uuid].upcost*(1+smc.skills[this.s_uuid].slv))){
oops.gui.toast("技能碎片不足")
return
}
smc.skills[this.s_uuid].num -= (SkillSet[this.s_uuid].upcost*(1+smc.skills[this.s_uuid].slv))
smc.skills[this.s_uuid].slv++
let mscards:any= ecs.query(ecs.allOf(MSCardComp));
for(let i=0;i<mscards.length;i++){
mscards[i].MSCardComp.update_data()
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}