PopRoomGroup.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PopRoomGroup : PopBase {
  5. [SerializeField]
  6. private TextMesh SchoolNameText;
  7. [SerializeField]
  8. private TextMesh IDNameText;
  9. [SerializeField]
  10. private TextMesh UserNameText;
  11. [SerializeField]
  12. private ItemListView ItemList;//本地课
  13. [SerializeField]
  14. private Game3DButton CreateBtn;//创建本校课按钮
  15. [SerializeField]
  16. private Game3DButton QuitBtn;//退出房间
  17. [SerializeField]
  18. private GameObject PrivateBg;
  19. [SerializeField]
  20. private GameObject PublicBg;
  21. protected override void Awake()
  22. {
  23. base.Awake();
  24. }
  25. protected override void Start () {
  26. base.Start();
  27. ItemList.InitClick(ItemClick);
  28. if (CreateBtn != null)
  29. CreateBtn.onClick.AddListener(CreateClick);
  30. QuitBtn.onClick.AddListener(QuitClick);
  31. MessageCenterController.Instance.Register(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW, RefreshListen);
  32. }
  33. protected override void OnDestroy()
  34. {
  35. base.OnDestroy();
  36. if (CreateBtn != null)
  37. CreateBtn.onClick.RemoveListener(CreateClick);
  38. QuitBtn.onClick.RemoveListener(QuitClick);
  39. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW, RefreshListen);
  40. }
  41. private string school_name_str = "{0}({1})";
  42. private string id_name_str = "用户id: {0}";
  43. private string user_name_str = "用户名: {0}";
  44. public override void Show()
  45. {
  46. base.Show();
  47. //这里要区别一下 当前是哪个服务器
  48. if (GameServerInfo.Instance.CurServer.serverType == ServerType.Public)
  49. {
  50. CreateBtn.gameObject.SetActive(GamePlayerData.Instance.RootCreatePublic);
  51. }
  52. else
  53. {
  54. CreateBtn.gameObject.SetActive(GamePlayerData.Instance.IsMaster);
  55. }
  56. string tipStr = GameServerInfo.Instance.CurServer.serverType == ServerType.Public ? "全国": "本地";
  57. if (PlayerPrefs.HasKey("SocketUrl"))
  58. {
  59. if (PlayerPrefs.GetInt("SocketUrl") == 1)
  60. {
  61. tipStr = "本地";
  62. }
  63. else
  64. {
  65. tipStr = "云端";
  66. }
  67. }
  68. SchoolNameText.text = string.Format(school_name_str, GamePlayerData.Instance.school_name, tipStr);
  69. IDNameText.text = string.Format(id_name_str, GamePlayerData.Instance.user_id);
  70. UserNameText.text = string.Format(user_name_str, GamePlayerData.Instance.user_name);
  71. InitItemList();
  72. PublicBg.SetActive(GameServerInfo.Instance.CurServer.serverType == ServerType.Public);
  73. PrivateBg.SetActive(GameServerInfo.Instance.CurServer.serverType == ServerType.Private);
  74. //IvChatManager.Instance.QueryRoom();//进来的时候需要刷新的
  75. }
  76. //框体类型
  77. public override PopType MType { get { return PopType.RoomList; } }
  78. private void TabClick()
  79. {
  80. RefreshItemList();
  81. }
  82. private void InitItemList()
  83. {
  84. if (ItemList != null)
  85. {
  86. if(GameServerInfo.Instance.CurServer.serverType == ServerType.Public)
  87. {
  88. ItemList.InitInfo(GamePlayerData.Instance.room_data.PublicList.ToArray());
  89. }
  90. else
  91. {
  92. ItemList.InitInfo(GamePlayerData.Instance.room_data.PrivateList.ToArray());
  93. }
  94. }
  95. }
  96. private void RefreshItemList()
  97. {
  98. if (ItemList != null)
  99. {
  100. if (GameServerInfo.Instance.CurServer.serverType == ServerType.Public)
  101. {
  102. ItemList.RefreshInfo(GamePlayerData.Instance.room_data.PublicList.ToArray());
  103. }
  104. else
  105. {
  106. ItemList.RefreshInfo(GamePlayerData.Instance.room_data.PrivateList.ToArray());
  107. }
  108. }
  109. }
  110. private void CreateClick()
  111. {
  112. this.Hide();
  113. GamePlayerData.Instance.CreateRoomdata = new SocketRoomItemData();
  114. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.SubjectList, null));
  115. }
  116. private void RefreshListen(System.Object data = null)
  117. {
  118. RefreshItemList();
  119. //IvChatManager.Instance.QueryRoom();
  120. }
  121. private void ItemClick(ItemViewBase item)
  122. {
  123. var data = item.ItemData as SocketOnlineRoomItemData;
  124. if(data == null)
  125. {
  126. return;
  127. }
  128. RoomItemView view = item as RoomItemView;
  129. if(data.onlineCt >= view.CurMaxCt)
  130. {
  131. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "房间内人数已达到上限");
  132. return;
  133. }
  134. CDebug.Log("这里应该选择个弹出窗口 提示进入或者取消" + data.room_id);
  135. GamePlayerData.Instance.room_data.CurRoomId = data.room_id;
  136. //获取课程信息
  137. MessageCenterController.Instance.Register(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
  138. HttpStaticMessage.SendHttpQuestion(GamePlayerData.Instance.user_id, GamePlayerData.Instance.room_data.CurOnlineData.course_id);
  139. //同时进入语音
  140. Debug.Log("data.owner_name" + data.owner_name);
  141. //IvChatManager.Instance.JoinRoomById(data.owner_name.ToString());
  142. }
  143. private void CourseLoadOK(System.Object datas)
  144. {
  145. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK, CourseLoadOK);
  146. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ENTER_COURSE);
  147. UIDataManager.Instance.ClearAll();//提前清除房间的数据
  148. GameNetManager.Instance.mSocketMsgCenter.PlayerEnterRoom(GamePlayerData.Instance.room_data.CurRoomId, true);
  149. }
  150. private void QuitClick()
  151. {
  152. this.Hide();
  153. //显示登陆的界面
  154. GameNetManager.Instance.mSocketMsgCenter.StopConnect();//主动断开
  155. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.ServerList, null));
  156. }
  157. }