完成新的 卡牌栏,完成物品使用,接下来需要英雄召唤

This commit is contained in:
2024-09-10 21:05:52 +08:00
parent 77a168628a
commit f286a2f2b2
16 changed files with 1513 additions and 6088 deletions

View File

@@ -20,14 +20,15 @@ export class CardControllerComp extends CCComp {
card_level:number = 1;
in_load:boolean = false
touch_time:number = 0
in_touch:boolean = false
cards:any = {
1:{uuid:1101,type:1,alive:false},
2:{uuid:1102,type:1,alive:false},
3:{uuid:1103,type:1,alive:false},
4:{uuid:1104,type:1,alive:false},
5:{uuid:1105,type:1,alive:false},
6:{uuid:1106,type:1,alive:false},
1:{uuid:1101,type:1,lv:0,alive:false},
2:{uuid:1102,type:1,lv:0,alive:false},
3:{uuid:1103,type:1,lv:0,alive:false},
4:{uuid:1104,type:1,lv:0,alive:false},
5:{uuid:1105,type:1,lv:0,alive:false},
6:{uuid:1106,type:1,lv:0,alive:false},
}
protected onLoad(): void {
let card1 = this.node.getChildByName("cards").getChildByName("card1");
@@ -51,37 +52,19 @@ export class CardControllerComp extends CCComp {
card6.on(NodeEventType.TOUCH_START, this.touch6, this);
card6.on(NodeEventType.TOUCH_MOVE, this.touch6, this);
card1.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card1.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card2.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card2.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card3.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card3.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card4.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card4.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card5.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card5.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card6.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
card6.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
card1.on(NodeEventType.TOUCH_END, this.end1, this);
card1.on(NodeEventType.TOUCH_CANCEL, this.end1, this);
card2.on(NodeEventType.TOUCH_END, this.end2, this);
card2.on(NodeEventType.TOUCH_CANCEL, this.end2, this);
card3.on(NodeEventType.TOUCH_END, this.end3, this);
card3.on(NodeEventType.TOUCH_CANCEL, this.end3, this);
card4.on(NodeEventType.TOUCH_END, this.end4, this);
card4.on(NodeEventType.TOUCH_CANCEL, this.end4, this);
card5.on(NodeEventType.TOUCH_END, this.end5, this);
card5.on(NodeEventType.TOUCH_CANCEL, this.end5, this);
card6.on(NodeEventType.TOUCH_END, this.end6, this);
card6.on(NodeEventType.TOUCH_CANCEL, this.end6, this);
const clickEventHandler = new EventHandler();
clickEventHandler.target = this.node; // 这个 node 节点是你的事件处理代码组件所属的节点
clickEventHandler.component = 'CardControllerComp';// 这个是脚本类名
clickEventHandler.handler = 'user_card';
clickEventHandler.customEventData = 'foobar';
const button1 = this.node.getChildByName('cards').getChildByName('card1').getComponent(Button);
const button2 = this.node.getChildByName('cards').getChildByName('card2').getComponent(Button);
const button3 = this.node.getChildByName('cards').getChildByName('card3').getComponent(Button);
const button4 = this.node.getChildByName('cards').getChildByName('card4').getComponent(Button);
const button5 = this.node.getChildByName('cards').getChildByName('card5').getComponent(Button);
const button6 = this.node.getChildByName('cards').getChildByName('card6').getComponent(Button);
button1.clickEvents.push(clickEventHandler);
button2.clickEvents.push(clickEventHandler);
button3.clickEvents.push(clickEventHandler);
button4.clickEvents.push(clickEventHandler);
button5.clickEvents.push(clickEventHandler);
button6.clickEvents.push(clickEventHandler);
}
start() {
@@ -98,28 +81,82 @@ export class CardControllerComp extends CCComp {
// }
// }
touch1(event: EventTouch) {
console.log("touch 1");
console.log("touch 1");
this.in_touch=true
if(this.in_load)return
if(!this.cards[1].alive)return
this.show_info(this.cards[1].uuid,this.cards[1].type)
}
touch2(event: EventTouch) {
console.log("touch 2");
}
this.in_touch=true
if(this.in_load)return
if(!this.cards[2].alive)return
this.show_info(this.cards[2].uuid,this.cards[2].type)
}
touch3(event: EventTouch) {
console.log("touch 3");
}
this.in_touch=true
if(this.in_load)return
if(!this.cards[3].alive)return
this.show_info(this.cards[3].uuid,this.cards[3].type)
}
touch4(event: EventTouch) {
console.log("touch 4");
}
this.in_touch=true
if(this.in_load)return
if(!this.cards[4].alive)return
this.show_info(this.cards[4].uuid,this.cards[4].type)
}
touch5(event: EventTouch) {
console.log("touch 5");
}
this.in_touch=true
if(this.in_load)return
if(!this.cards[5].alive)return
this.show_info(this.cards[5].uuid,this.cards[5].type)
}
touch6(event: EventTouch) {
console.log("touch 6");
}
this.in_touch=true
if(this.in_load)return
if(!this.cards[6].alive)return
this.show_info(this.cards[6].uuid,this.cards[6].type)
}
end1(event: EventTouch) {
console.log("end1 1");
this.onTouchEnd(1)
}
end2(event: EventTouch) {
console.log("end2 2");
this.onTouchEnd(2)
}
end3(event: EventTouch) {
console.log("end3 3");
this.onTouchEnd(3)
}
end4(event: EventTouch) {
console.log("end4 4");
this.onTouchEnd(4)
}
end5(event: EventTouch) {
console.log("end5 5");
this.onTouchEnd(5)
}
end6(event: EventTouch) {
console.log("end6 6");
this.onTouchEnd(6)
}
show_info(uuid:number,type:number){
console.log("show_info",uuid)
let node =this.node.getChildByName("item_box")
@@ -150,7 +187,12 @@ export class CardControllerComp extends CCComp {
}
}
}
onTouchEnd(){
onTouchEnd(index:number){
if(this.touch_time < 0.2){
this.use_card(index)
}
this.in_touch=false
this.touch_time = 0
let node = this.node.getChildByName("item_box")
node.active=false
node.getChildByName("data").getChildByName("shield").active=false
@@ -208,6 +250,7 @@ export class CardControllerComp extends CCComp {
card=RandomManager.instance.getRandomByObjectList(CardList, 1);
this.cards[index].uuid=card[0].uuid
this.cards[index].type=card[0].type
let url: string = "";
let pathName: string = "";
let name: string = "";
@@ -227,6 +270,8 @@ export class CardControllerComp extends CCComp {
url = "game/heros/skill";
({ path: pathName, name, level } = smc.skills[uuid]);
}
this.cards[index].lv=level
console.log("load_cards:",url,pathName,name,level)
let node=this.node.getChildByName('cards').getChildByName('card'+index)
node.getChildByName('cost').getComponent(Label).string=level.toString()
node.getChildByName('name').getComponent(Label).string=name
@@ -241,14 +286,28 @@ export class CardControllerComp extends CCComp {
// console.log("cards:",this.cards)
this.in_load = false
}
load_card(){
remove_card(index:number){
this.cards[index].alive=false
this.cards[index].uuid=0
this.cards[index].type=0
this.cards[index].lv=0
let url: string = "gui/gui";
let pathName: string = "129";
let node=this.node.getChildByName('cards').getChildByName('card'+index)
node.getChildByName('cost').getComponent(Label).string=""
node.getChildByName('name').getComponent(Label).string=""
// const sprite = node.getChildByName("item").getComponent(Sprite);
// console.log(this['card'+index],url,pathName,sprite)
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("item").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
});
}
use_card(event:Event,index: number){
this.cards[index].alive=false
use_card(index: number){
this.check_card(index)
console.log("cards:",this.cards)
// console.log("cards:",this.cards)
}
check_card(index:number){
let heros = ecs.query(ecs.allOf(HeroModelComp))
@@ -258,16 +317,21 @@ export class CardControllerComp extends CCComp {
oops.gui.toast("英雄数量达到上限");
return;
}
if(smc.vm_data.gold.min >= this.card_level){
if(!this.cards[index].alive) {
// console.log("card_index:",index,"card_alive:",this.cards[index].alive)
return;
};
if(smc.vm_data.gold.min >= this.cards[index].lv){
this.cards[index].alive=false
this.do_use_card(index)
smc.vm_data.gold.min -= this.card_level;
}else{
oops.gui.toast("金币不够");
}
}
do_use_card(index:number){
this.cards[index].alive=false
smc.vm_data.gold.min -= this.cards[index].lv;
switch (this.cards[index].type) {
case 1:
oops.message.dispatchEvent("do_add_hero", { uuid: this.cards[index].uuid });
@@ -278,13 +342,14 @@ export class CardControllerComp extends CCComp {
case 3:
oops.message.dispatchEvent("do_use_skill", { uuid: this.cards[index].uuid });
break;
default:
break;
}
this.remove_card(index)
}
protected update(dt: number): void {
this.shuaxin(dt)
if(this.in_touch){
this.touch_time+=dt
}
}
get_card_list(){

View File

@@ -99,7 +99,7 @@ export class CSkillComp extends CCComp {
// 94role 临时buff
// 95role 永久buff
let uuid= this.skill_uuid;
let atk:number=smc.Role.RoleView.atk
let atk:number=smc.Role.RoleView.atk?smc.Role.RoleView.atk:0
let args:any = {
atk:atk*GameSet.ATK_TO_ATK_RATIO,
hp:atk*GameSet.ATK_TO_HP_RATIO,

View File

@@ -103,7 +103,7 @@ export class HeroCardViewComp extends CCComp {
node.active=false
node.getChildByName("data").getChildByName("shield").active=false
node.getChildByName("data").getChildByName("hp").active=false
}
private do_active_card_eid(event: string, args: any) {