UserPrefab_21201.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. m_UserScore: cc.Label,
  5. m_Ready: cc.Node,
  6. m_Zhuang: cc.Node,
  7. m_LeaveHead: cc.Node,
  8. m_Gang: cc.Label,
  9. m_CurEffect: cc.Node,
  10. m_Ting: cc.Node,
  11. m_Trustee: cc.Node,
  12. m_Score: cc.Label,
  13. m_Flower: cc.Node,
  14. m_FlowerNumber: cc.Label,
  15. m_Flowercard: cc.Node,
  16. m_FlowerLayout: cc.Node,
  17. m_Feng: cc.Label,
  18. m_Flowerbg3: cc.SpriteFrame,
  19. m_playingNode: cc.Node,
  20. m_Diamond: cc.Node,
  21. },
  22. ctor: function () {
  23. this.m_lScore = 0;
  24. },
  25. start: function () {
  26. },
  27. Init: function (View, Chair) {
  28. this.m_UserCtrl = this.node.getComponent('UserCtrl');
  29. this.m_Hook = View;
  30. this.m_ChairID = Chair;
  31. this.m_Gang.node.active = false;
  32. this.m_Ting.active = false;
  33. this.m_Trustee.active = false;
  34. this.m_Score.node.active = false;
  35. this.node.active = false;
  36. this.m_Flower.active = false;
  37. this.Reset();
  38. },
  39. Reset: function () {
  40. this.m_Ready.active = false;
  41. this.m_LeaveHead.active = false;
  42. this.m_Zhuang.active = false;
  43. this.m_Gang.node.active = false;
  44. this.m_Ting.active = false;
  45. this.m_Trustee.active = false;
  46. this.m_Score.node.active = false;
  47. this.node.active = false; //初始不显示头像
  48. this.m_Flower.active = false;
  49. this.m_Flowercard.active = false;
  50. for (let i = 0; i < this.m_FlowerLayout.childrenCount; i++) {
  51. this.m_FlowerLayout.children[i].active = false;
  52. }
  53. this.m_Feng.string = "";
  54. this.m_playingNode.active = false;
  55. this.m_Diamond.active = false;
  56. },
  57. SetReady: function (show) {
  58. if (this.m_ChairID == 3) {
  59. this.m_Ready.setPosition(-100, 0);
  60. }
  61. if (this.m_ChairID == 0) {
  62. this.m_Ready.setPosition(-100, 0);
  63. }
  64. this.m_Ready.active = show;
  65. },
  66. SetUserItem: function (pUserItem) {
  67. this.m_dwUserID = pUserItem.GetUserID();
  68. this.m_pUserItem = pUserItem;
  69. this.node.getComponent('UserCtrl').SetUserByID(this.m_dwUserID);
  70. this.node.getComponent('UserCtrl').SetShowFullName(false, 5);
  71. console.log("设置SetUserItem", GameDef.m_dwGameRuleArr)
  72. if (GameDef.m_dwGameRuleArr&&GameDef.m_dwGameRuleArr[3] > 0) {
  73. this.getUserMedal();
  74. }
  75. //this.SetUserScore(pUserItem.GetUserScore());
  76. },
  77. //初始化花牌
  78. ClearFlower: function (display) {
  79. this.m_Flower.active = display;
  80. this.m_FlowerNumber.string = '×0';
  81. for (let i = 0; i < this.m_FlowerLayout.childrenCount; i++) {
  82. this.m_FlowerLayout.children[i].active = false;
  83. }
  84. },
  85. UserLeave: function (pUserItem) {
  86. if (pUserItem.GetUserID() == this.m_dwUserID) {
  87. this.m_dwUserID = 0;
  88. this.node.getComponent('UserCtrl').SetUserByID(this.m_dwUserID);
  89. this.m_UserScore.string = '';
  90. this.Reset();
  91. }
  92. },
  93. //点击花
  94. OnClickFlower: function () {
  95. let flowercard = this.m_Flower.getChildByName('flowercard');
  96. if (!flowercard.active) {
  97. flowercard.active = true;
  98. setTimeout(() => {
  99. if (flowercard.active) {
  100. flowercard.active = false;
  101. }
  102. }, 2000);
  103. }
  104. },
  105. OnBtClickedUser: function () {
  106. if (this.m_dwUserID == null || this.m_dwUserID == 0) return;
  107. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  108. if (this.m_dwUserID == pGlobalUserData.dwUserID) {
  109. return
  110. }
  111. if (this.m_Hook.m_FaceExCtrl) this.m_Hook.m_FaceExCtrl.SetShowInfo(
  112. this.m_dwUserID,
  113. this.m_ChairID,
  114. this.m_pUserItem.GetUserIP());
  115. //, this.m_Hook.strAddress[this.m_ChairID]);
  116. return;
  117. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  118. // if(this.m_dwUserID == pGlobalUserData.dwUserID){
  119. // return
  120. // }
  121. if (this.m_Hook.m_FaceExCtrl) this.m_Hook.m_FaceExCtrl.SetShowInfo(
  122. this.m_dwUserID,
  123. 'IP:' + this.m_pUserItem.GetUserIP(),
  124. this.m_ChairID,
  125. this.m_Hook.strAddress[this.m_ChairID]);
  126. },
  127. UpdateScore: function (pUserItem) {
  128. // if (pUserItem.GetUserID() == this.m_dwUserID) {
  129. // this.SetUserScore(pUserItem.GetUserScore());
  130. // }
  131. if (GameDef.m_dwGameRuleArr&&GameDef.m_dwGameRuleArr[3] > 0) {
  132. this.getUserMedal();
  133. }else{
  134. this.m_Diamond.active = false;
  135. }
  136. },
  137. SetUserScore: function (Score) {
  138. console.log("设置SetUserScore-2", Score)
  139. // 将传入的分数赋值给当前对象的m_lScore属性
  140. this.m_lScore = Score;
  141. // 将分数转换为字符串格式,并设置给m_UserScore节点的string属性,用于显示用户分数
  142. this.m_UserScore.string = Score;
  143. },
  144. SetUserFlower: function (viewID, flower, wFlowercard, displayF, displayC) {
  145. this.m_Flowercard.active = displayC;
  146. this.m_FlowerNumber.string = '×' + flower;
  147. let flowerLayout = this.m_FlowerLayout;
  148. for (let i = 0; i < wFlowercard.length; i++) {
  149. if (wFlowercard[i] > 0) {
  150. flowerLayout.getChildByName('' + wFlowercard[i]).active = true;
  151. }
  152. }
  153. setTimeout(() => {
  154. this.m_Flowercard.active = false;
  155. }, 3000);
  156. },
  157. SetFeng: function (cbQuan, cbFeng, display) {
  158. let directions = ["東", "南", "西", "北"];
  159. let cbQuanStr = directions[cbQuan];
  160. let cbFengStr = directions[cbFeng];
  161. this.m_Feng.string = cbQuanStr + " 風 " + cbFengStr;
  162. if (!display) {
  163. this.m_Feng.string = "";
  164. console.log("显示风位", cbQuan, cbFeng, display, this.m_Feng.string);
  165. }
  166. },
  167. SetShowFenganFlower: function () {
  168. // console.log("关闭显示花牌,风位");
  169. this.m_Flower.active = false;
  170. this.m_Feng.string = "";
  171. },
  172. SetCurrentAction: function (cur) {
  173. this.m_CurEffect.active = cur;
  174. },
  175. OnUserOffLine: function (bShow) {
  176. this.SetLeave(bShow);
  177. },
  178. //基准位置
  179. SetBenchmarkPos: function (nXPos, nYPos) {
  180. this.node.setPosition(nXPos, nYPos);
  181. },
  182. SetBanker: function (bBanker) {
  183. this.m_Zhuang.active = bBanker;
  184. },
  185. //离开状态
  186. SetLeave: function (bLeave) {
  187. this.m_LeaveHead.active = bLeave;
  188. },
  189. SetGang: function (cbDouble) {
  190. if (cbDouble == 0) {
  191. this.m_Gang.node.active = false;
  192. }
  193. else {
  194. this.m_Gang.node.active = true;
  195. if (cbDouble == 255) {
  196. //this.m_Gang.string = '不下嘴';
  197. }
  198. else {
  199. this.m_Gang.string = '飘' + cbDouble;
  200. }
  201. }
  202. },
  203. SetTing: function (bShow) {
  204. this.m_Ting.active = bShow;
  205. },
  206. SetTrustee: function (bShow) {
  207. this.m_Trustee.active = bShow;
  208. },
  209. updateEndDimond: function (viewID, lScore) {
  210. let tmpeS = parseInt(this.m_lScore) +parseInt(lScore)
  211. console.log("最新的钻石",this.m_lScore,tmpeS,lScore)
  212. this.scheduleOnce(function() {
  213. console.log("最新的钻石2",this.m_lScore,tmpeS,lScore)
  214. this.SetUserScore( tmpeS);
  215. }, 2);
  216. },
  217. SetScore: function (viewID, lScore) {
  218. if (GameDef.m_dwGameRuleArr&&GameDef.m_dwGameRuleArr[3] > 0) {
  219. this.getUserMedal();
  220. } else {
  221. this.SetUserScore(lScore);
  222. }
  223. return;
  224. // this.m_Score.node.stopAllActions();
  225. this.m_Score.node.active = true;
  226. var Score = lScore;
  227. if (lScore > 0) {
  228. this.m_Score.string = lScore;//'+'+Score2Str(lScore);
  229. //this.m_Score.font = this.m_Font[0];
  230. this.m_Score.node.color = cc.color(0, 255, 0);
  231. }
  232. else {
  233. //this.m_Score.font = this.m_Font[1];
  234. this.m_Score.node.color = cc.color(255, 0, 0);
  235. this.m_Score.string = lScore; //Score2Str(lScore);
  236. }
  237. if (viewID == 1 || viewID == 3 || viewID == 2) {
  238. this.m_Score.node.setPosition(cc.v2(0, 50));
  239. }
  240. else if (viewID == 0) {
  241. this.m_Score.node.setPosition(cc.v2(70, 0));
  242. }
  243. // var sequence = cc.sequence
  244. // (
  245. // cc.moveBy(0.5, cc.v2(0, 50)),
  246. // cc.delayTime(0.5),
  247. // cc.callFunc(function () {
  248. // this.m_Score.node.active = false;
  249. // }, this)
  250. // );
  251. // this.m_Score.node.runAction(sequence);
  252. },
  253. SetFlower: function (viewID, wFlower, wFlowercard, displayF, displayC) {
  254. this.m_Flower.active = displayF;
  255. this.SetUserFlower(viewID, wFlower, wFlowercard, displayF, displayC);
  256. },
  257. SetPlaying(status) {
  258. this.m_playingNode.active = status;
  259. },
  260. getUserMedal: function () {
  261. // // 将传入的分数赋值给当前对象的m_lScore属性
  262. // this.m_lScore = Score;
  263. // // 将分数转换为字符串格式,并设置给m_UserScore节点的string属性,用于显示用户分数
  264. // this.m_scoreLab.string = formatToChineseAbbreviation(Score);
  265. if(this.m_dwUserID==0) return;
  266. var webUrl = window.PHP_HOME + '/UserFunc.php?&GetMark=5&dwUserID=' + this.m_dwUserID;
  267. WebCenter.GetData(webUrl, 3, function (data) {
  268. var resData = JSON.parse(data);
  269. this.SetUserScore(resData && resData.UserMedal)
  270. this.m_Diamond.active = true;
  271. }.bind(this));
  272. },
  273. });