134 lines
5.3 KiB
TypeScript
134 lines
5.3 KiB
TypeScript
import { _decorator, Label, Node, ProgressBar, resources, Sprite, SpriteAtlas, tween, v3 } 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 { ButtonTouchLong } from "../../../../extensions/oops-plugin-framework/assets/libs/gui/button/ButtonTouchLong";
|
|
import { EnhancedButtonTouchLong } from "../common/EnhancedButtonTouchLong";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { MasterModelComp } from "../hero/MasterModel";
|
|
import { FriendModelComp } from "../hero/FriendModel";
|
|
import { HeroInfo } from "../common/config/heroSet";
|
|
import { FacSet } from "../common/config/BoxSet";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('BarCompComp')
|
|
@ecs.register('BarComp', false)
|
|
export class BarCompComp extends CCComp {
|
|
hero:HeroViewComp = null;
|
|
friend:HeroViewComp = null;
|
|
boss:HeroViewComp = null;
|
|
/** 视图层逻辑代码分离演示 */
|
|
protected onLoad(): void {
|
|
this.on(GameEvent.FightReady,this.readay,this)
|
|
this.on(GameEvent.FriendCalled,this.friend_called,this)
|
|
this.on(GameEvent.MasterCalled,this.master_called,this)
|
|
this.on(GameEvent.APChange,this.ap_change,this)
|
|
|
|
}
|
|
start() {
|
|
// this.boss_bar = this.node.getChildByName("bar");
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
}
|
|
private readay(){
|
|
this.node.getChildByName("bar").active = true
|
|
this.node.getChildByName("fbar").active = false
|
|
this.node.getChildByName("bar").getChildByName("more").active=false
|
|
this.node.getChildByName("fbar").getChildByName("more").active=false
|
|
}
|
|
private master_called(e:any,data:any){
|
|
this.node.getChildByName("bar").active = true
|
|
let show=this.node.getChildByName("bar").getChildByName("hero")
|
|
var icon_path = "game/heros/herois"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[data.uuid].path);
|
|
});
|
|
}
|
|
private friend_called(e:any,data:any){
|
|
this.node.getChildByName("fbar").active=true
|
|
let show=this.node.getChildByName("fbar").getChildByName("hero")
|
|
var icon_path = "game/heros/herois"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[data.uuid].path);
|
|
});
|
|
}
|
|
private ap_change(e:any,data:any){
|
|
console.log("[barcomp]:ap_change",data)
|
|
if(data.fac==FacSet.HERO){
|
|
let barNode = this.node.getChildByName("bar").getChildByName("ap").getChildByName("val")
|
|
tween(barNode).to(0.2, {scale:v3(1.5,1.5,1)},{
|
|
onComplete:()=>{
|
|
tween(barNode).to(0.1, {scale:v3(1,1,1)}).start()
|
|
}
|
|
}).start()
|
|
|
|
}else{
|
|
let barNode = this.node.getChildByName("fbar").getChildByName("ap").getChildByName("val")
|
|
tween(barNode).to(0.2, {scale:v3(1.5,1.5,1)},{
|
|
onComplete:()=>{
|
|
tween(barNode).to(0.1, {scale:v3(1,1,1)}).start()
|
|
}
|
|
}).start()
|
|
}
|
|
}
|
|
show_master_more(){
|
|
let barNode = this.node.getChildByName("bar");
|
|
let node = barNode.getChildByName("more");
|
|
node.active = true;
|
|
node.setScale(v3(1, 0, 1));
|
|
console.log("[barcomp]:show_master_more",node)
|
|
// 使用缓动动画放大和移动
|
|
tween(node).to(0.2, {scale:v3(1,1,1)}).start()
|
|
}
|
|
|
|
hide_master_more(){
|
|
let barNode = this.node.getChildByName("bar");
|
|
let node = barNode.getChildByName("more");
|
|
console.log("[barcomp]:hide_master_more",node)
|
|
// 使用缓动动画放大和移动
|
|
tween(node).to(0.2, {scale:v3(1,0,1)}).start()
|
|
node.active = false;
|
|
}
|
|
|
|
show_friend_more(){
|
|
let barNode = this.node.getChildByName("fbar");
|
|
let node = barNode.getChildByName("more");
|
|
node.active = true;
|
|
node.setScale(v3(1, 0, 1));
|
|
console.log("[barcomp]:show_friend_more",node)
|
|
// 使用缓动动画放大和移动
|
|
tween(node).to(0.2, {scale:v3(1,1,1)}).start()
|
|
}
|
|
|
|
hide_friend_more(){
|
|
let barNode = this.node.getChildByName("fbar");
|
|
let node = barNode.getChildByName("more");
|
|
console.log("[barcomp]:hide_friend_more",node)
|
|
// 使用缓动动画放大和移动
|
|
tween(node).to(0.2, {scale:v3(1,0,1)}).start()
|
|
node.active = false;
|
|
}
|
|
update_bar(){
|
|
|
|
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
|
|
|
|
} |