123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PopCourseCreateByName : PopBase
- {
- [SerializeField]
- private Game3DButton OkBtn;
- [SerializeField]
- private Game3DButton CancelBtn;
- [SerializeField]
- private Game3DInputField NameInputField;
- protected override void Start()
- {
- base.Start();
- OkBtn.onClick.AddListener(OkClick);
- CancelBtn.onClick.AddListener(delegate () {
- this.Hide();
- NormalUIData n_data = new NormalUIData();
- n_data.str = data.subject_id.ToString();
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.CourseList, n_data));
- });
- }
- //框体类型
- public override PopType MType { get { return PopType.CreateRoom; } }
- protected override void OnDestroy()
- {
- base.OnDestroy();
- OkBtn.onClick.RemoveListener(OkClick);
- }
- private SocketRoomItemData data;
- public override void Show(System.Object data)
- {
- base.Show(data);
- this.data = (SocketRoomItemData)data;
- //this.NameInputField.text = "";//重置输入框的内容
- this.NameInputField.text = RandomName(3);//重置输入框的内容
- //自动主动帮助创建
- //this.NameInputField.text = "萃英公开课";
- //PrivateClick();
- }
- private string RandomName(int num)
- {
- string r_name = "";
- string randGroup = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- for(int i = 0; i< num; i++)
- {
- if(i == 0)
- {
- r_name += randGroup.Substring(Random.Range(10, randGroup.Length - 1), 1);
- }
- else
- {
- r_name += randGroup.Substring(Random.Range(0, randGroup.Length - 1), 1);
- }
-
- }
- return r_name;
- }
- public override void Show()
- {
- base.Show();
- this.NameInputField.text = "";//重置输入框的内容
- }
- public override void Hide()
- {
- base.Hide();
- this.NameInputField.keyboard.gameObject.SetActive(false);//隐藏输入框
- }
- private bool CheckNameSafe()
- {
- Debug.Log("名字长度" + RoomName.Length);
- if (RoomName.Length == 0)
- {
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "房间名不能为空");
- return false;
- }
- if (RoomName.Length > GameEnum.ROOM_NAME_MAX_LENGHT)
- {
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "房间名字符超过" + GameEnum.ROOM_NAME_MAX_LENGHT);
- return false;
- }
- return true;
- }
- private void OkClick()
- {
- if (!CheckNameSafe())
- {
- return;
- }
- this.Hide();
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
- HttpStaticMessage.SendHttpQuestion(GamePlayerData.Instance.user_id, data.course_id);
- }
- public string RoomName
- {
- get { return NameInputField.text; }
- }
- private void CourseLoadOK(System.Object datas)
- {
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
- if (this.NameInputField.text.Length > 0)
- {
- this.data.course_name = this.NameInputField.text;
- }
- CDebug.Log("发送创建房间的请求");
- UIDataManager.Instance.ClearAll();//提前清除房间的数据
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_CREATE_ROOM_SOCKET_DATA, this.data);
- }
- private NormalUIData CurData
- {
- get { return UICanshu as NormalUIData; }
- }
- }
|