TPPlayerBase.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. let Global = require("Global");
  2. let GamePlayer = require("GamePlayer");
  3. let ScenceManager = require("HNScenceManager");
  4. const UIHelper = require("UIHelper");
  5. cc.Class({
  6. extends: GamePlayer,
  7. properties: {
  8. },
  9. onLoad() {
  10. },
  11. inits(node) {
  12. this.node = node;
  13. this.initConfig();
  14. this.initHeadNode();
  15. },
  16. initConfig() {
  17. this.initWhiteList = ["sprite_playerHead", "sprite_playerNameBg", "label_playerName", "sprite_myCoinBg", "sprite_myCoin", "label_myCoin"];
  18. this.sprite_vip = UIHelper.pathGetNode(this.node, "sprite_playerHead/sprite_vip");
  19. this.sprite_title = UIHelper.pathGetNode(this.node, "sprite_playerHead/sprite_title");
  20. this.sprite_playerHead = UIHelper.pathGetNode(this.node, "sprite_playerHead");
  21. this.spine_playerWin = UIHelper.pathGetNode(this.node, "spine_playerWin");
  22. this.sprite_playerFail = UIHelper.pathGetNode(this.node, "sprite_playerFail");
  23. this.sprite_playerWin = UIHelper.pathGetNode(this.node, "sprite_playerWin");
  24. this.label_playerName = UIHelper.pathGetNode(this.node, "label_playerName");
  25. this.emptySprite = this.sprite_playerHead.getComponent(cc.Sprite).spriteFrame;
  26. },
  27. _initNode() {
  28. for (let i = 0; i < this.node.children.length; i += 1) {
  29. let node = this.node.children[i];
  30. node.active = this.initWhiteList.indexOf(node.name) >= 0;
  31. }
  32. },
  33. initHeadNode() {
  34. this._initNode();
  35. this._setUserNameLabel();
  36. this._setUserHead();
  37. this._setUserVip();
  38. this._setUserTitle();
  39. },
  40. refreshHeadNode() {
  41. this._initNode();
  42. this._setUserNameLabel("");
  43. this._setUserHead("");
  44. this._setUserVip(-1);
  45. this._setUserTitle();
  46. this.node.stopAllActions();
  47. },
  48. initMyself() {
  49. this.sprite_myCoinBg = UIHelper.pathGetNode(this.node, "sprite_myCoinBg");
  50. this.sprite_myCoin = UIHelper.pathGetNode(this.node, "sprite_myCoin");
  51. this.label_myCoin = UIHelper.pathGetNode(this.node, "label_myCoin");
  52. if (this.sprite_myCoinBg && this.sprite_myCoin && this.label_myCoin) {
  53. this.sprite_myCoinBg.active = true;
  54. this.sprite_myCoin.active = true;
  55. this.label_myCoin.active = true;
  56. this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(this.getUserScore());
  57. this.initConfig();
  58. this.initHeadNode();
  59. }
  60. },
  61. refreshMyself(num) {
  62. if (this.label_myCoin) {
  63. let score = (this.getUserScore() - num);
  64. this.setUserScore(score);
  65. this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(score);
  66. }
  67. },
  68. setScore(score) {
  69. this.label_myCoin.getComponent(cc.Label).string = Global.formatString2Score(score);
  70. this.setUserScore(score);
  71. },
  72. _setUserNameLabel(str = this.getNickName()) {
  73. if (!this.label_playerName) {
  74. return;
  75. }
  76. let label = this.label_playerName.getComponent(cc.Label);
  77. label.string = str;
  78. },
  79. _setUserHead(url = this.getHeadHttp()) {
  80. if (!this.sprite_playerHead) {
  81. return;
  82. }
  83. this.sprite_playerHead.width = 105;
  84. this.sprite_playerHead.height = 105;
  85. let sprite = this.sprite_playerHead.getComponent(cc.Sprite);
  86. let base = ScenceManager.Instance().getGameComponent();
  87. if (url.length > 10) {
  88. sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + 1);
  89. } else if (url != "") {
  90. sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + url);
  91. } else {
  92. sprite.spriteFrame = base.avatarsSpriteAtlas.getSpriteFrame("avatar_" + 1);
  93. // sprite.spriteFrame = this.emptySprite;
  94. }
  95. },
  96. _setUserVip(vipID = this.getVIPLevel()) {
  97. if (!this.sprite_vip) { return; }
  98. let sprite = this.sprite_vip.getComponent(cc.Sprite);
  99. if (vipID >= 4 && vipID <= 7) {
  100. sprite.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
  101. this.sprite_vip.active = true;
  102. } else {
  103. this.sprite_vip.active = false;
  104. }
  105. },
  106. _setUserTitle() {
  107. },
  108. endGameAnim(score) {
  109. if (score > 0) {
  110. this.userWin(score);
  111. } else if (score < 0) {
  112. this.userLost(score)
  113. }
  114. },
  115. userWin(score) {
  116. this.spine_playerWin.active = true;
  117. this.sprite_playerWin.active = true;
  118. this.sprite_playerFail.active = false;
  119. this.spine_playerWin.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
  120. if (!this.sprite_playerWin.saveParent) { this.sprite_playerWin.saveParent = this.sprite_playerWin.parent; }
  121. let parentPos = this.sprite_playerWin.parent.position;
  122. let pos = parentPos.y > 300 ? cc.v2(0, 50) : parentPos.add(cc.v2(0, 100));
  123. if (parentPos.y < 300) {
  124. this.sprite_playerWin.parent = ScenceManager.Instance().getGameComponent().node.getChildByName("TP_Base").getChildByName("layer_animNode");
  125. }
  126. this.sprite_playerWin.children[0].getComponent(cc.Label).string = "+" + Global.formatString2Score(score);
  127. this.sprite_playerWin.scale = 2;
  128. this.sprite_playerWin.opacity = 150;
  129. this.sprite_playerWin.position = pos;
  130. this.sprite_playerWin.stopAllActions();
  131. this.sprite_playerWin.runAction(cc.sequence(
  132. cc.spawn(
  133. cc.scaleTo(0.25, 1.5),
  134. cc.fadeIn(0.25),
  135. ),
  136. cc.delayTime(4),
  137. cc.callFunc(() => {
  138. this.spine_playerWin.active = false;
  139. this.sprite_playerWin.active = false;
  140. this.sprite_playerWin.parent = this.sprite_playerWin.saveParent;
  141. })
  142. ))
  143. },
  144. userLost(score) {
  145. this.spine_playerWin.active = false;
  146. this.sprite_playerWin.active = false;
  147. this.sprite_playerFail.active = true;
  148. if (!this.sprite_playerFail.saveParent) { this.sprite_playerFail.saveParent = this.sprite_playerFail.parent; }
  149. let parentPos = this.sprite_playerFail.parent.position;
  150. let pos = parentPos.y > 300 ? cc.v2(0, 50) : parentPos.add(cc.v2(0, 100));
  151. if (parentPos.y < 300) {
  152. this.sprite_playerFail.parent = ScenceManager.Instance().getGameComponent().node.getChildByName("TP_Base").getChildByName("layer_animNode");
  153. }
  154. this.sprite_playerFail.children[0].getComponent(cc.Label).string = Global.formatString2Score(score);
  155. this.sprite_playerFail.scale = 2;
  156. this.sprite_playerFail.opacity = 150;
  157. this.sprite_playerFail.position = pos;
  158. this.sprite_playerFail.stopAllActions();
  159. this.sprite_playerFail.runAction(cc.sequence(
  160. cc.spawn(
  161. cc.scaleTo(0.25, 1.5),
  162. cc.fadeIn(0.25),
  163. ),
  164. cc.delayTime(4),
  165. cc.callFunc(() => {
  166. this.sprite_playerFail.active = false;
  167. this.sprite_playerFail.parent = this.sprite_playerFail.saveParent;
  168. })
  169. ))
  170. },
  171. });