|
|
@ -1,10 +1,10 @@ |
|
|
|
import { _decorator, Animation, Button, Component, find, Label, Node, sp, Sprite } from 'cc'; |
|
|
|
import { _decorator, Animation, Button, Component, find, Label, Node, sp, Sprite, SpriteFrame } from 'cc'; |
|
|
|
import { TeenPattieCommData } from '../TeenPattieCommData'; |
|
|
|
import { TeenPattiePathTool } from '../../tool/TeenPattiePathTool'; |
|
|
|
import { TeenPattieCommTool } from '../../tool/TeenPattieCommTool'; |
|
|
|
import { TeenPattieEventType } from '../../tool/TeenPattieEventType'; |
|
|
|
import { AudioManager, Message, Sleep, UIManager } from '../../sdk/API'; |
|
|
|
import { GamePanelConst, GameSound, GameStatus } from '../../GameConst10001'; |
|
|
|
import { AudioManager, LoaderManager, Message, Sleep, UIManager } from '../../sdk/API'; |
|
|
|
import { BundleName, GamePanelConst, GameSound, GameStatus } from '../../GameConst10001'; |
|
|
|
const { ccclass, property } = _decorator; |
|
|
|
|
|
|
|
@ccclass('TeenPattieBiPaiSuccGamePanel') |
|
|
@ -36,6 +36,11 @@ export class TeenPattieBiPaiSuccGamePanel extends Component { |
|
|
|
private cardList_2: Sprite[]; |
|
|
|
private cardType_2: Sprite; |
|
|
|
private cardType_Node_2:Node; |
|
|
|
|
|
|
|
/**胜利方数据 */ |
|
|
|
private faqiData: any; |
|
|
|
/**失败方数据 */ |
|
|
|
private beiFaqiData: any; |
|
|
|
|
|
|
|
/**PK结果数据 */ |
|
|
|
private result: any; |
|
|
@ -83,19 +88,36 @@ export class TeenPattieBiPaiSuccGamePanel extends Component { |
|
|
|
this.cardType_Node_2.active = false; |
|
|
|
|
|
|
|
this.result = TeenPattieCommData.getInstance().pkResult; |
|
|
|
|
|
|
|
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){ |
|
|
|
this.bipai_faqi_cards.active = true; |
|
|
|
this.bipai_beifaqi_cards.active = true; |
|
|
|
}else{ |
|
|
|
this.bipai_faqi_cards.active = false; |
|
|
|
this.bipai_beifaqi_cards.active = false; |
|
|
|
} |
|
|
|
|
|
|
|
this.timeLabel = 2; |
|
|
|
this.clickNum = 1; |
|
|
|
this.anumNum_1 = 0; |
|
|
|
this.anumNum_2 = 0; |
|
|
|
|
|
|
|
this.startEvnet(); |
|
|
|
} |
|
|
|
private async onStartClose(){ |
|
|
|
this.timeLabel--; |
|
|
|
if(this.timeLabel <= 0){ |
|
|
|
clearInterval(this.tid); |
|
|
|
this.tid = null; |
|
|
|
|
|
|
|
await Sleep(1000) |
|
|
|
this.onClickBtn(); |
|
|
|
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){ |
|
|
|
if(this.anumNum_1 > 2 || this.anumNum_2 > 2){ |
|
|
|
clearInterval(this.tid); |
|
|
|
this.tid = null; |
|
|
|
|
|
|
|
await Sleep(1000) |
|
|
|
this.onClickBtn(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
this.onClickBtn(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
private startEvnet() { |
|
|
@ -106,17 +128,118 @@ export class TeenPattieBiPaiSuccGamePanel extends Component { |
|
|
|
|
|
|
|
this.isFaqi(); |
|
|
|
|
|
|
|
this.vsSkele.setCompleteListener(()=>{ |
|
|
|
this.showWinPlayer(); |
|
|
|
}) |
|
|
|
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){ |
|
|
|
console.log("******注册动画事件*******"); |
|
|
|
this.onSkeleEvent() |
|
|
|
}else{ |
|
|
|
this.vsSkele.setCompleteListener(()=>{ |
|
|
|
this.showWinPlayer(); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
protected onDestroy(): void { |
|
|
|
// this.closeBtn?.node?.off(Node.EventType.TOUCH_END,this.onClickBtn,this);
|
|
|
|
Message.remove(TeenPattieEventType.Reconnect, this.closeUI, this); |
|
|
|
|
|
|
|
this.onDesSkeleEvent(); |
|
|
|
} |
|
|
|
|
|
|
|
/**注册需要播放的动画事件 */ |
|
|
|
private onSkeleEvent(){ |
|
|
|
|
|
|
|
console.log("******背景动画播放开始*******"); |
|
|
|
let loadAnim = setTimeout(()=>{ |
|
|
|
clearTimeout(loadAnim); |
|
|
|
loadAnim = null; |
|
|
|
|
|
|
|
console.log("******背景动画播放完*******"); |
|
|
|
this.onloadAnimFunc(); |
|
|
|
},1000) |
|
|
|
|
|
|
|
for(let i=0;i<this.cardAnim_1.length;i++){ |
|
|
|
this.cardAnim_1[i].on(Animation.EventType.FINISHED,this.cardAnimFunc_1,this) |
|
|
|
} |
|
|
|
for(let i=0;i<this.cardAnim_2.length;i++){ |
|
|
|
this.cardAnim_2[i].on(Animation.EventType.FINISHED,this.cardAnimFunc_2,this) |
|
|
|
} |
|
|
|
} |
|
|
|
/**销毁需要播放的动画事件 */ |
|
|
|
private onDesSkeleEvent(){ |
|
|
|
for(let i=0;i<this.cardAnim_1.length;i++){ |
|
|
|
this.cardAnim_1[i]?.off(Animation.EventType.FINISHED,this.cardAnimFunc_1,this) |
|
|
|
} |
|
|
|
for(let i=0;i<this.cardAnim_2.length;i++){ |
|
|
|
this.cardAnim_2[i]?.off(Animation.EventType.FINISHED,this.cardAnimFunc_2,this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**开始动画播放完成 */ |
|
|
|
private onloadAnimFunc(){ |
|
|
|
this.cardAnim_1[this.anumNum_1].play() |
|
|
|
this.cardAnim_2[this.anumNum_2].play() |
|
|
|
} |
|
|
|
|
|
|
|
private anumNum_1:number = 0; |
|
|
|
private anumNum_2:number = 0; |
|
|
|
private cardAnimFunc_1(){ |
|
|
|
if(this.anumNum_1 > 2) return |
|
|
|
if(this.cardAnim_1[this.anumNum_1]){ |
|
|
|
this.cardAnim_1[this.anumNum_1].stop(); |
|
|
|
this.cardAnim_1[this.anumNum_1]=null; |
|
|
|
} |
|
|
|
|
|
|
|
this.setCardSprite_1(this.anumNum_1) |
|
|
|
this.anumNum_1 += 1 |
|
|
|
if(this.anumNum_1 > 2) return |
|
|
|
if( this.cardAnim_1[this.anumNum_1])this.cardAnim_1[this.anumNum_1].play() |
|
|
|
} |
|
|
|
private cardAnimFunc_2(){ |
|
|
|
if(this.anumNum_2 > 2) return |
|
|
|
if(this.cardAnim_2[this.anumNum_2]){ |
|
|
|
this.cardAnim_2[this.anumNum_2].stop(); |
|
|
|
this.cardAnim_2[this.anumNum_2]=null; |
|
|
|
} |
|
|
|
|
|
|
|
this.setCardSprite_2(this.anumNum_2) |
|
|
|
this.anumNum_2 += 1 |
|
|
|
if(this.anumNum_2 > 2){ |
|
|
|
this.animEnd(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(this.cardAnim_2[this.anumNum_2])this.cardAnim_2[this.anumNum_2].play() |
|
|
|
} |
|
|
|
|
|
|
|
/**动画结束 */ |
|
|
|
private animEnd(){ |
|
|
|
this.faqi_win.active = this.result.winSeatId == TeenPattieCommData.getInstance().playerData.SeatId; |
|
|
|
this.beifaqi_win.active = this.result.winSeatId == TeenPattieCommData.getInstance().beiPlayerData.SeatId; |
|
|
|
} |
|
|
|
|
|
|
|
private clickNum:number=1 |
|
|
|
|
|
|
|
private onClickBtn(){ |
|
|
|
this.closeUI(); |
|
|
|
if(this.anumNum_1 > 2 || this.anumNum_2 > 2) this.clickNum++ |
|
|
|
if(this.clickNum > 1){ |
|
|
|
this.closeUI(); |
|
|
|
return |
|
|
|
}else{ |
|
|
|
this.skipAnim() |
|
|
|
this.clickNum++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private skipAnim(){ |
|
|
|
for(let i = 0;i<3;i++){ |
|
|
|
this.anumNum_1 = 3 |
|
|
|
this.setCardSprite_1(i) |
|
|
|
} |
|
|
|
for(let i = 0;i<3;i++){ |
|
|
|
this.anumNum_2 = 3 |
|
|
|
this.setCardSprite_2(i) |
|
|
|
} |
|
|
|
if(this.cardType_Node_1 && this.cardType_1.isValid)this.cardType_Node_1.active = true; |
|
|
|
if(this.cardType_Node_2 && this.cardType_2.isValid)this.cardType_Node_2.active = true; |
|
|
|
} |
|
|
|
|
|
|
|
/**关闭UI */ |
|
|
@ -125,6 +248,9 @@ export class TeenPattieBiPaiSuccGamePanel extends Component { |
|
|
|
this.tid=null |
|
|
|
|
|
|
|
this.timeLabel = 3; |
|
|
|
this.clickNum = 1; |
|
|
|
this.anumNum_1 = 0; |
|
|
|
this.anumNum_2 = 0; |
|
|
|
|
|
|
|
Message.send(TeenPattieEventType.PkCardEnd); |
|
|
|
TeenPattieCommTool.gamePause(GameStatus.Recover); |
|
|
@ -140,25 +266,102 @@ export class TeenPattieBiPaiSuccGamePanel extends Component { |
|
|
|
if(win && win.SeatId == TeenPattieCommData.getInstance().playerSeatId) AudioManager.getInstance().playEffect(GameSound.bipaiWin) |
|
|
|
|
|
|
|
//发起方
|
|
|
|
this.initFaqiData(win); |
|
|
|
const selfCardCard = TeenPattieCommData.getInstance().bipaiPlayerCardData; |
|
|
|
this.initFaqiData(selfCardCard, win); |
|
|
|
//被发起方
|
|
|
|
this.initBeiFaqiData(lost); |
|
|
|
const beiPlayerCardCard = TeenPattieCommData.getInstance().beiBipaiPlayerCardData; |
|
|
|
this.initBeiFaqiData(beiPlayerCardCard, lost); |
|
|
|
} |
|
|
|
|
|
|
|
/**发起方数据初始化 */ |
|
|
|
private initFaqiData(win: any) { |
|
|
|
private initFaqiData(playerCard: any, win: any) { |
|
|
|
this.faqiData = win; |
|
|
|
TeenPattiePathTool.setAvatar(this.biPai_faqi_head, win.avatar); |
|
|
|
TeenPattiePathTool.setAvatarFrame(this.biPai_faqi_frame, win.avatar_vip); |
|
|
|
this.biPai_faqi_naicName.string = win.nickname; |
|
|
|
|
|
|
|
if(!playerCard){ |
|
|
|
this.bipai_faqi_cards.active = false; |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
const cards = playerCard.Cards; |
|
|
|
const cardsType = playerCard.CardType; |
|
|
|
async function findCardsType(owner: TeenPattieBiPaiSuccGamePanel) { |
|
|
|
let sp: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, `res/cardsType/${cardsType}/spriteFrame`, SpriteFrame) as SpriteFrame; |
|
|
|
owner.cardType_1.spriteFrame = sp; |
|
|
|
} |
|
|
|
findCardsType(this); |
|
|
|
|
|
|
|
this.cards_1 = cards |
|
|
|
} |
|
|
|
|
|
|
|
private cards_1:any |
|
|
|
/**翻牌 1 */ |
|
|
|
private setCardSprite_1(num:number){ |
|
|
|
const cards = this.cards_1 |
|
|
|
if(!cards || !this.cardList_1) return; |
|
|
|
//牌的花色
|
|
|
|
const suitType = cards[num].suit; |
|
|
|
//牌的值
|
|
|
|
const suitValue = cards[num].value; |
|
|
|
const anumNum = num |
|
|
|
const path = TeenPattiePathTool.getCardPath(suitType,suitValue) |
|
|
|
async function findSpriteFrame(owner: TeenPattieBiPaiSuccGamePanel) { |
|
|
|
const url = path; |
|
|
|
let spriteFrame: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, url, SpriteFrame) as SpriteFrame; |
|
|
|
owner.cardList_1[anumNum].spriteFrame = spriteFrame; |
|
|
|
} |
|
|
|
findSpriteFrame(this); |
|
|
|
if(anumNum >= 2){ |
|
|
|
this.cardType_Node_1.active = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**被发起方数据初始化 */ |
|
|
|
private initBeiFaqiData(lost: any) { |
|
|
|
private initBeiFaqiData(playerCard: any, lost: any) { |
|
|
|
this.beiFaqiData = lost; |
|
|
|
TeenPattiePathTool.setAvatar(this.biPai_beifaqi_head, lost.avatar); |
|
|
|
TeenPattiePathTool.setAvatarFrame(this.biPai_beifaqi_frame, lost.avatar_vip); |
|
|
|
this.biPai_beifaqi_naicName.string = lost.nickname; |
|
|
|
this.beifaqi_win.active = this.result.winSeatId == lost.SeatId; |
|
|
|
|
|
|
|
if(!playerCard){ |
|
|
|
this.bipai_beifaqi_cards.active = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const cards = playerCard.Cards; |
|
|
|
const cardsType = playerCard.CardType; |
|
|
|
async function findCardsType(owner: TeenPattieBiPaiSuccGamePanel) { |
|
|
|
let sp: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, `res/cardsType/${cardsType}/spriteFrame`, SpriteFrame) as SpriteFrame; |
|
|
|
owner.cardType_2.spriteFrame = sp; |
|
|
|
} |
|
|
|
findCardsType(this); |
|
|
|
|
|
|
|
this.cards_2 = cards |
|
|
|
} |
|
|
|
|
|
|
|
private cards_2:any |
|
|
|
/**翻牌 2 */ |
|
|
|
private setCardSprite_2(num:number){ |
|
|
|
const cards = this.cards_2 |
|
|
|
if(!cards || !this.cardList_2) return; |
|
|
|
//牌的花色
|
|
|
|
const suitType = cards[num].suit; |
|
|
|
//牌的值
|
|
|
|
const suitValue = cards[num].value; |
|
|
|
const anumNum = num |
|
|
|
const path = TeenPattiePathTool.getCardPath(suitType,suitValue) |
|
|
|
async function findSpriteFrame(owner: TeenPattieBiPaiSuccGamePanel) { |
|
|
|
const url = path; |
|
|
|
let spriteFrame: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, url, SpriteFrame) as SpriteFrame; |
|
|
|
owner.cardList_2[anumNum].spriteFrame = spriteFrame; |
|
|
|
} |
|
|
|
findSpriteFrame(this); |
|
|
|
if(anumNum >= 2){ |
|
|
|
this.cardType_Node_2.active = true; |
|
|
|
} |
|
|
|
} |
|
|
|
/**动画播放完成后显示赢家 */ |
|
|
|
private showWinPlayer(){ |
|
|
|