JoinRoomForms.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using LitJson;
  2. using SUIFW;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class JoinRoomForms : BaseUIForms
  9. {
  10. public InputField fieldName;
  11. public Text remind;
  12. public Button joinBtn;
  13. public Button returnBtn;
  14. private bool isClick = false;
  15. #region 窗体生命周期
  16. public override void Display()
  17. {
  18. base.Display();
  19. Init();
  20. }
  21. public override void Redisplay()
  22. {
  23. base.Redisplay();
  24. }
  25. public override void Freeze()
  26. {
  27. base.Freeze();
  28. }
  29. public override void Hiding()
  30. {
  31. base.Hiding();
  32. }
  33. #endregion
  34. private void Awake()
  35. {
  36. joinBtn.onClick.AddListener(ClickOnJoin);
  37. returnBtn.onClick.AddListener(ClickOnReturn);
  38. fieldName.onValueChanged.AddListener(UserValueChanged);
  39. fieldName.onEndEdit.AddListener(UserValueEnd);
  40. }
  41. private void UserValueEnd(string arg0)
  42. {
  43. fieldName.image.color = Color.white;
  44. }
  45. public void Init()
  46. {
  47. isClick = false;
  48. fieldName.text = "";
  49. remind.gameObject.SetActive(false);
  50. fieldName.image.color = Color.white;
  51. }
  52. private void UserValueChanged(string arg0)
  53. {
  54. ChangeBlue(fieldName.image);
  55. remind.gameObject.SetActive(false);
  56. }
  57. public void ClickOnJoin()
  58. {
  59. if (fieldName.text == "")
  60. {
  61. remind.gameObject.SetActive(true);
  62. remind.text = "请输入房间号";
  63. ChangeRed(fieldName.image);
  64. }
  65. else
  66. {
  67. if (!isClick)
  68. {
  69. isClick = true;
  70. OnJoinRoom(fieldName.text);
  71. }
  72. }
  73. }
  74. private void OnJoinRoom(string roomId)
  75. {
  76. RoomMainInfo.roomNum = roomId;
  77. WSHandler.Office.OnJoinRoomReveived -= joinRoom;
  78. WSHandler.Office.OnJoinRoomReveived += joinRoom;
  79. WSHandler.Office.JoinRoom(roomId);
  80. }
  81. private void joinRoom(JsonData data)
  82. {
  83. switch (data["data"]["code"].ToString())
  84. {
  85. case "200":
  86. WSHandler.roomRtcinit(RoomMainInfo.roomNum);
  87. WSHandler.Office.ChangeUserType(UserInfo.BusyType);
  88. break;
  89. case "1000":
  90. remind.gameObject.SetActive(true);
  91. remind.text = "房间号无效";
  92. ChangeRed(fieldName.image);
  93. isClick = false;
  94. break;
  95. case "1001":
  96. ShowUIForms(SysConst.PopForms);
  97. PopForms.Instance.ShowPublic(PopType.PopOne, "房间人数已满", "知道了", ()=> {
  98. ClickOnReturn();
  99. });
  100. isClick = false;
  101. break;
  102. default:
  103. TipMgr.Instance.ShowTip(RtcStrConfig.serverError);
  104. isClick = false;
  105. break;
  106. }
  107. WSHandler.Office.OnJoinRoomReveived -= joinRoom;
  108. }
  109. private void ClickOnReturn()
  110. {
  111. CloseOrReturnUIForms();
  112. ShowUIForms(SysConst.MainPanelForms);
  113. }
  114. }