HallComp.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. private OnlinePlayerType _curType = OnlinePlayerType.Friends;
  32. public Action OnLoadingCloseAction;
  33. private void Start()
  34. {
  35. MessageComp.Instance.EnterHall = true;
  36. // initOnlinePlayers();
  37. SoundCore.Instance.PlaySound(SoundType.HallBgmMain, SoundCtrl.HallBgmPlayer, true, true);
  38. BackToHallAndRefreshUI();
  39. Invoke(nameof(TTT), 1.0f);
  40. }
  41. public void BackToHallAndRefreshUI()
  42. {
  43. MyCockComp.ModeCockMy();
  44. UserInfoComp.Instance.RefreshSelfUI();
  45. }
  46. public void HideSelf()
  47. {
  48. PageManagerComp.singleton.HideUI();
  49. }
  50. private void TTT()
  51. {
  52. DefaultSelectOnlinePlayerTypeButton.onClick.Invoke();
  53. // GameStartJumper.JumpGameScene("100020VS100019:1680153980543:WNBIDVLNYT");
  54. }
  55. public void A__ClickUpdateInfo()
  56. {
  57. PageManagerComp.singleton.OpenPage(UpdateInfoPrefab);
  58. }
  59. public void A__ClickSetting()
  60. {
  61. PageManagerComp.singleton.OpenPage(SettingPagePrefab);
  62. }
  63. public void OpenLoading()
  64. {
  65. if (_fullLoadingInstance == null)
  66. {
  67. _fullLoadingInstance = PageManagerComp.singleton.OpenPage(FullLoadingPrefab);
  68. _fullLoadingInstance.GetComponent<PageComp>().setOnPageCloseListener((() =>
  69. {
  70. _fullLoadingInstance = null;
  71. OnLoadingCloseAction?.Invoke();
  72. }));
  73. }
  74. }
  75. public void OpenAutoCloseLoading(int seconds)
  76. {
  77. OpenLoading();
  78. _fullLoadingInstance.GetComponent<LoadingComp>().initAutoClose(seconds);
  79. }
  80. public void CloseLoading()
  81. {
  82. if (_fullLoadingInstance != null)
  83. {
  84. var p = _fullLoadingInstance.GetComponent<PageComp>();
  85. p.A__ClosePage();
  86. }
  87. }
  88. public void A__ClickRefresh()
  89. {
  90. // TipsComp.ShowTips("sssssss");
  91. initOnlinePlayers();
  92. }
  93. public void A__ClickInviteByPlayerId()
  94. {
  95. // TipsComp.ShowTips("test test test!");
  96. if (!String.IsNullOrEmpty(PlayerIdInput.text))
  97. {
  98. int enemyId;
  99. int.TryParse(PlayerIdInput.text, out enemyId);
  100. if (enemyId > 0)
  101. {
  102. OnInviteClick(enemyId);
  103. }
  104. }
  105. }
  106. public void A__Click_AllOnlinePlayers()
  107. {
  108. if (_curType == OnlinePlayerType.All)
  109. {
  110. return;
  111. }
  112. _curType = OnlinePlayerType.All;
  113. initOnlinePlayers();
  114. }
  115. public void A__Click_FriendsPlayers()
  116. {
  117. if (_curType == OnlinePlayerType.Friends)
  118. {
  119. return;
  120. }
  121. _curType = OnlinePlayerType.Friends;
  122. initOnlinePlayers();
  123. }
  124. public void A__Click_IndiaPlayers()
  125. {
  126. if (_curType == OnlinePlayerType.India)
  127. {
  128. return;
  129. }
  130. _curType = OnlinePlayerType.India;
  131. initOnlinePlayers();
  132. }
  133. private void initOnlinePlayers()
  134. {
  135. ApiComp.Instance.GetOnlinePlayers(_curType, data =>
  136. {
  137. RemoveTransformAllChild(OnlinePlayerContainer);
  138. if (data.players != null)
  139. {
  140. foreach (var dataPlayer in data.players)
  141. {
  142. Instantiate(PlayerPrefab, OnlinePlayerContainer, false).GetComponent<OnlinePlayerItemComp>()
  143. .init(OnInviteClick, dataPlayer);
  144. }
  145. }
  146. }, (code, err) => { });
  147. }
  148. private void OnInviteClick(int enemyId)
  149. {
  150. OpenAutoCloseLoading(10);
  151. BattleInviteManager.Instance.InviteBattle(enemyId, data => { }, (code, err) =>
  152. {
  153. CloseLoading();
  154. // TipsComp.ShowTips();
  155. });
  156. }
  157. public void A__ClickMarket()
  158. {
  159. PageManagerComp.singleton.OpenPage(MarketPrefab);
  160. }
  161. }
  162. }