joinRoom.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { _decorator, Component, Node, Label } from 'cc';
  2. import { ClientEvent } from './clientEvent';
  3. import { Constant } from './constant';
  4. import ChessMng, { ChessType } from './Game/DiffSel/ChessMng';
  5. import { GameMng } from './GameMng';
  6. import ScenceMng from './gcommon/ScenceMng';
  7. import { UIButton } from './gcommon/UIButton';
  8. import { UIManager } from './gcommon/UIManager';
  9. import { msgManager } from './socket/msgManager';
  10. import { roomData } from './UserData/roomData';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('joinRoom')
  13. export class joinRoom extends Component {
  14. @property(Node)
  15. btnClose: Node = null;
  16. @property(Node)
  17. btnReStart: Node = null;
  18. @property(Node)
  19. btnDelete: Node = null;
  20. @property(Node)
  21. btnSure: Node = null;
  22. @property(Node)
  23. labNumber: Node = null;
  24. @property(Node)
  25. numberNodeParent: Node = null;
  26. num:string = "";
  27. start() {
  28. for (let index = 0; index < 10; index++) {
  29. var btn = this.numberNodeParent.getChildByName("number_"+index)
  30. UIButton.BindClick(btn,()=>{
  31. this.updateLab(index+"")
  32. },this)
  33. }
  34. UIButton.BindClick(this.btnClose,()=>{
  35. this.node.destroy()
  36. },this)
  37. UIButton.BindClick(this.btnReStart,()=>{
  38. this.num = ""
  39. this.labNumber.getComponent(Label).string=this.num
  40. },this)
  41. UIButton.BindClick(this.btnDelete,()=>{
  42. this.num = this.num.substring(0,this.num.length-1);
  43. this.labNumber.getComponent(Label).string = this.num
  44. },this)
  45. UIButton.BindClick(this.btnSure,()=>{
  46. UIManager.AddPrefab(GameMng.Instance.uiloading)
  47. msgManager.joinRoom(this.num)
  48. },this)
  49. ClientEvent.on(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  50. }
  51. onDestroy(){
  52. ClientEvent.off(Constant.EVENT_TYPE.MSG_JOIN_ROOM,this.onJoinRoom,this)
  53. }
  54. onJoinRoom(room:roomData){
  55. UIManager.removeLoadingLayer()
  56. GameMng.updateRoomData(room)
  57. ScenceMng.Instance.load('Chess')
  58. console.log("room",room)
  59. }
  60. updateLab(number){
  61. this.num=this.num+number
  62. this.labNumber.getComponent(Label).string = this.num
  63. }
  64. update(deltaTime: number) {
  65. }
  66. }