UserCtrl.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_HeadNode:cc.Node,
  5. m_HeadErr:cc.Node,
  6. m_SpGender:[cc.Sprite],
  7. m_LabNick:cc.Label,
  8. m_LabID:cc.Label,
  9. m_BtKick:cc.Button,
  10. m_SpGenderstr:cc.Label,
  11. m_adressStr: cc.Label,
  12. m_winRateStr: cc.Label,
  13. m_shootRateStr: cc.Label,
  14. m_pairingRateStr: cc.Label,
  15. },
  16. ctor: function(){
  17. this.m_bForceUpdare = true;
  18. },
  19. onLoad:function() {
  20. },
  21. InitPre:function(){
  22. this.SetUserByID(0);
  23. },
  24. SetPreInfo:function(ParaArr){
  25. this.SetUserByID(ParaArr);
  26. },
  27. SetUserByGameID :function(GameID, bForceUpdare) {
  28. this.m_bForceUpdare = bForceUpdare;
  29. this.InitUser();
  30. if(GameID == null || GameID == 0) return;
  31. this.m_CheckGameID = GameID;
  32. this.m_CheckUserID = null;
  33. this.m_CheckCnt = 0;
  34. },
  35. SetUserByID :function(UserID, bForceUpdare) {
  36. this.m_bForceUpdare = bForceUpdare;
  37. this.InitUser();
  38. if(UserID == null || UserID == 0) return;
  39. this.m_CheckUserID = UserID;
  40. this.m_CheckGameID = null;
  41. this.m_CheckCnt = 0;
  42. },
  43. GetUserID:function(){ return this.m_UserID;},
  44. InitUser:function(){
  45. this.m_UserID = 0;
  46. this.m_bShowFullID = true;
  47. this.m_bShowFullName = true;
  48. this.m_LenName = 6;
  49. // if(this.m_LabNick) this.m_LabNick.string = '使用者暱稱';
  50. // if(this.m_LabID) this.m_LabID.string = '使用者ID';
  51. if(this.m_HeadCtrl) {
  52. this.m_HeadCtrl.SetHook(this);
  53. this.m_HeadCtrl.SetUserHead();
  54. }
  55. if(this.m_HeadErr) this.m_HeadErr.active = false;
  56. if(this.m_BtKick) this.m_BtKick.node.active = false;
  57. this.SetShowFullIDWithClubRule();
  58. },
  59. OnClicked_Kick: function() {
  60. cc.gSoundRes.PlaySound('Button');
  61. if(this.m_Hook && this.m_Hook.OnUserCtrlCallback_Kick) this.m_Hook.OnUserCtrlCallback_Kick(this);
  62. },
  63. OnHeadErr:function(){
  64. if(this.m_HeadErr) this.m_HeadErr.active = true;
  65. },
  66. SetShowFullID:function(bShow){
  67. this.m_bFulShowlID=bShow;
  68. if(this.m_LabID && !this.m_bShowFullID) {
  69. var temp = (this.m_LabID.string+"").split('');
  70. temp[2] = '*'
  71. temp[3] = '*'
  72. this.m_LabID.string = temp.join('');
  73. }
  74. },
  75. SetShowFullIDWithClubRule:function(){
  76. if(g_ServerListDataLast == null || ShowLobbyClub == 0) return;
  77. var ClubRule = g_GlobalClubInfo.onGetClubRules(ShowLobbyClub);
  78. if((ClubRule & 0x01)>0){
  79. this.SetShowFullID(false);
  80. }
  81. },
  82. SetShowFullName:function(bShow, Len){
  83. this.m_bShowFullName=bShow;
  84. if(Len) this.m_LenName = Len;
  85. if(this.m_LabNick && !this.m_bShowFullName) {
  86. var temp = this.m_LabNick.string;
  87. this.m_LabNick.string = cutstr(temp, this.m_LenName);
  88. }
  89. },
  90. SetUserInfo :function(UserID, Info) {
  91. console.log("SetUserInfo",UserID, Info);
  92. //未加载成功
  93. if(Info == null || Info == 'Loading') return;
  94. //设置信息
  95. this.m_UserID = UserID;
  96. this.m_CheckUserID = null;
  97. this.m_CheckGameID = null;
  98. // for(var i in this.m_SpGender) {
  99. // if(!this.m_SpGender[i]) continue;
  100. // this.m_SpGender[i].node.active = (i == Info.Gender);
  101. // }
  102. if(this.m_LabNick && Info.NickName != null){
  103. this.m_LabNick.string = this.m_bShowFullName?Info.NickName:cutstr(Info.NickName, this.m_LenName);
  104. }
  105. // if(this.m_LabID && Info.GameID != null){
  106. // this.m_LabID.string = Info.GameID;
  107. // if(!this.m_bShowFullID) {
  108. // var temp = (this.m_LabID.string+"").split(''); //ID显示
  109. // temp[2] = '*';
  110. // temp[3] = '*';
  111. // this.m_LabID.string = temp.join('');
  112. // }
  113. // }
  114. if(this.m_SpGenderstr && Info.Gender != null){
  115. this.m_SpGenderstr.string = Info.Gender ==0?"女":"男";
  116. }
  117. if(this.m_LabID && UserID != null){
  118. this.m_LabID.string = UserID;
  119. if(!this.m_bShowFullID) {
  120. var temp = (this.m_LabID.string+"").split(''); //ID显示
  121. temp[2] = '*';
  122. temp[3] = '*';
  123. this.m_LabID.string = temp.join('');
  124. }
  125. }
  126. if(this.m_HeadNode && this.m_HeadCtrl == null) this.m_HeadCtrl = this.m_HeadNode.getComponent('HeadPrefab');
  127. if(this.m_HeadCtrl) this.m_HeadCtrl.SetUserHead(UserID, this.m_bForceUpdare);
  128. if(this.m_BtKick) this.m_BtKick.node.active = true;
  129. if (this.m_adressStr) {
  130. let isShow = !!Info.Adress;
  131. this.m_adressStr.node.parent.active = isShow;
  132. if (isShow) {
  133. this.m_adressStr.string = `${Info.Adress}`;
  134. }
  135. }
  136. if (this.m_winRateStr) {
  137. let isShow = !!Info.WinRate;
  138. this.m_winRateStr.node.parent.active = isShow;
  139. if (isShow) {
  140. this.m_winRateStr.string = `${Info.WinRate}%`;
  141. }
  142. }
  143. if (this.m_shootRateStr) {
  144. let isShow = !!Info.ShootRate;
  145. this.m_shootRateStr.node.parent.active = isShow;
  146. if (isShow) {
  147. this.m_shootRateStr.string = `${Info.ShootRate}%`;
  148. }
  149. }
  150. if (this.m_pairingRateStr) {
  151. let isShow = !!Info.PairingRate;
  152. this.m_pairingRateStr.node.parent.active = isShow;
  153. if (isShow) {
  154. this.m_pairingRateStr.string = `${Info.PairingRate}%`;
  155. }
  156. }
  157. },
  158. update:function() {
  159. if(this.m_CheckUserID == null && this.m_CheckGameID == null) return;
  160. if(this.m_CheckUserID) this.GetUserInfo(this.m_CheckUserID);
  161. if(this.m_CheckGameID) this.GetUserInfo2(this.m_CheckGameID);
  162. },
  163. GetUserInfo:function(UserID){
  164. //等待其他控件加载结果
  165. if ( g_GlobalUserInfo.m_UserInfoMap[UserID] == 'Loading') return;
  166. //首次加载
  167. // if(this.m_bForceUpdare || g_GlobalUserInfo.m_UserInfoMap[UserID] == null){
  168. // this.LoadUserInfo(UserID);
  169. // }else {
  170. // this.SetUserInfo(UserID, g_GlobalUserInfo.m_UserInfoMap[UserID]);
  171. // }
  172. this.LoadUserInfo(UserID);
  173. },
  174. LoadUserInfo:function(UserID, bReload){
  175. g_GlobalUserInfo.m_UserInfoMap[UserID] = 'Loading';
  176. var webUrl = window.PHP_HOME+'/UserFunc.php?GetMark=12&dwUserID='+UserID;
  177. WebCenter.GetData(webUrl, null, function (data) {
  178. var UserInfo = JSON.parse(data);
  179. if (UserInfo.UserID == null) {
  180. if(bReload == null) this.LoadUserInfo(UserID, true);
  181. else this.m_CheckUserID = null;
  182. }else{
  183. g_GlobalUserInfo.SetUserInfo(UserID,UserInfo.NickName,UserInfo.GameID,UserInfo.HeadUrl,UserInfo.Gender);
  184. if(this.m_CheckUserID == UserID) this.SetUserInfo(UserID, g_GlobalUserInfo.m_UserInfoMap[UserID]);
  185. }
  186. }.bind(this));
  187. },
  188. GetUserInfo2:function(GameID, bReload){
  189. //等待其他控件加载结果
  190. if( g_GlobalUserInfo.m_UserGameIDMap[GameID] == 'Loading') return;
  191. if(g_GlobalUserInfo.m_UserGameIDMap[GameID] == null){
  192. this.LoadUserInfo2(GameID);
  193. }else{
  194. var UserID = g_GlobalUserInfo.m_UserGameIDMap[GameID];
  195. this.SetUserInfo(UserID, g_GlobalUserInfo.m_UserInfoMap[UserID]);
  196. }
  197. },
  198. LoadUserInfo2:function(GameID, bReload){
  199. g_GlobalUserInfo.m_UserGameIDMap[GameID] = 'Loading';
  200. var webUrl = window.PHP_HOME+'/UserFunc.php?GetMark=13&dwGameID='+GameID;
  201. WebCenter.GetData(webUrl, null, function (data) {
  202. var UserInfo = JSON.parse(data);
  203. if(UserInfo.UserID == null){
  204. if(bReload == null) this.LoadUserInfo2(GameID, true);
  205. else this.m_CheckGameID = null;
  206. }else{
  207. g_GlobalUserInfo.SetUserInfo(UserInfo.UserID,UserInfo.NickName,UserInfo.GameID,UserInfo.HeadUrl);
  208. if(this.m_CheckGameID == GameID)this.SetUserInfo(UserInfo.UserID, g_GlobalUserInfo.m_UserInfoMap[UserInfo.UserID]);
  209. }
  210. }.bind(this));
  211. },
  212. OnBtChangeSex:function(){
  213. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  214. var ChangeSex = pGlobalUserData.cbGender==1?0:1 ;
  215. // if(pGlobalUserData.cbGender) ChangeSex=0;
  216. var webUrl = window.PHP_HOME+'/UserFunc.php?&GetMark=6&dwUserID='+pGlobalUserData.dwUserID;
  217. webUrl += "&Sex="+ChangeSex;
  218. WebCenter.GetData(webUrl, null, function (data) {
  219. pGlobalUserData.cbGender = ChangeSex;
  220. console.log("OnBtChangeSex",pGlobalUserData);
  221. for(var i in this.m_SpGender) {
  222. if(!this.m_SpGender[i]) continue;
  223. this.m_SpGender[i].node.active = (i == ChangeSex);
  224. }
  225. }.bind(this));
  226. },
  227. });