You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
9.3 KiB
241 lines
9.3 KiB
import { _decorator,Node,Label, Sprite, find, UITransform, Vec3, Tween, tween, instantiate } from "cc";
|
|
import { Game20009BaseComp } from "./Game20009BaseComp";
|
|
import { AudioManager, GameUtils, IsNullOrEmpty, Message} from "../sdk/API";
|
|
import { UserData } from "../sdk/GameVO";
|
|
import { Game20006Res } from "../controller/Game20006Res";
|
|
import { GameController } from "../controller/GameController";
|
|
import { GameOptSubItemComp } from "./sub/GameOptSubItemComp";
|
|
import { ShakeComp } from "../efct/ShakeComp";
|
|
import { FlyGoldLabelComp } from "../efct/FlyGoldLabelComp";
|
|
import { GameObject } from "../controller/GameObject";
|
|
import { SoundConst } from "../Game2006Const";
|
|
import { Game20006Tools } from "../units/Game20006Tools";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('PlayerHeadInfoComp')
|
|
export class PlayerHeadInfoComp extends Game20009BaseComp{
|
|
@property({type:Boolean})
|
|
isPlayer:boolean=false
|
|
|
|
private icon:Sprite
|
|
private headFont:Sprite
|
|
private nickName:Label
|
|
private gold:Label
|
|
private lucky:Node
|
|
|
|
private name_bg:Node
|
|
private gold_bg:Node
|
|
|
|
private headUITRF:UITransform
|
|
|
|
|
|
private _flyLab:FlyGoldLabelComp
|
|
|
|
data:any
|
|
|
|
shake:ShakeComp
|
|
playShake(offsetx?:number,duration ?:number,count?:number,call?:()=>void){
|
|
if(this.shake && this.shake.isValid){
|
|
this.shake.Run(offsetx,duration,call)
|
|
}
|
|
}
|
|
/** 玩家飘文本信息 */
|
|
flyLab(num:number,duration?:number,isWinner?:boolean,callback?:()=>void){
|
|
if(this._flyLab && this._flyLab.isValid){
|
|
this._flyLab.fly(num,duration,isWinner,callback)
|
|
}
|
|
}
|
|
|
|
protected onLoad(): void {
|
|
let con:Node=find("con",this.node)
|
|
this.lucky = find("lucky",con)
|
|
this.name_bg=find("name_bg",con)
|
|
this.gold_bg=find("gold_bg",con)
|
|
this.icon = find("head/icon",con)?.getComponent(Sprite)
|
|
this.headFont = find("headFont",con)?.getComponent(Sprite)
|
|
this.nickName = find("name_bg/Label",con)?.getComponent(Label)
|
|
this.gold = find("gold_bg/Label",con)?.getComponent(Label)
|
|
|
|
this.headUITRF =find("head",con)?.getComponent(UITransform)
|
|
this.shake = con.getComponent(ShakeComp)
|
|
if(!this.shake)this.shake=con.addComponent(ShakeComp)
|
|
|
|
this._flyLab = find("TipsLabel",this.node)?.getComponent(FlyGoldLabelComp)
|
|
|
|
this.showLuck(false)
|
|
this.clear();
|
|
}
|
|
|
|
protected start(): void {
|
|
if(this.isPlayer){
|
|
// Message.add("User_Data_Chanaged",this.onUserDataChanaged,this)
|
|
Message.add("PlayerClickBetGold",this.onPlayerClickBetGold,this)
|
|
Message.add("BetRespose",this.onBetRespose,this)
|
|
Message.add("gameAddGold",this.onUserDataChanaged,this)
|
|
Message.add("ClearCurrentBet",this.onClearCurrentBet,this);
|
|
}
|
|
|
|
}
|
|
protected onDestroy(): void {
|
|
this.currentBet=null
|
|
// Message.remove("User_Data_Chanaged",this.onUserDataChanaged,this)
|
|
Message.remove("PlayerClickBetGold",this.onPlayerClickBetGold,this)
|
|
Message.remove("BetRespose",this.onBetRespose,this)
|
|
Message.remove("gameAddGold",this.onUserDataChanaged,this)
|
|
Message.remove("ClearCurrentBet",this.onClearCurrentBet,this);
|
|
|
|
}
|
|
private _isHandler:boolean=false
|
|
private onBetRespose(val:any){
|
|
if(val.code == 0){
|
|
if(this._isHandler)return
|
|
this._isHandler=true
|
|
console.log("下注 >> ",JSON.stringify(val))
|
|
// if(this.currentBet)GameController.getInstance().addPlayerOpt(Object.assign({},this.currentBet))
|
|
if(this.currentBet)GameController.getInstance().addPlayerOpt(this.currentBet)
|
|
if(val.userScore && this.isPlayer){
|
|
this.onUserDataChanaged(val.userScore)
|
|
}
|
|
let infos:any[]=val.betInfo || []
|
|
for(let i=0;i<infos?.length;i++){
|
|
let info:any=infos[i]
|
|
GameController.getInstance().setPlayerBetScore(info.betAmount);
|
|
let itemInfo:any=GameController.getInstance().getPlayerOptItem(info.betArea)
|
|
if(itemInfo){
|
|
let tabitem:GameOptSubItemComp = GameController.getInstance().getBetArea(info.betArea)
|
|
if(tabitem){
|
|
tabitem.setPlayerBetData(info.betAmount)
|
|
tabitem.setBetData({areaTotalAmount:info.areaTotalAmount})
|
|
AudioManager.getInstance().playEffect(SoundConst.Betting_chip)
|
|
this.flyGold(itemInfo.betVal.areaId,tabitem.getWorldPos(),itemInfo.betVal,itemInfo.goldlayer,info.betAmount)
|
|
}
|
|
}
|
|
}
|
|
// this.currentBet=null
|
|
this._isHandler=false
|
|
}else{
|
|
console.log("下注错误 >> ",JSON.stringify(val))
|
|
// GameController.getInstance().clearPlayerOpt();
|
|
}
|
|
}
|
|
private onClearCurrentBet(){
|
|
this.currentBet=null
|
|
}
|
|
private currentBet:any
|
|
//用户点击了下注
|
|
private onPlayerClickBetGold(pos:Vec3,betVal:any,goldlayer:Node){
|
|
let betAmount:number=GameController.getInstance().getCurBetValue()
|
|
if(!this.currentBet) this.currentBet=[]
|
|
const data ={
|
|
pos:pos,
|
|
betArea:betVal.betArea,
|
|
// betArea:betVal.areaId,
|
|
betVal:betVal,
|
|
goldlayer:goldlayer,
|
|
betAmount:betAmount
|
|
}
|
|
this.currentBet.push(data)
|
|
let infos:any[]=[
|
|
{
|
|
betArea:betVal.betArea,
|
|
betAmount:betAmount,
|
|
areaTotalAmount:0
|
|
}
|
|
]
|
|
// if(this.currentBet)GameController.getInstance().addPlayerOpt(Object.assign({},this.currentBet))
|
|
GameController.getInstance().proxy.sendPlayerBetRequest(infos)
|
|
|
|
}
|
|
|
|
flyGold(areaId:number,pos:Vec3,betVal:any,goldlayer:Node,betAmount?:number){
|
|
if(!this.node || !this.node.isValid)return
|
|
this.playShake() //晃动
|
|
|
|
let uitrf:UITransform=this.node.getComponent(UITransform)
|
|
const btnItems:number[] = Game20006Tools.getSplitChips(betAmount)
|
|
for(let i=0;i<btnItems.length;i++){
|
|
let item_prefab:Node = GameController.getInstance().cloneGold(btnItems[i])
|
|
item_prefab.scale=GameController.getInstance().getGoldScale()
|
|
this.node.addChild(item_prefab)
|
|
|
|
GameController.getInstance().addGoldToStage(areaId,item_prefab)
|
|
const n = GameUtils.randomRange(2,10);
|
|
let new_pos:Vec3=pos.clone()
|
|
new_pos.x += n
|
|
new_pos.y += n
|
|
new_pos = uitrf.convertToNodeSpaceAR(new_pos)
|
|
// item_prefab.worldPosition=this.node.worldPosition
|
|
let flyGoldTween:Tween<Node>=tween(item_prefab).by(0.3,{worldPosition:new_pos},{
|
|
onComplete:()=>{
|
|
flyGoldTween.stop();
|
|
flyGoldTween=null
|
|
}
|
|
}).start()
|
|
}
|
|
}
|
|
//播放玩家胜利音效
|
|
playWinSound(){
|
|
AudioManager.getInstance().playEffect(SoundConst.Player_win)
|
|
}
|
|
onUserDataChanaged(gold:number){
|
|
if(this.isPlayer && this.gold && this.gold.isValid){
|
|
this.gold.string=`${(gold / 1000).toFixed(2)}`
|
|
}
|
|
}
|
|
public clear(){
|
|
if(this.name_bg && this.name_bg.isValid)this.name_bg.active=false
|
|
// if(this.gold_bg && this.gold_bg.isValid)this.gold_bg.active=false
|
|
}
|
|
public clearGoldItem(){
|
|
while(this.node.children?.length > 2){
|
|
GameObject.getInstance().pushObj(this.node.children[2])
|
|
}
|
|
}
|
|
public setData(val:any){
|
|
this.data = val
|
|
if(!this.data){
|
|
this.clear();
|
|
return
|
|
}
|
|
|
|
if(this.isPlayer){
|
|
this.onUserDataChanaged(this.data.gold)
|
|
this.nickName.string=UserData.nickname
|
|
}
|
|
else {
|
|
this.changedGold(this.data.tableWin)
|
|
this.nickName.string=this.data.nickname
|
|
}
|
|
|
|
if(!IsNullOrEmpty(this.data.avatar)){
|
|
if(this.name_bg && this.name_bg.isValid)this.name_bg.active=true
|
|
// if(this.gold_bg && this.gold_bg.isValid)this.gold_bg.active=true
|
|
Game20006Res.getInstance().setAvatar(this.icon, `${this.data.avatar || 1}`);
|
|
Game20006Res.getInstance().setAvatarFrame(this.headFont, `${this.data.level || 1}`);
|
|
}else{
|
|
if(this.name_bg && this.name_bg.isValid)this.name_bg.active=false
|
|
// if(this.gold_bg && this.gold_bg.isValid)this.gold_bg.active=false
|
|
}
|
|
|
|
|
|
this.setSize()
|
|
|
|
}
|
|
showLuck(status:boolean){
|
|
if(this.lucky && this.lucky.isValid){
|
|
this.lucky.active=status
|
|
}
|
|
}
|
|
changedGold(value:number){
|
|
if(!this.gold && !this.gold.isValid)return
|
|
this.gold.string=`${(value/1000).toFixed(2)}`
|
|
}
|
|
private setSize(){
|
|
let puif:UITransform=this.headFont.getComponent(UITransform)
|
|
if(puif){
|
|
this.headUITRF.width=puif.width
|
|
this.headUITRF.height = puif.height
|
|
}
|
|
|
|
}
|
|
}
|