waitFirend.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { _decorator, Component, Node, Label } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant, room_type } from '../constant';
  4. import { GameMng } from '../GameMng';
  5. import { UIButton } from '../gcommon/UIButton';
  6. import UILoading from '../gcommon/UILoading';
  7. import { UIManager } from '../gcommon/UIManager';
  8. import { msgManager } from '../socket/msgManager';
  9. import { Tools } from '../Tools';
  10. import { roomData } from '../UserData/roomData';
  11. import ChessMng, { ChessType } from './DiffSel/ChessMng';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('waitFirend')
  14. export class waitFirend extends Component {
  15. @property(Node)
  16. lab_dumiao:Node=null;
  17. @property(Node)
  18. lab_jushu:Node=null;
  19. @property(Node)
  20. lab_bushu: Node = null;
  21. @property(Node)
  22. lab_meibujiashi: Node = null;
  23. @property(Node)
  24. btn_start: Node = null;
  25. @property(Node)
  26. btn_start_2: Node = null;
  27. @property(Node)
  28. btn_yaoqing: Node = null;
  29. @property(Node)
  30. btn_yaoqing_2: Node = null;
  31. @property(Node)
  32. onReady: Node = null;
  33. @property(Node)
  34. onReady_2: Node = null;
  35. @property(Node)
  36. lab_roomid: Node = null;
  37. @property(Node)
  38. lab_new_roomid: Node = null;
  39. @property(Node) //新的一盘
  40. node_newRound: Node = null;
  41. @property(Node) //最初的一盘
  42. node_initRound: Node = null;
  43. start() {
  44. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  45. }else{
  46. if(GameMng._userData.room!=null){
  47. if(GameMng._userData.room.game_number>1){
  48. this.node_newRound.active = true;
  49. this.node_initRound.active = false;
  50. }else{
  51. this.node_newRound.active = false;
  52. this.node_initRound.active = true;
  53. } //新的一局了
  54. }
  55. }
  56. this.lab_meibujiashi.active = false;
  57. this.lab_dumiao.active = false;
  58. this.lab_roomid.getComponent(Label).string ="象棋"
  59. let self = this;
  60. if(GameMng._userData.room!=null){
  61. this.lab_jushu.getComponent(Label).string ="局时:"+Tools.time(GameMng._userData.room.totaltime)
  62. this.lab_bushu.getComponent(Label).string ="步时:"+Tools.time(GameMng._userData.room.everysteptime)
  63. if(GameMng._userData.room.roomtype===room_type._jing_dian_hao_you){
  64. if(GameMng._userData.room.countdown>0){
  65. this.lab_dumiao.active = true;
  66. this.lab_dumiao.getComponent(Label).string ="读秒:"+Tools.time(GameMng._userData.room.countdown)
  67. }
  68. }
  69. if(GameMng._userData.room.roomtype===room_type._mei_miao_die_jia_hao_you){
  70. if(GameMng._userData.room.everystepaddtime>0){
  71. this.lab_meibujiashi.active = true;
  72. this.lab_meibujiashi.getComponent(Label).string ="每步加时:"+Tools.time(GameMng._userData.room.everystepaddtime)
  73. }
  74. }
  75. if(GameMng._userData.room.wait_rival_startGame_status==3||GameMng._userData.room.wait_rival_startGame_status==1){
  76. this.btn_start.active = false;
  77. this.onReady.active = true;
  78. }
  79. UIButton.BindClick(this.btn_start,function(){
  80. self.sendReady(self.btn_start)
  81. },this)
  82. UIButton.BindClick(this.btn_start_2,function(){
  83. self.sendReady(self.btn_start_2)
  84. },this)
  85. UIButton.BindClick(this.btn_yaoqing,function(){
  86. UIManager.AddPrefab(GameMng.Instance.invite_firend_view)
  87. },this)
  88. UIButton.BindClick(this.btn_yaoqing_2,function(){
  89. UIManager.AddPrefab(GameMng.Instance.invite_firend_view)
  90. },this)
  91. this.lab_roomid.getComponent(Label).string = "象棋"+"【"+GameMng._userData.room.roomid+"】"
  92. this.lab_new_roomid.getComponent(Label).string = "象棋"+"【"+GameMng._userData.room.roomid+"】"
  93. }
  94. ClientEvent.on(Constant.UI_EVENT.UI_MSG_ready,this.sendReady,this)
  95. }
  96. sendReady(node:Node=null){
  97. if(node){
  98. node.active = false;
  99. }
  100. UILoading.deley_show(2);
  101. msgManager.ready()
  102. }
  103. onDestroy(){
  104. ClientEvent.off(Constant.UI_EVENT.UI_MSG_ready,this.sendReady,this)
  105. }
  106. recvReady(room:roomData){
  107. console.log("recvReady",room.wait_rival_startGame_status)
  108. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  109. }else{
  110. if(GameMng._userData.room.game_number>1){ //新的一局了
  111. if(room.wait_rival_startGame_status==3||room.wait_rival_startGame_status==1){
  112. this.btn_start_2.active = false;
  113. this.onReady_2.active = true;
  114. }else{
  115. this.btn_start_2.active = true;
  116. this.onReady_2.active = false;
  117. }
  118. }else{
  119. if(room.wait_rival_startGame_status==3||room.wait_rival_startGame_status==1){
  120. this.btn_start.active = false;
  121. this.onReady.active = true;
  122. }else{
  123. this.btn_start.active = true;
  124. this.onReady.active = false;
  125. }
  126. }
  127. }
  128. }
  129. //新的一盘
  130. recvAgainRound(room:roomData){
  131. if(room!=null){
  132. this.node_newRound.active = true;
  133. this.node_initRound.active = false;
  134. if(room.wait_rival_startGame_status==3||room.wait_rival_startGame_status==1){
  135. this.btn_start_2.active = false;
  136. this.onReady_2.active = true;
  137. }
  138. }
  139. }
  140. setData(){
  141. }
  142. update(deltaTime: number) {
  143. }
  144. }