HomeView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using System;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. /* 主界面 */
  10. public class HomeView : MonoBehaviour
  11. {
  12. [SerializeField] Image myAvatarSprite;
  13. [SerializeField] Text nickNameText;
  14. [SerializeField] GameObject[] genders;
  15. [SerializeField] GameObject btnConnectBow;
  16. [SerializeField] GameObject btnConnectArrow;
  17. [SerializeField] GameObject friendTip;
  18. public static HomeView ins;
  19. void Awake() {
  20. if (CommonConfig.needToExamine) {
  21. transform.Find("LeftPanel/Item (1)").gameObject.SetActive(false);
  22. transform.Find("RightPanel/Item/Text").GetComponent<TextAutoLanguage>().SetText(1234562);
  23. transform.Find("RightPanel/Item (1)/Text").GetComponent<TextAutoLanguage>().SetText(1234563);
  24. transform.Find("RightPanel/Item (3)").gameObject.SetActive(false);
  25. }
  26. }
  27. void Start()
  28. {
  29. ins = this;
  30. BluetoothHolder.Init();
  31. AudioMgr.Init();
  32. if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
  33. if (LoginMgr.myUserInfo.id > 0) {
  34. RenderNameOrGender();
  35. RenderMyAvatarSprite();
  36. RenderDeviceNames();
  37. }
  38. StartCoroutine(RefreshFriendBar());
  39. }
  40. void OnDestroy()
  41. {
  42. if (ins == this) ins = null;
  43. }
  44. void Update() {
  45. if (UserPlayer.ins != null) {
  46. if (UserPlayer.ins.tempData.hasFriendRequest && !friendTip.activeSelf) {
  47. friendTip.SetActive(true);
  48. }
  49. else if (!UserPlayer.ins.tempData.hasFriendRequest && friendTip.activeSelf) {
  50. friendTip.SetActive(false);
  51. }
  52. }
  53. }
  54. public void RenderNameOrGender() {
  55. nickNameText.text = LoginMgr.myUserInfo.nickname;
  56. genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
  57. genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
  58. LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
  59. }
  60. public void RenderMyAvatarSprite() {
  61. myAvatarSprite.sprite = RoleMgr.GetAvatar(LoginMgr.myUserInfo.avatarID);
  62. }
  63. public void RenderDeviceNames()
  64. {
  65. try {
  66. (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
  67. // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
  68. this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
  69. this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
  70. } catch (System.Exception) {}
  71. }
  72. public void GoTo(string target) {
  73. AudioMgr.ins.PlayBtn();
  74. switch (target)
  75. {
  76. case "开始游戏":
  77. if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
  78. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  79. return;
  80. }
  81. GameObject.Instantiate(SceneResMgr.ins.GetPrefab("GameStartView"));
  82. break;
  83. case "联机游戏":
  84. if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
  85. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
  86. return;
  87. }
  88. GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
  89. GameObject.Instantiate(SceneResMgr.ins.GetPrefab("PKGameOptionView"));
  90. break;
  91. case "好友":
  92. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/FriendView"));
  93. break;
  94. case "排行磅":
  95. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RankView"));
  96. break;
  97. case "对战":
  98. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
  99. break;
  100. case "教程":
  101. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/CourseView"), Vector3.zero, new Quaternion());
  102. break;
  103. case "我的":
  104. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/MeView"), Vector3.zero, new Quaternion());
  105. break;
  106. case "设备":
  107. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/DeviceView"), Vector3.zero, new Quaternion());
  108. break;
  109. case "商城":
  110. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"), Vector3.zero, new Quaternion());
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. /* FriendBar */
  117. GameObject friendItemPrefab = null;
  118. Transform friendBarContent = null;
  119. IEnumerator RefreshFriendBar() {
  120. if (friendItemPrefab == null) {
  121. friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
  122. Destroy(friendItemPrefab.GetComponent<Image>());
  123. friendItemPrefab.SetActive(false);
  124. }
  125. if (friendBarContent == null) {
  126. friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
  127. }
  128. while (LoginMgr.myUserInfo.id < 1) {
  129. yield return null;
  130. }
  131. Action<JArray> cb = RenderFriendList;
  132. UserPlayer.ins.call("friendComp.getMyFriends", null, cb);
  133. }
  134. public void RenderFriendList(JArray list) {
  135. for (int i = 1; i < friendBarContent.childCount; i++) {
  136. Destroy(friendBarContent.GetChild(i).gameObject);
  137. }
  138. if (list.Count > 0) {
  139. Color outColor;
  140. foreach (var itemInfo in list) {
  141. int friendID = itemInfo.Value<int>("friendID");
  142. int avatarID = itemInfo.Value<int>("avatarID");
  143. string nickname = itemInfo.Value<string>("nickname");
  144. bool online = itemInfo.Value<bool>("online");
  145. long offlineTime = itemInfo.Value<long>("offlineTime");
  146. GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
  147. o.SetActive(true);
  148. o.name = friendID.ToString();
  149. o.transform.Find("Avatar").GetComponent<Image>().sprite = RoleMgr.GetAvatar(avatarID);
  150. o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
  151. TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
  152. TimeUtil.SetOfflineTimeTextKey(offlineTime, online, timeTip);
  153. if (online) {
  154. ColorUtility.TryParseHtmlString("#12B525", out outColor);
  155. } else {
  156. ColorUtility.TryParseHtmlString("#A8B2BD", out outColor);
  157. }
  158. timeTip.GetComponent<Text>().color = outColor;
  159. }
  160. }
  161. }
  162. int flag_SwapFriendAndRank = 0;
  163. public void OnClick_SwapFriendAndRank() {
  164. AudioMgr.ins.PlayBtn();
  165. if (flag_SwapFriendAndRank == 0) {
  166. flag_SwapFriendAndRank = 1;
  167. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("rank_title");
  168. } else if (flag_SwapFriendAndRank == 1) {
  169. flag_SwapFriendAndRank = 0;
  170. transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("friend_title");
  171. }
  172. }
  173. public void OnClick_ShowDetail() {
  174. AudioMgr.ins.PlayBtn();
  175. if (flag_SwapFriendAndRank == 0) {
  176. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/FriendView"));
  177. } else if (flag_SwapFriendAndRank == 1) {
  178. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RankView"));
  179. }
  180. }
  181. }