123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- let Global = require("Global");
- let GamePlayer = require("GamePlayer");
- let ScenceManager = require("HNScenceManager");
- const UIHelper = require("UIHelper");
- cc.Class({
- extends: GamePlayer,
- properties: {
- },
- onLoad() {
- },
- inits(node) {
- this.node = node;
- this.initConfig();
- this.initHeadNode();
- },
- initConfig() {
- this.initWhiteList = ["sprite_playerHead", "sprite_playerNameBg", "label_playerName", "sprite_myCoinBg", "sprite_myCoin", "label_myCoin"];
- this.sprite_vip = UIHelper.pathGetNode(this.node, "sprite_playerHead/sprite_vip");
- this.sprite_title = UIHelper.pathGetNode(this.node, "sprite_playerHead/sprite_title");
- this.sprite_playerHead = UIHelper.pathGetNode(this.node, "sprite_playerHead");
- this.spine_playerWin = UIHelper.pathGetNode(this.node, "spine_playerWin");
- this.sprite_playerFail = UIHelper.pathGetNode(this.node, "sprite_playerFail");
- this.sprite_playerWin = UIHelper.pathGetNode(this.node, "sprite_playerWin");
- this.label_playerName = UIHelper.pathGetNode(this.node, "label_playerName");
- this.emptySprite = this.sprite_playerHead.getComponent(cc.Sprite).spriteFrame;
- },
- _initNode() {
- for (let i = 0; i < this.node.children.length; i += 1) {
- let node = this.node.children[i];
- node.active = this.initWhiteList.indexOf(node.name) >= 0;
- }
- },
- initHeadNode() {
- this._initNode();
- this._setUserNameLabel();
- this._setUserHead();
- this._setUserVip();
- this._setUserTitle();
- },
- refreshHeadNode() {
- this._initNode();
- this._setUserNameLabel("");
- this._setUserHead("");
- this._setUserVip(-1);
- this._setUserTitle();
- this.node.stopAllActions();
- },
- initMyself() {
- this.sprite_myCoinBg = UIHelper.pathGetNode(this.node, "sprite_myCoinBg");
- this.sprite_myCoin = UIHelper.pathGetNode(this.node, "sprite_myCoin");
- this.label_myCoin = UIHelper.pathGetNode(this.node, "label_myCoin");
- if (this.sprite_myCoinBg && this.sprite_myCoin && this.label_myCoin) {
- this.sprite_myCoinBg.active = true;
- this.sprite_myCoin.active = true;
- this.label_myCoin.active = true;
- this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(this.getUserScore());
- this.initConfig();
- this.initHeadNode();
- }
- },
- refreshMyself(num) {
- if (this.label_myCoin) {
- let score = (this.getUserScore() - num);
- this.setUserScore(score);
- this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(score);
- }
- },
- setScore(score) {
- this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(score);
- this.setUserScore(score);
- },
- _setUserNameLabel(str = this.getNickName()) {
- if (!this.label_playerName) {
- return;
- }
- let label = this.label_playerName.getComponent(cc.Label);
- label.string = str;
- },
- _setUserHead(url = this.getHeadHttp()) {
- if (!this.sprite_playerHead) {
- return;
- }
- this.sprite_playerHead.width = 105;
- this.sprite_playerHead.height = 105;
- let sprite = this.sprite_playerHead.getComponent(cc.Sprite);
- let base = ScenceManager.Instance().getGameComponent();
- if (url.length > 10) {
- sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + 1);
- } else if (url != "") {
- sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + url);
- } else {
- sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + 1);
- // sprite.spriteFrame = this.emptySprite;
- }
- },
- _setUserVip(vipID = this.getVIPLevel()) {
- if (!this.sprite_vip) { return; }
- let sprite = this.sprite_vip.getComponent(cc.Sprite);
- if (vipID >= 4 && vipID <= 7) {
- sprite.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
- this.sprite_vip.active = true;
- } else {
- this.sprite_vip.active = false;
- }
- },
- _setUserTitle() {
- },
- endGameAnim(score) {
- if (score > 0) {
- this.userWin(score);
- } else if (score < 0) {
- this.userLost(score)
- }
- },
- userWin(score) {
- this.spine_playerWin.active = true;
- this.sprite_playerWin.active = true;
- this.sprite_playerFail.active = false;
- this.spine_playerWin.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
- if (!this.sprite_playerWin.saveParent) { this.sprite_playerWin.saveParent = this.sprite_playerWin.parent; }
- let parentPos = this.sprite_playerWin.parent.position;
- let pos = parentPos.y > 300 ? cc.v2(0, 50) : parentPos.add(cc.v2(0, 100));
- if (parentPos.y < 300) {
- this.sprite_playerWin.parent = ScenceManager.Instance().getGameComponent().node.getChildByName("TP_Base").getChildByName("layer_animNode");
- }
- this.sprite_playerWin.children[0].getComponent(cc.Label).string = "+" + Global.formatString2Score(score);
- this.sprite_playerWin.scale = 2;
- this.sprite_playerWin.opacity = 150;
- this.sprite_playerWin.position = pos;
- this.sprite_playerWin.stopAllActions();
- this.sprite_playerWin.runAction(cc.sequence(
- cc.spawn(
- cc.scaleTo(0.25, 1.5),
- cc.fadeIn(0.25),
- ),
- cc.delayTime(4),
- cc.callFunc(() => {
- this.spine_playerWin.active = false;
- this.sprite_playerWin.active = false;
- this.sprite_playerWin.parent = this.sprite_playerWin.saveParent;
- })
- ))
- },
- userLost(score) {
- this.spine_playerWin.active = false;
- this.sprite_playerWin.active = false;
- this.sprite_playerFail.active = true;
- if (!this.sprite_playerFail.saveParent) { this.sprite_playerFail.saveParent = this.sprite_playerFail.parent; }
- let parentPos = this.sprite_playerFail.parent.position;
- let pos = parentPos.y > 300 ? cc.v2(0, 50) : parentPos.add(cc.v2(0, 100));
- if (parentPos.y < 300) {
- this.sprite_playerFail.parent = ScenceManager.Instance().getGameComponent().node.getChildByName("TP_Base").getChildByName("layer_animNode");
- }
- this.sprite_playerFail.children[0].getComponent(cc.Label).string = Global.formatString2Score(score);
- this.sprite_playerFail.scale = 2;
- this.sprite_playerFail.opacity = 150;
- this.sprite_playerFail.position = pos;
- this.sprite_playerFail.stopAllActions();
- this.sprite_playerFail.runAction(cc.sequence(
- cc.spawn(
- cc.scaleTo(0.25, 1.5),
- cc.fadeIn(0.25),
- ),
- cc.delayTime(4),
- cc.callFunc(() => {
- this.sprite_playerFail.active = false;
- this.sprite_playerFail.parent = this.sprite_playerFail.saveParent;
- })
- ))
- },
- });
|