123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- var GamePlayer = require("GamePlayer");
- var Define = require("Define");
- var Global = require("Global");
- var UIHelper = require("UIHelper");
- import { CServerItem } from 'CServerItem'
- import ScenceManager from 'HNScenceManager'
- var BaseDefine = require("BaseDefine");
- var SoundFun = require("TrucoSoundFun");
- var GameProtocol = require("TrucoGameProtocol");
- var ProtocolGameServer = require("ProtocolGameServer");
- const propConfig = require("propConfig");
- cc.Class({
- extends: GamePlayer,
- //extends: cc.Component,
- editor: {
- menu: 'Game/Truco/GamePlayer'
- },
- properties: {
- sprHeadIcon:cc.Sprite, //头像
- sprVipIcon:cc.Sprite, // VIP框
- btnHead:cc.Button,
- btnGift:cc.Button,
- sprEmptyHeadIcon:cc.Sprite,
- labScore:cc.Label, //分数
- labName:cc.Label, //昵称
- infoNode: cc.Node,
- cardsNode: cc.Node,
- OffineFlag:cc.Node, //离线标记
- TrusteeFlag: cc.Node,
- EmojiNode: cc.Node,
- trucoEmoNode: cc.Node,
- chatTxtNode: cc.Node,
- readyNode:cc.Node,
- trucoState:cc.Node,
- trucoNode: cc.Node,
- trucoChoose: cc.Node,
- outCardNode: cc.Node,
- _magicCardValue: -1,
- iIndex:-1,
- _CurGameScene:null,
- _myScore:0,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function() {
- this.handCardPos = [
- {x:[-104,6,115], y:[-303,-303,-303], angle:0, scale:0.55},
- {x:[-422,-422,-422], y:[22,-7,-36], angle:-90, scale:0.42},
- {x:[44,121,198], y:[295,295,295], angle:0, scale:0.4},
- {x:[418,418,418], y:[22,-7,-36], angle:90, scale:0.42},
- ];
- this.outCardStartPos = [
- {x:6, y:-303},
- {x:-422, y:-7},
- {x:121, y:295},
- {x:418, y:-7},
- ];
- this.outCardPos = [
- {x:6, y:-110, angle:0, scale:0.4},
- {x:-150, y:-7, angle:-70, scale:0.4},
- {x:6, y:110, angle:180, scale:0.4},
- {x:150, y:-7, angle:70, scale:0.4},
- ];
- this._isGameEnd = false;
- this._tenCardPosX = 724;
- this.needPlayScoreAni = false;
- this.trusteeState = 0;
- this._chatTxtTimes = 0;
- // this.sprVipIcon.node.width = 118;
- // this.sprVipIcon.node.height = 118;
- this.sprVipIcon.node.scale = 0.25;
- if(this.infoNode) {
- this.infoNode.active = false;
- this.loadMemeProp();
- }
- this.myHandCards = [];
- this.hideHandCard();
- this.hideTruco();
- this.hideTrucoChoose();
- UIHelper.addButtonListener(this.btnHead.node, this.node, "TrucoPlayer", "onClickeHead");
- UIHelper.addButtonListener(this.btnGift.node, this.node, "TrucoPlayer", "onClickeHead");
- },
-
- init: function(index) {
-
- },
- playerEnter: function(){
- Global.print("用户playerEnter")
- this.node.getChildByName("PlayerHead").active = true;
- // this.sprEmptyHeadIcon.node.active = false;
- this.sprHeadIcon.node.active = true;
- this.btnHead.node.userID = this.getUserID();
- this.btnHead.node.gameID = this.getGameID();
- this.btnGift.node.userID = this.getUserID();
- this.btnGift.node.gameID = this.getGameID();
- this.node.active = true;
- this.needPlayScoreAni = false;
- this._bMingCard = false;
- this.changeTrusteeState(0);
- this.setScore(this.getUserScore());
- this.hideTruco();
- this.hideTrucoChoose();
- this.hideTimeNode();
- this.node.getChildByName("AndroidTip").active = (this.getAndroidTip()==1 && BaseDefine.LOCALTEST);
- },
- playerLeave:function() {
- this.labName.string = "";
- this.sprEmptyHeadIcon.node.active = true;
- this.sprHeadIcon.node.active = false;
-
- this.node.getChildByName("AndroidTip").active = false;
- this.hideTimeNode();
- this.upPlayerInfo();
- this.upPlayerHead();
- this.upPlayerState();
- Global.print("用户离开了")
- this.sprVipIcon.node.active = false;
- this.node.active = false;
- },
- upPlayer:function(show)
- {
- this.upPlayerInfo();
- this.upPlayerHead();
- this.node.active = show;
- },
- upPlayerState: function() {
- this.setOffline(this.getUserStatus() == Define.US_OFFLINE);
- },
- upPlayerInfo: function() {
- if (this.getNickName() != "") {
- var str = this.getNickName();
- let len = 6;
- this.labName.string = Global.subStr(str,len);
- }
- this.setScore(this.getUserScore());
- },
- setNameLabelActive:function(show){
- },
- setVIPActive:function(show){
- this.sprVipIcon.node.active = show;
- },
- getnickName: function()
- {
- return this.labName.string
- },
- upPlayerHead: function() {
- if (this.getHeadHttp() != "") {
- // 设置头像
- this.sprHeadIcon.getComponent("urlSpriteFrame").loadAvatar(this.getHeadHttp(),null, {width:120, height:120});
- } else {
- this.sprHeadIcon.spriteFrame = this.spriteFrame;
- this.sprHeadIcon.node.width = 120;
- this.sprHeadIcon.node.height = 120;
- }
- this.sprHeadIcon.node.active = true;
- let vipID = this.getVIPLevel();
- if(vipID >= 4 && vipID <= 7) {
- this.sprVipIcon.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
- this.sprVipIcon.node.active = true;
- }else{
- this.sprVipIcon.node.active = false;
- }
- },
- getHeadSpriteFrame() {
- return this.sprHeadIcon.spriteFrame;
- },
- getVIPSpriteFrame() {
- return this.sprVipIcon.spriteFrame;
- },
- //游戏结束,隐藏VIP框
- hideVIP() {
- this.sprVipIcon.node.active = false;
- },
- getHeadIcon: function(ret) {
- if(ret)
- {
- return this.sprHeadIcon.spriteFrame;
- }
- if (this.getHeadHttp() != "") {
- return this.sprHeadIcon.spriteFrame;
- }
- return null;
- },
- getIndex: function() {
- return this.iIndex;
- },
- setScore: function(score) {
- this._myScore = score;
- var strScore = this.changeScore(Global.formatString2Score(score));
- this.labScore.string = strScore;
- },
- getScore: function() {
- return this._myScore;
- },
- setOffline: function(isOffline) {
- this.OffineFlag.active = isOffline;
- if (isOffline) {
- this.TrusteeFlag.active = false;
- }else{
- this.changeTrusteeState(this.trusteeState);
- }
- },
- setEndGameState(bbb) {
- this.needPlayScoreAni = bbb;
- },
- getEndGameState() {
- return this.needPlayScoreAni;
- },
- setEndGameScore(score) {
- this.needPlayScore = score;
- },
- getEndGameScore() {
- return this.needPlayScore;
- },
- changeTrusteeState(state) {
- this.trusteeState = state;
- this.TrusteeFlag.active = state;
- },
- playTruco(score) {
- this.trucoNode.active = true;
- this.trucoNode.getChildByName("bg").getChildByName("label").getComponent(cc.Label).string = '+'+score;
- let ani = this.trucoNode.getChildByName("ani").getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- },
- hideTruco() {
- this.trucoNode.active = false;
- },
- showTrucoChoose(type) {
- this.trucoChoose.active = true;
- let ani = this.trucoChoose.getComponent(sp.Skeleton);
- ani.clearTracks();
- if(type == 1) {
- ani.setAnimation(0, "b1", false);
- ani.addAnimation(0, "b2", true);
- }else{
- ani.setAnimation(0, "a1", false);
- ani.addAnimation(0, "a2", true);
- }
- this.trucoState.active = true;
- this.trucoState.getChildByName("ace").active = type == 1;
- this.trucoState.getChildByName("cor").active = type == 2;
- },
- hideTrucoChoose() {
- this.trucoChoose.active = false;
- this.trucoState.active = false;
- },
- showPe: function(isPe) {
- this.readyNode.active = isPe;
- },
- playTimeAction: function(UserLeftTime){
- this.node.getChildByName("TimeNode").active = true;
- this.node.getChildByName("TimeNode").getComponent("TrucoTimePointer").playTimeAction(UserLeftTime,this.iIndex==0);
- },
- hideTimeNode:function(){
- this.node.getChildByName("TimeNode").active = false;
- this.node.getChildByName("TimeNode").getComponent("TrucoTimePointer").stopTimeSchedule();
- },
- start () {
-
- },
- update(dt) {
- if(this._chatTxtTimes > 0) {
- this._chatTxtTimes-=dt;
- if(this._chatTxtTimes <= 0) {
- this.hideChatNode();
- }
- }
- },
- hideChatNode() {
- this.chatTxtNode.stopAllActions()
- cc.tween(this.chatTxtNode)
- .to(0.2, {scale: 0})
- .call(()=>{
- this.chatTxtNode.active = false;
- })
- .start()
- },
- showTalkState: function(data){
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TALK_TYPE){
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD){
- if(data.String == ""){
- return;
- }
-
- this.chatTxtNode.stopAllActions()
- this.chatTxtNode.scale = 0;
- this.chatTxtNode.active = true;
- this.chatTxtNode.getChildByName("msg").getComponent(cc.Label).string = data.String;
- cc.tween(this.chatTxtNode)
- .to(0.2, {scale: 1})
- .start()
- this._chatTxtTimes = 3;
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_DEFINE){
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING)
- {
- if(data.String == ""){
- return;
- }
- let memeIdx = parseInt(data.String);
- if(memeIdx >= 100){
- this.trucoEmoNode.active = true;
- var Ani = this.trucoEmoNode.getComponent(sp.Skeleton);
- Ani.setAnimation(0,"a"+(memeIdx-100),false);
- return;
- }
- this.EmojiNode.active = true;
- var Ani = this.EmojiNode.getComponent(sp.Skeleton);
- Ani.setAnimation(0,"a"+memeIdx,false);
- }
- },
- rePlayHandCardShow() {
- if(this.iIndex <= 0) return;
- this.cardsNode.active = true;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].position = this.handCardPos[this.iIndex];
- this.cardsNode.children[i].scale = 0.6;
- this.cardsNode.children[i].angle = 0;
- this.cardsNode.children[i].getComponent("TrucoCard").setId(0,0);
- this.cardsNode.children[i].active = true;
- }
- },
- getHandCardPos() {
- return this.handCardPos[this.iIndex];
- },
- hideHandCard() {
- if(!this.cardsNode) return;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].stopAllActions();
- this.cardsNode.children[i].x = 429+9;
- this.cardsNode.children[i].y = 231+9;
- this.cardsNode.children[i].scale = 0.43;
- if(this.cardsNode.children[i].is3DNode) {
- this.cardsNode.children[i].eulerAngles = cc.v3(0,0,0);
- }else{
- this.cardsNode.children[i].angle = 0;
- }
- this.cardsNode.children[i].cardValue = 0;
- this.cardsNode.children[i].getComponent("TrucoCard").setId(0,0);
- this.cardsNode.children[i].active = false;
- }
- this.outCardNode.getChildByName("diAni").active = false;
- this.outCardNode.getChildByName("ani").active = false;
- this.outCardNode.active = false;
- this.cardsNode.active = true;
- // this.huAniNode.active = false;
- // this.myHandCards.splice(0);
- this.myHandCards = [];
- this.handCardCount = 0;
- this._bMingCard = false;
- },
- changeMingCard(bMing) {
- this._bMingCard = bMing;
- },
- getHandCardValue(idx) {
- if(this.handCards && this.handCards.length > idx) {
- return this.handCards[idx];
- }
- return 0;
- },
- resetHandCardPos() {
- if(!this.cardsNode) return;
- this.cardsNode.active = true;
- let config = this.handCardPos[this.iIndex];
- let cards = this.handCards;
- let count = this.handCardCount;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].active = false;
- this.cardsNode.children[i].cardValue = cards?cards[i]:0;
- if(this.iIndex == 0)
- Global.print(this.cardsNode.children[i].cardValue)
- }
- if(this._bMingCard) {
- let cardIdx = 0;
- for(let i = 0; i < cards.length; ++i) {
- if(cards[i] > 0) {
- let card = this.cardsNode.children[cardIdx];
- if(card) {
- card.getComponent("TrucoCard").setId(cards[i], this._magicCardValue);
- card.scale = config.scale;
- card.x = config.x[cardIdx];
- card.y = config.y[cardIdx];
- card.angle = config.angle;
- card.active = true;
- cardIdx++;
- }
- }
- }
- }else{
- for(let i = 0; i < count; ++i) {
- let card = this.cardsNode.children[i];
- if(card) {
- card.getComponent("TrucoCard").setId(0,0);
- card.scale = config.scale;
- card.x = config.x[i];
- card.y = config.y[i];
- card.angle = config.angle;
- card.active = true;
- }
- }
- }
- },
- setMagicCardValue(val) {
- this._magicCardValue = val;
- },
- setHandCards(cards, count, needReset) {
- this.handCards = cards.slice(0);
- this.handCardCount = count;
- if(needReset)
- this.resetHandCardPos();
- return;
- let config = this.handCardPos[this.iIndex];
- if(this.iIndex == 0) {
- let cardIdx = 0;
- for(let i = 0; i < cards.length; ++i) {
- if(cards[i] > 0) {
- let card = this.cardsNode.children[cardIdx];
- if(card) {
- card.getComponent("TrucoCard").setId(cards[i],0);
- card.scale = config.scale;
- card.x = config.x[cardIdx];
- card.y = config.y[cardIdx];
- card.angle = config.angle;
- card.active = true;
- cardIdx++;
- }
- }
- }
- }else{
- for(let i = 0; i < count; ++i) {
- let card = this.cardsNode.children[i];
- if(card) {
- card.getComponent("TrucoCard").setId(0,0);
- card.scale = config.scale;
- card.x = config.x[i];
- card.y = config.y[i];
- card.angle = config.angle;
- card.active = true;
- }
- }
- }
- },
- oneCardMove(cardIdx) {
- let config = this.handCardPos[this.iIndex];
- if(!config) {return;}
- let card = this.cardsNode.children[cardIdx];
- this.handCardCount = 3;
- if(card) {
- card.active = true;
- cc.tween(card)
- .to(0.2, {x: config.x[cardIdx], y:config.y[cardIdx], scale: config.scale, angle: config.angle})
- .start()
- }
- },
- outOneCard(cardid, magicCard) {
- this._outCard = cardid;
- if(this.handCards) {
- for(let i = 0; i < this.handCards.length; ++i) {
- if(this.handCards[i] == cardid) {
- this.handCards.splice(i, 1);
- break;
- }
- }
- // }else{
- // this.handCards.splice(0, 1);
- }
- this.handCardCount--;
- this.resetHandCardPos();
- this.showOutCard(cardid, magicCard);
- // let card = this.cardsNode.children[2];
- // if(card) {
- // card.scale = outConfig.scale;
- // card.x = outConfig.x;
- // card.y = outConfig.y;
- // card.angle = outConfig.angle;
- // card.active = true;
- // card.getComponent("TrucoCard").setId(cardid, magicCard);
- // }
- },
- showOutCard(cardid, magicCard) {
- if(cardid <= 0) {return;}
- let outConfig = this.outCardPos[this.iIndex];
- let startPos = this.outCardStartPos[this.iIndex];
- if(!outConfig) {return;}
- this._outCard = cardid;
- let card = this.outCardNode;
- if(card) {
- card.scale = 0;
- card.x = startPos.x;
- card.y = startPos.y;
- card.angle = outConfig.angle;
- card.active = true;
- card.getChildByName("card0").getComponent("TrucoCard").setId(cardid, magicCard);
- card.getChildByName("diAni").active = false;
- let ani = card.getChildByName("ani");
- ani.active = false;
- cc.tween(card)
- .to(0.1, {x: outConfig.x, y:outConfig.y, scale:outConfig.scale})
- .call(()=>{
- ani.active = card.getChildByName("card0").getComponent("TrucoCard").isJoker();
- ani.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
- })
- .start();
-
- // ani.active = card.getChildByName("card0").getComponent("TrucoCard").isJoker();
- // ani.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
- }
- },
- getOutCard() {
- return this._outCard;
- },
- getHandCards() {
- return this.myHandCards;
- },
- playLightCardAni() {
- let card = this.outCardNode;
- if(card) {
- card.active = true;
- let ani = card.getChildByName("diAni");
- ani.active = true;
- ani.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
- }
- },
- outCardMoveToTrush() {
- let card = this.outCardNode;
- if(card) {
- card.active = true;
- card.stopAllActions();
- cc.tween(card)
- .to(0.3, {x:438, y:240, scale:0})
- .start()
- }
- },
- loadMemeProp: function() {
- let memePropConfig = Array.from(propConfig.getMemePropConfig());
- cc.resources.loadDir("GameTextures/Public/MemeProp", cc.SpriteFrame, (error, assets) => {
- if(error) {
- Global.print("loadRes:: error:" + error.message);
- } else {
- for(let i = 0; i < memePropConfig.length; ++i) {
- let config = memePropConfig[i]
- let asset = assets.find(asset => asset.name == config.description);
- if(!asset) {continue;}
- let node = this.infoNode.children[i];
- node.name = config.id.toString();
- node.getChildByName("img").getComponent(cc.Sprite).spriteFrame = asset;
- UIHelper.addButtonListener(node, this.node, "TrucoPlayer", "onClickMemePropItem");
- }
- }
- })
- },
- onClickMemePropItem: function(event) {
- let item = event.target;
- let id = item.name;
- ScenceManager.Instance().getGameComponent().useProp(id, 1, this.getUserID());
- this.playTimePointerAni();
- Global.print("GameHeadInfo:: 使用互动表情:" + id);
- this.hideInfoNode();
- },
- onClickeHead() {
- if(!this.infoNode || this.iIndex == 0) {
- return;
- }
- ScenceManager.Instance().getGameComponent().hideAllMene();
- this.infoNode.active = true;
- },
- hideInfoNode() {
- if(!this.infoNode || this.iIndex == 0) {
- return;
- }
- this.infoNode.active = false;
- },
- playTimePointerAni: function() {
- const TIME_POINT = 5; // 时钟总时间
- for(let item of this.infoNode.children) {
- item.getComponent(cc.Button).interactable = false;
- let timeNode = item.getChildByName("timePointer");
- let timeLabel = timeNode.getChildByName("label").getComponent(cc.Label);
- let timeSprite = timeNode.getChildByName("sprite").getComponent(cc.Sprite);
- let time = TIME_POINT;
- timeLabel.string = TIME_POINT;
- timeSprite.fillRange = 1;
- if(timeNode.active) {return;}
- timeNode.active = true;
- let timePointFunc = (dt) => {
- time -= dt; // dt:与上次调用间隔时间
- if(time > 0) {
- timeLabel.string = Math.floor(time);
- timeSprite.fillRange = (time / TIME_POINT);
- } else {
- item.getComponent(cc.Button).interactable = true;
- timeNode.active = false;
- this.unschedule(timePointFunc);
- }
- }
- this.schedule(timePointFunc, 0.1);
- }
- },
- });
|