PopCourseCreateByName.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PopCourseCreateByName : PopBase
  5. {
  6. [SerializeField]
  7. private Game3DButton OkBtn;
  8. [SerializeField]
  9. private Game3DButton CancelBtn;
  10. [SerializeField]
  11. private Game3DInputField NameInputField;
  12. protected override void Start()
  13. {
  14. base.Start();
  15. OkBtn.onClick.AddListener(OkClick);
  16. CancelBtn.onClick.AddListener(delegate () {
  17. this.Hide();
  18. NormalUIData n_data = new NormalUIData();
  19. n_data.str = data.subject_id.ToString();
  20. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.CourseList, n_data));
  21. });
  22. }
  23. //框体类型
  24. public override PopType MType { get { return PopType.CreateRoom; } }
  25. protected override void OnDestroy()
  26. {
  27. base.OnDestroy();
  28. OkBtn.onClick.RemoveListener(OkClick);
  29. }
  30. private SocketRoomItemData data;
  31. public override void Show(System.Object data)
  32. {
  33. base.Show(data);
  34. this.data = (SocketRoomItemData)data;
  35. //this.NameInputField.text = "";//重置输入框的内容
  36. this.NameInputField.text = RandomName(3);//重置输入框的内容
  37. //自动主动帮助创建
  38. //this.NameInputField.text = "萃英公开课";
  39. //PrivateClick();
  40. }
  41. private string RandomName(int num)
  42. {
  43. string r_name = "";
  44. string randGroup = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  45. for(int i = 0; i< num; i++)
  46. {
  47. if(i == 0)
  48. {
  49. r_name += randGroup.Substring(Random.Range(10, randGroup.Length - 1), 1);
  50. }
  51. else
  52. {
  53. r_name += randGroup.Substring(Random.Range(0, randGroup.Length - 1), 1);
  54. }
  55. }
  56. return r_name;
  57. }
  58. public override void Show()
  59. {
  60. base.Show();
  61. this.NameInputField.text = "";//重置输入框的内容
  62. }
  63. public override void Hide()
  64. {
  65. base.Hide();
  66. this.NameInputField.keyboard.gameObject.SetActive(false);//隐藏输入框
  67. }
  68. private bool CheckNameSafe()
  69. {
  70. Debug.Log("名字长度" + RoomName.Length);
  71. if (RoomName.Length == 0)
  72. {
  73. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "房间名不能为空");
  74. return false;
  75. }
  76. if (RoomName.Length > GameEnum.ROOM_NAME_MAX_LENGHT)
  77. {
  78. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "房间名字符超过" + GameEnum.ROOM_NAME_MAX_LENGHT);
  79. return false;
  80. }
  81. return true;
  82. }
  83. private void OkClick()
  84. {
  85. if (!CheckNameSafe())
  86. {
  87. return;
  88. }
  89. this.Hide();
  90. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
  91. HttpStaticMessage.SendHttpQuestion(GamePlayerData.Instance.user_id, data.course_id);
  92. }
  93. public string RoomName
  94. {
  95. get { return NameInputField.text; }
  96. }
  97. private void CourseLoadOK(System.Object datas)
  98. {
  99. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
  100. if (this.NameInputField.text.Length > 0)
  101. {
  102. this.data.course_name = this.NameInputField.text;
  103. }
  104. CDebug.Log("发送创建房间的请求");
  105. UIDataManager.Instance.ClearAll();//提前清除房间的数据
  106. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_CREATE_ROOM_SOCKET_DATA, this.data);
  107. }
  108. private NormalUIData CurData
  109. {
  110. get { return UICanshu as NormalUIData; }
  111. }
  112. }