This commit is contained in:
pan
2024-08-15 10:53:40 +08:00
parent cc2020086d
commit 8686d50a6c
10 changed files with 2596 additions and 689 deletions

View File

@@ -13,7 +13,8 @@ const { ccclass, property } = _decorator;
@ccclass('CardControllerComp')
@ecs.register('CardController', false)
export class CardControllerComp extends CCComp {
card_level = 1;
card_level:number = 1;
in_load:boolean = false
start() {
this.load_cards()
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
@@ -34,7 +35,15 @@ export class CardControllerComp extends CCComp {
this.load_cards()
}
}
palyer_ref(){
if (this.in_load) {
return
}
this.load_cards()
}
load_cards() {
this.in_load = true
let old_cards = ecs.query(ecs.allOf(HeroCardViewComp))
if (old_cards.length > 0) {
old_cards.forEach(element => {
@@ -53,6 +62,8 @@ export class CardControllerComp extends CCComp {
x=x+100
});
this.node.getChildByName("cards").getChildByName("active").active = false
this.in_load = false;
}
/** 转场 */
protected update(dt: number): void {
@@ -67,6 +78,7 @@ export class CardControllerComp extends CCComp {
}
return lists
}
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();

View File

@@ -0,0 +1,41 @@
import { _decorator,v3 ,NodeEventType} 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { HeroCard } from "../monster/HeroCard";
import { HeroCardViewComp } from "../monster/HeroCardViewComp";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { CardList } from "../common/config/CardSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('RefControllerComp')
@ecs.register('RefController', false)
export class RefControllerComp extends CCComp {
card_level = 1;
protected onLoad(): void {
}
start() {
}
protected update(dt: number): void {
}
reset() {
this.node.destroy();
}
onTouch(){
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"6527b285-9d12-416e-8963-5e39820b7d4e","files":[],"subMetas":{},"userData":{}}

View File

@@ -3,6 +3,7 @@ import { oops } from "../../../../../extensions/oops-plugin-framework/assets/cor
import MapData from "./map/base/MapData";
import { MapLoadModel } from "./map/base/MapLoadModel";
import EntityLayer from "./map/layer/EntityLayer";
import SkillLayer from "./map/layer/SkillLayer";
import MapLayer from "./map/layer/MapLayer";
const { ccclass, property } = _decorator;
@@ -27,6 +28,9 @@ export class MapViewScene extends Component {
@property(EntityLayer)
public entityLayer: EntityLayer | null = null;
@property(SkillLayer)
public SkillLayer: SkillLayer | null = null;
@property(CCBoolean)
public isFollowPlayer: boolean = true;

View File

@@ -14,59 +14,38 @@ export class HeroCardViewComp extends CCComp {
card_name:string = "hero_card";
card_type:string = "hero";
card_uid:number = 1000;
/** 方向 */
private _dir: Vec2 = new Vec2(0, 0);
public get dir(): Vec2 {
return this._dir;
}
public set dir(value: Vec2) {
this._dir = value;
}
pos_x=0;
pos_y=0;
protected onLoad(): void {
this.node.on(NodeEventType.TOUCH_START, this.onTouch, this);
this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
oops.message.on("destroy hero_card", this.on_destroy_node, this);
// this.node.on(NodeEventType.TOUCH_START, this.onTouch, this);
// this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
// this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
// this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
// oops.message.on("active_card_eid", this.do_active_card_eid, this);
}
private on_destroy_node(event: string, args: any) {
// if(this.ent.eid == args){
// this.reset();
// }
}
onTouch(){
smc.vm_data.cards.eid = this.ent.eid;
let parent = this.node.parent;
let active = parent.getChildByName("active");
active.setPosition(this.pos_x,this.pos_y)
active.active = true;
active.setPosition(this.node.position.x+47.5,this.node.position.y+47.5);
}
onTouchMove(event: EventTouch) {
smc.vm_data.cards.eid = this.ent.eid;
// if(this.ent.eid == smc.vm_data.cards.eid){
// this.node.getChildByName("active").active = true;
// }else{
// this.node.getChildByName("active").active = false;
// }
let delta = event.getDelta();
this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y);
}
onTouchEnd(){
let parent = this.node.parent;
let active = parent.getChildByName("active");
active.setPosition(this.pos_x+47.5,this.pos_y+47.5)
if(this.node.position.y-this.pos_y > 110){
active.active = false;
this.use_card()
}else{
this.node.setPosition(this.pos_x,this.pos_y);
private do_active_card_eid(event: string, args: any) {
console.log("active_card_eid",args,this.ent.eid)
if(this.ent.eid != args.eid){
this.no_active()
}
}
do_active(){
}
no_active(){
// this.node.getChildByName("active").active=false;
// this.node.getChildByName("use").active=false;
// this.node.getChildByName("bag").active=false;
}
doit(){
// this.do_active()
console.log("doit",this.ent)
smc.vm_data.cards.eid = this.ent.eid;
// oops.message.dispatchEvent("active_card_eid",{eid:this.ent.eid})
}
use_card(){
if(smc.vm_data.gold.min >= CardSet[this.card_uid].level){
oops.message.dispatchEvent("do_add_hero",{uuid:this.card_uid})
@@ -74,13 +53,12 @@ export class HeroCardViewComp extends CCComp {
smc.vm_data.gold.min -= CardSet[this.card_uid].level;
}else{
oops.gui.toast("金币不够");
this.node.setPosition(this.pos_x,this.pos_y);
}
}
/** 视图层逻辑代码分离演示 */
start() {
this.pos_x=this.node.position.x;
this.pos_y=this.node.position.y;
}
/** 全局消息逻辑处理 */