HallComp.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System;
  2. using Api;
  3. using Message;
  4. using Plugins.CxShine.page;
  5. using Plugins.CxShine.Singleton;
  6. using Sound;
  7. using TMPro;
  8. using UI.BattleRequest;
  9. using UI.Common;
  10. using UI.Hall;
  11. using UI.Items;
  12. using UI.Loading;
  13. using UnityEditor;
  14. using UnityEngine;
  15. using UnityEngine.UI;
  16. namespace UI
  17. {
  18. public class HallComp : UnitySingleton<HallComp>
  19. {
  20. public Transform OnlinePlayerContainer;
  21. public GameObject PlayerPrefab;
  22. public GameObject FullLoadingPrefab;
  23. private GameObject _fullLoadingInstance;
  24. public GameObject RefreshButton;
  25. public Button DefaultSelectOnlinePlayerTypeButton;
  26. public InputField PlayerIdInput;
  27. public CockUIItemComp MyCockComp;
  28. public GameObject MarketPrefab;
  29. public GameObject SettingPagePrefab;
  30. public GameObject UpdateInfoPrefab;
  31. public GameObject RankPagePrefab;
  32. private OnlinePlayerType _curType = OnlinePlayerType.Friends;
  33. public Action OnLoadingCloseAction;
  34. private void Start()
  35. {
  36. MessageComp.Instance.EnterHall = true;
  37. // initOnlinePlayers();
  38. SoundCore.Instance.PlaySound(SoundType.HallBgmMain, SoundCtrl.HallBgmPlayer, true, true);
  39. BackToHallAndRefreshUI();
  40. Invoke(nameof(TTT), 1.0f);
  41. }
  42. public void BackToHallAndRefreshUI()
  43. {
  44. MyCockComp.ModeCockMy();
  45. UserInfoComp.Instance.RefreshSelfUI();
  46. }
  47. public void HideSelf()
  48. {
  49. PageManagerComp.singleton.HideUI();
  50. }
  51. private void TTT()
  52. {
  53. DefaultSelectOnlinePlayerTypeButton.onClick.Invoke();
  54. // GameStartJumper.JumpGameScene("100020VS100019:1680153980543:WNBIDVLNYT");
  55. }
  56. public void A__ClickUpdateInfo()
  57. {
  58. PageManagerComp.singleton.OpenPage(UpdateInfoPrefab);
  59. }
  60. public void A__ClickSetting()
  61. {
  62. PageManagerComp.singleton.OpenPage(SettingPagePrefab);
  63. }
  64. public void OpenLoading()
  65. {
  66. if (_fullLoadingInstance == null)
  67. {
  68. _fullLoadingInstance = PageManagerComp.singleton.OpenPage(FullLoadingPrefab);
  69. _fullLoadingInstance.GetComponent<PageComp>().setOnPageCloseListener((() =>
  70. {
  71. _fullLoadingInstance = null;
  72. OnLoadingCloseAction?.Invoke();
  73. }));
  74. }
  75. }
  76. public void OpenAutoCloseLoading(int seconds)
  77. {
  78. OpenLoading();
  79. _fullLoadingInstance.GetComponent<LoadingComp>().initAutoClose(seconds);
  80. }
  81. public void CloseLoading()
  82. {
  83. if (_fullLoadingInstance != null)
  84. {
  85. var p = _fullLoadingInstance.GetComponent<PageComp>();
  86. p.A__ClosePage();
  87. }
  88. }
  89. public void A__ClickRefresh()
  90. {
  91. // TipsComp.ShowTips("sssssss");
  92. initOnlinePlayers();
  93. }
  94. public void A__ClickInviteByPlayerId()
  95. {
  96. // TipsComp.ShowTips("test test test!");
  97. if (!String.IsNullOrEmpty(PlayerIdInput.text))
  98. {
  99. int enemyId;
  100. int.TryParse(PlayerIdInput.text, out enemyId);
  101. if (enemyId > 0)
  102. {
  103. OnInviteClick(enemyId);
  104. }
  105. }
  106. }
  107. public void A__Click_AllOnlinePlayers()
  108. {
  109. if (_curType == OnlinePlayerType.All)
  110. {
  111. return;
  112. }
  113. _curType = OnlinePlayerType.All;
  114. initOnlinePlayers();
  115. }
  116. public void A__Click_FriendsPlayers()
  117. {
  118. if (_curType == OnlinePlayerType.Friends)
  119. {
  120. return;
  121. }
  122. _curType = OnlinePlayerType.Friends;
  123. initOnlinePlayers();
  124. }
  125. public void A__Click_IndiaPlayers()
  126. {
  127. if (_curType == OnlinePlayerType.India)
  128. {
  129. return;
  130. }
  131. _curType = OnlinePlayerType.India;
  132. initOnlinePlayers();
  133. }
  134. private void initOnlinePlayers()
  135. {
  136. ApiComp.Instance.GetOnlinePlayers(_curType, data =>
  137. {
  138. RemoveTransformAllChild(OnlinePlayerContainer);
  139. if (data.players != null)
  140. {
  141. foreach (var dataPlayer in data.players)
  142. {
  143. Instantiate(PlayerPrefab, OnlinePlayerContainer, false).GetComponent<OnlinePlayerItemComp>()
  144. .init(OnInviteClick, dataPlayer);
  145. }
  146. }
  147. }, (code, err) => { });
  148. }
  149. private void OnInviteClick(int enemyId)
  150. {
  151. OpenAutoCloseLoading(10);
  152. BattleInviteManager.Instance.InviteBattle(enemyId, data => { }, (code, err) =>
  153. {
  154. CloseLoading();
  155. // TipsComp.ShowTips();
  156. });
  157. }
  158. public void A__ClickMarket()
  159. {
  160. PageManagerComp.singleton.OpenPage(MarketPrefab);
  161. }
  162. public void A__ClickRank()
  163. {
  164. PageManagerComp.singleton.OpenPage(RankPagePrefab);
  165. }
  166. }
  167. }