DissolveRoom.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_BtSure:cc.Node,
  5. m_BtCancel:cc.Node,
  6. m_BtClose:cc.Node,
  7. m_ClockNode:cc.Node,
  8. m_LabTips:cc.Label,
  9. m_LabTime:cc.Label,
  10. m_FirstUserNode:cc.Node,
  11. m_UserNode:cc.Node,
  12. m_atlas:cc.SpriteAtlas,
  13. },
  14. // LIFE-CYCLE CALLBACKS:
  15. ctor :function () {
  16. this.m_UserArr = new Array();
  17. this.m_EndTime = null;
  18. },
  19. SetDissolveInfo:function(UserID, ChooseArr, CntDown,LockArr,allCntDown){
  20. this.m_BtClose.active = false;
  21. this.m_DisUserID = UserID;
  22. if(this.DisUserCtrl == null) this.DisUserCtrl = this.$('UserCtrl@DisUserPre');
  23. //默认数据
  24. this.m_LockArr = LockArr;
  25. this.m_UserArr = ChooseArr;
  26. for(var i = 0;i<GameDef.GAME_PLAYER;i++){
  27. if(this.m_UserArr[i] == null) this.m_UserArr[i] = 0;
  28. }
  29. //玩家状态信息
  30. this.UpdateTableUser();
  31. //提示信息
  32. var kernel = gClientKernel.get();
  33. var MeSelfInfo = kernel.GetMeUserItem();
  34. if(this.m_DisUserID == MeSelfInfo.GetUserID() || ChooseArr[MeSelfInfo.GetChairID()] != 0 || !LockArr[MeSelfInfo.GetChairID()]){
  35. this.m_BtSure.active = false;
  36. this.m_BtCancel.active = false;
  37. this.m_LabTips.string = '等待其他玩家選擇!'
  38. }else if(ChooseArr[MeSelfInfo.GetChairID()] == 0){
  39. this.m_BtSure.active = true;
  40. this.m_BtCancel.active = true;
  41. this.m_LabTips.string = '是否同意解散?'
  42. }
  43. //倒计时
  44. this.m_ClockNode.active = true;
  45. this.m_LabTime.string = CntDown;
  46. this.m_EndTime = new Date().getTime() + CntDown*1000;
  47. if(allCntDown){
  48. this.$('LabDis@Label',this.m_FirstUserNode).string = `玩家【 】申請解散房間,請等待其他玩家選擇(超過${allCntDown}秒未做選擇則默認該玩家同意)`;
  49. }
  50. },
  51. UpdateTableUser:function(){
  52. if(this.m_ListCtrl == null) this.m_ListCtrl = this.$('@CustomListCtrl');
  53. this.m_ListCtrl.InitList(0, 'DisUserPre', this);
  54. //玩家界面
  55. for(var i=0;i<GameDef.GAME_PLAYER;i++){
  56. if(!this.m_LockArr[i]) continue; //跳过未锁定玩家
  57. var UserItem = this.m_Hook.GetClientUserItem(i);
  58. if(UserItem == null) continue
  59. if(this.m_DisUserID == UserItem.GetUserID()) {
  60. this.DisUserCtrl.SetPreInfo([this.m_DisUserID]);
  61. }else{
  62. this.m_ListCtrl.InsertListInfo(0, [UserItem.GetUserID(),UserItem.GetChairID(), this.m_UserArr]);
  63. }
  64. }
  65. },
  66. SetUserChoose:function(wChairID, byRes){
  67. var bNoIn = true;
  68. this.m_UserArr[wChairID] = byRes;
  69. this.UpdateTableUser();
  70. return
  71. for(var i =1;i< this.m_UserArr.length; i++){
  72. if(this.m_UserArr[i].GetChairID() == wChairID) {
  73. bNoIn = false;
  74. this.m_UserArr[i].SetUserState( byRes );
  75. }
  76. }
  77. if(bNoIn){
  78. var UserItem = this.m_Hook.GetClientUserItem(wChairID);
  79. if(UserItem == null) return
  80. for(var i =1;i< this.m_UserArr.length; i++){
  81. if(this.m_UserArr[i].GetChairID() == 0xff) {
  82. this.m_UserArr[i].node.active = true;
  83. this.m_UserArr[i].SetUser(UserItem.GetUserID(),UserItem.GetChairID());
  84. this.m_UserArr[i].SetUserState( byRes );
  85. break;
  86. }
  87. }
  88. }
  89. },
  90. SetDisRes:function(byRes){
  91. this.m_BtSure.active = false;
  92. this.m_BtCancel.active = false;
  93. this.m_ClockNode.active = false;
  94. this.m_BtClose.active = true;
  95. this.m_LabTips.string = byRes?"投票通過,遊戲解散!":"投票未通過,遊戲繼續!";
  96. this.m_EndTime = null;
  97. this.m_LabTime.string = '';
  98. if(byRes==0) {
  99. this.ShowAlert("投票未通過,遊戲繼續!");
  100. this.scheduleOnce(this.OnHide,2);
  101. }
  102. },
  103. OnBtClickChoose:function(Tag, byRes){
  104. this.m_BtSure.active = false;
  105. this.m_BtCancel.active = false;
  106. var UserChoose = new CMD_GF_UserChoose();
  107. UserChoose.byChoose = byRes == 1 ? 1 : 0;
  108. this.m_Hook.sendClass(MDM_GF_CARDROOM, SUB_GF_USER_CHOOSE, UserChoose);
  109. },
  110. update (dt) {
  111. if(this.m_EndTime == null) return
  112. var TimeLeft = this.m_EndTime - new Date().getTime();
  113. this.m_LabTime.string = TimeLeft < 0 ? '' : parseInt(TimeLeft / 1000);//+'秒后结束投票!无人拒绝自动解散';
  114. },
  115. OnHide:function(){
  116. this.unschedule(this.OnHide);
  117. this.node.active = false;
  118. this['m_JsAlert'] && this['m_JsAlert'].HideView();
  119. },
  120. OnHideView:function(){
  121. this.unschedule(this.OnHide);
  122. var JsAlert = this['m_JsAlert'];
  123. if(JsAlert != null && JsAlert.node != null) JsAlert.HideView();
  124. if(this.m_Hook.m_RoomEnd) this.m_Hook.RealShowEndView();
  125. else this.node.active = false;
  126. },
  127. });