114 lines
4.1 KiB
TypeScript
114 lines
4.1 KiB
TypeScript
import { _decorator, instantiate, Label ,Prefab,Node} 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { ItemComp } from "./ItemComp";
|
|
import { startGuide } from "../common/config/Guide";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('VictoryComp')
|
|
@ecs.register('Victory', false)
|
|
export class VictoryComp extends CCComp {
|
|
|
|
reward_lv:number=1
|
|
reward_num:number=2
|
|
rewards:any[]=[]
|
|
game_data:any={
|
|
exp:0,
|
|
gold:0,
|
|
diamond:0
|
|
}
|
|
/** 视图层逻辑代码分离演示 */
|
|
protected onLoad(): void {
|
|
|
|
}
|
|
|
|
onAdded(args: any) {
|
|
// console.log("[VictoryComp] onAdded",args,smc.items)
|
|
if(args.game_data){
|
|
this.game_data=args.game_data
|
|
}
|
|
if(args.rewards){
|
|
this.add_reward(args.rewards)
|
|
this.rewards=args.rewards
|
|
}
|
|
this.node.getChildByName("box").getChildByName("exp").getChildByName("num").getComponent(Label)!.string="x"+this.game_data["exp"].toString()
|
|
this.node.getChildByName("box").getChildByName("gold").getChildByName("num").getComponent(Label)!.string="x"+this.game_data["gold"].toString()
|
|
this.node.getChildByName("box").getChildByName("diamond").getChildByName("num").getComponent(Label)!.string="x"+this.game_data["diamond"].toString()
|
|
this.node.getChildByName("title").getChildByName("victory").active=args.victory
|
|
this.node.getChildByName("title").getChildByName("defeat").active=!args.victory
|
|
this.node.getChildByName("btns").getChildByName("next").active=false
|
|
this.scheduleOnce(()=>{
|
|
this.node.getChildByName("btns").getChildByName("next").active=true
|
|
},0.2)
|
|
}
|
|
|
|
add_reward(rewards:any[]){
|
|
let parent=this.node.getChildByName("box").getChildByName("items")
|
|
let items=parent.children
|
|
for(let i=0;i<rewards.length;i++){
|
|
let d_item=rewards[i]
|
|
let path="game/gui/item"
|
|
const prefab = oops.res.get(path, Prefab);
|
|
if (!prefab) {
|
|
console.error("[MissionComp=>do_drop] 预制体加载失败:", path);
|
|
return;
|
|
}
|
|
const node = instantiate(prefab) as unknown as Node;
|
|
node.parent=parent
|
|
node.getComponent(ItemComp)!.update_data(d_item.item_uuid,d_item.count,{no_show:true})
|
|
}
|
|
}
|
|
victory_end(){
|
|
this.clear_data()
|
|
// startGuide(2)
|
|
oops.message.dispatchEvent(GameEvent.MissionEnd)
|
|
oops.gui.removeByNode(this.node)
|
|
}
|
|
clear_data(){
|
|
this.game_data={
|
|
exp:0,
|
|
gold:0,
|
|
diamond:0
|
|
}
|
|
this.rewards=[]
|
|
this.node.getChildByName("box").getChildByName("items").removeAllChildren()
|
|
}
|
|
//看广告双倍
|
|
watch_ad(){
|
|
return true
|
|
}
|
|
double_reward(){
|
|
if(this.watch_ad()){
|
|
smc.addExp(this.game_data["exp"])
|
|
smc.addGold(this.game_data["gold"])
|
|
smc.addDiamond(this.game_data["diamond"])
|
|
this.rewards.forEach(d_item=>{
|
|
smc.addItem(d_item.item_uuid,d_item.count)
|
|
})
|
|
this.node.getChildByName("btns").getChildByName("double").active=false
|
|
}
|
|
// console.log("[VictoryComp]double_reward",smc.items,this.rewards)
|
|
}
|
|
restart(){
|
|
this.clear_data()
|
|
oops.message.dispatchEvent(GameEvent.MissionStart)
|
|
oops.gui.removeByNode(this.node)
|
|
}
|
|
|
|
item_show(e:any,val:any){
|
|
// console.log("item_show",val)
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
// console.log("释放胜利界面");
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy()
|
|
}
|
|
} |