| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 | 
							- using System.Collections;
 
- using System.Collections.Generic;
 
- using UnityEngine;
 
- using UnityEngine.UI;
 
- using UnityEngine.SceneManagement;
 
- using System;
 
- using Newtonsoft.Json;
 
- using Newtonsoft.Json.Linq;
 
- /* 主界面 */
 
- public class HomeView : JCUnityLib.ViewBase
 
- {
 
-     public static bool bOpenOtherView = false;
 
-     public static string openName = "";
 
-     [SerializeField] Image myAvatarSprite;
 
-     [SerializeField] Text nickNameText;
 
-     [SerializeField] GameObject[] genders;
 
-     [SerializeField] GameObject btnConnectBow;
 
-     [SerializeField] Text gameVersion;
 
-     [SerializeField] GameObject friendBarTipTop;
 
-     [SerializeField] GameObject friendBarTipBottom;
 
-     [SerializeField] GameObject bettery;
 
-     [SerializeField] GameObject betteryBar;
 
-     [SerializeField] GameObject bettery2;
 
-     [SerializeField] GameObject betteryBar2;
 
-     [SerializeField] HomeView_ChallengeOption challengeOption;
 
-     public HomeView_ChallengeOption MyChallengeOption => challengeOption;
 
-     [SerializeField] HomeView_TopBarView topBarView;
 
-     public HomeView_TopBarView MyTopBarView => topBarView;
 
-     public static HomeView ins;
 
-     void Awake() {
 
-         gameVersion.text = "V" + Application.version;
 
-         gameVersion.gameObject.SetActive(false); //隐藏版本号
 
-         if (CommonConfig.needToExamine) {
 
-             transform.Find("LeftPanel/Item (1)").gameObject.SetActive(false);
 
-             transform.Find("RightPanel/Item/Text").GetComponent<TextAutoLanguage>().SetText(1234562);
 
-             transform.Find("RightPanel/Item (1)/Text").GetComponent<TextAutoLanguage>().SetText(1234563);
 
-             transform.Find("RightPanel/Item (3)").gameObject.SetActive(false);
 
-         }
 
-         
 
-         if (topBarView && challengeOption) topBarView.onChangeTypeEvent.AddListener(challengeOption.refreshList);
 
-     }
 
-     void Start()
 
-     {
 
-         ins = this;
 
-         transform.SetSiblingIndex(0); //放在ui最底层
 
-         BluetoothHolder.Init();
 
-         AudioMgr.Init();
 
-         TopBarView.NeedShowIt(this);
 
-         // if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
 
-         if (LoginMgr.myUserInfo.id > 0 || (CommonConfig.StandaloneMode && UserPlayer.ins != null && UserPlayer.ins.hasGetUserInfo)) {
 
-             RenderNameOrGender();
 
-             RenderMyAvatarSprite();
 
-             RenderDeviceNames();
 
-         }
 
-         if (CommonConfig.StandaloneMode)
 
-         {
 
-             transform.Find("FriendBar").gameObject.SetActive(false);
 
-             transform.Find("RightPanel/Line (1)").gameObject.SetActive(false);
 
-             transform.Find("RightPanel/Item (1)").gameObject.SetActive(false);
 
-         }
 
-         else StartCoroutine(RefreshFriendBar());
 
-         //如果需要初始化跳转页面,这里处理
 
-         Debug.Log("bOpenOtherView:"+ bOpenOtherView);
 
-         if (bOpenOtherView) {
 
-             bOpenOtherView = false;
 
-             switch (openName)
 
-             {
 
-                 case "DeviceView":
 
-                    // ViewMgr.Instance.ShowView<DeviceView>();
 
-                     break;
 
-                 default:
 
-                     break;
 
-             }
 
-         }
 
-         //StartCoroutine(testTip());
 
-     }
 
-     IEnumerator testTip() {
 
-         yield return new WaitForSeconds(1.0f);
 
-         GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_HomeViewTip);
 
-         settingsViewObj.GetComponent<HomeView_Tip>().setHomeTip(0);
 
-     }
 
-     void OnDestroy()
 
-     {
 
-         if (ins == this) ins = null;
 
-         TopBarView.DontNeedShowIt(this);
 
-     }
 
-     void Update() {
 
-         UpdateCheckRenderFriendTip();
 
-         UpdateBtnForConnect();
 
-         //更新电池显示
 
-         updateBatteryStatus();
 
-     }
 
-    // float countingTime1 = 0;
 
-     BluetoothStatusEnum bowStatus;
 
-     void UpdateBtnForConnect() {
 
-         if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
 
-             bowStatus = BluetoothAim.ins.status;
 
-             (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
 
-             //btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
 
-             //btnConnectBow.GetComponentInChildren<Text>().color = color;
 
-             //btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
 
-         }
 
-     }
 
-     public static bool ShowProminentBeforeConnectBLE(Action onAgree = null)
 
-     {
 
-         if (CommonConfig.StandaloneMode) return false;
 
-         if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
 
-         if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0) {
 
-             ModalView m = ModalView.Show();
 
-             string pName = Application.productName;
 
-             m.textKey = "Model_Location-Prominent";
 
-             m.onAgreeTextKey = "common_next";
 
-             m.onRejectTextKey = "common_cancel";
 
-             m.textFormatArgs = new object[] {pName};
 
-             m.onAgree = () => {
 
-                 PlayerPrefs.SetInt("Location-Prominent", 1);
 
-                 try { 
 
-                     onAgree?.Invoke(); 
 
-                 } catch (System.Exception e) { 
 
-                     Debug.LogError(e.Message + "\n" + e.StackTrace); 
 
-                 } 
 
-             };
 
-             return true;
 
-         }
 
-         return false;
 
-     }
 
-     public static bool ShowProminentBeforeConnectBLE_Event(Action onAgree = null,Action onReject = null)
 
-     {
 
-         if (CommonConfig.StandaloneMode) return false;
 
-         if (SceneManager.GetActiveScene().name.Equals("HeartRateBand")) return false;
 
-         if (PlayerPrefs.GetInt("Location-Prominent", 0) == 0)
 
-         {
 
-             ModalView m = ModalView.Show();
 
-             string pName = Application.productName;
 
-             m.textKey = "Model_Location-Prominent";
 
-             m.onAgreeTextKey = "common_next";
 
-             m.onRejectTextKey = "common_cancel";
 
-             m.textFormatArgs = new object[] { pName };
 
-             m.onAgree = () => {
 
-                 PlayerPrefs.SetInt("Location-Prominent", 1);
 
-                 try
 
-                 {
 
-                     onAgree?.Invoke();
 
-                 }
 
-                 catch (System.Exception e)
 
-                 {
 
-                     Debug.LogError(e.Message + "\n" + e.StackTrace);
 
-                 }
 
-             };
 
-             m.onReject = () =>
 
-             {
 
-                 try
 
-                 {
 
-                     onReject?.Invoke();
 
-                 }
 
-                 catch (System.Exception e)
 
-                 {
 
-                     Debug.LogError(e.Message + "\n" + e.StackTrace);
 
-                 }
 
-             };
 
-             return true;
 
-         }
 
-         return false;
 
-     }
 
-     public void OnClick_ConnectBLE() {
 
-         if (ShowProminentBeforeConnectBLE()) return;
 
-         BluetoothAim.ins.DoConnect();
 
-     }
 
-     public void OnClick_ShowDeviceView() {
 
-         AudioMgr.ins.PlayBtn();
 
-         ViewMgr.Instance.ShowView<DeviceViewInfrared>();
 
-     }
 
-     public void RenderNameOrGender() {
 
-         nickNameText.text = LoginMgr.myUserInfo.nickname;
 
-         genders[LoginMgr.myUserInfo.gender == 2 ? 1 : 0].SetActive(true);
 
-         genders[LoginMgr.myUserInfo.gender == 2 ? 0 : 1].SetActive(false);
 
-         LayoutRebuilder.ForceRebuildLayoutImmediate(nickNameText.transform.parent.GetComponent<RectTransform>());
 
-     }
 
-     public void RenderMyAvatarSprite() {
 
-         RoleMgr.SetAvatarToImage(myAvatarSprite, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl);
 
-     }
 
-     public void RenderDeviceNames()
 
-     {
 
-         try {
 
-             (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo();
 
-             // this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(bowInfo.config.name);
 
-             this.transform.Find("ShowBow/Text").GetComponent<TextAutoLanguage>().SetText(200000);
 
-             this.transform.Find("ShowArrow/Text").GetComponent<TextAutoLanguage>().SetText(arrowInfo.config.name);
 
-         } catch (System.Exception) {}
 
-     }
 
-     public Action action_OnClickStartGame;
 
-     public void GoTo(string target) {
 
-         AudioMgr.ins.PlayBtn();
 
-         switch (target)
 
-         {
 
-             case "开始游戏":
 
- #if !UNITY_EDITOR
 
-                 if ((CommonConfig.isReleaseVersion || CommonConfig.StandaloneMode) && !BluetoothStatus.IsAllConnected())
 
-                 {
 
-                     PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
 
-                     return;
 
-                 }
 
- #endif
 
-                 ViewMgr.Instance.ShowView<GameStartView>();
 
-                 action_OnClickStartGame?.Invoke();
 
-                 break;
 
-             case "联机游戏":
 
-                 if (CommonConfig.isReleaseVersion && !BluetoothStatus.IsAllConnected()) {
 
-                     PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请先连接设备"));
 
-                     return;
 
-                 }
 
-                 GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
 
-                 ViewMgr.Instance.ShowView<PKGameOptionView>();
 
-                 break;
 
-             case "我的":
 
-                 //ViewMgr.Instance.ShowView<MeView>();
 
-                 if (!CommonConfig.StandaloneMode)
 
-                     ViewManager2.ShowView(ViewManager2.Path_PersonalView);
 
-                 break;
 
-             default:
 
-                 break;
 
-         }
 
-     }
 
-     /* FriendBar */
 
-     GameObject friendItemPrefab = null;
 
-     Transform friendBarContent = null;
 
-     IEnumerator RefreshFriendBar() {
 
-         if (friendItemPrefab == null) {
 
-             friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
 
-             Destroy(friendItemPrefab.GetComponent<Image>());
 
-             friendItemPrefab.SetActive(false);
 
-         }
 
-         if (friendBarContent == null) {
 
-             friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
 
-         }
 
-         while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
 
-             yield return null;
 
-         }
 
-         Action<JArray> cb = RenderFriendList;
 
-         UserPlayer.ins.call("friendComp.getMyFriends", null, cb);
 
-     }
 
-     public void RenderFriendList(JArray list) {
 
-         if (flag_SwapFriendAndRank != 0) return;
 
-         for (int i = 1; i < friendBarContent.childCount; i++) {
 
-             Destroy(friendBarContent.GetChild(i).gameObject);
 
-         }
 
-         if (list.Count > 0) {
 
-             Color outColor;
 
-             foreach (var itemInfo in list) {
 
-                 int friendID = itemInfo.Value<int>("friendID");
 
-                 int avatarID = itemInfo.Value<int>("avatarID");
 
-                 string avatarUrl = itemInfo.Value<string>("avatarUrl");
 
-                 string nickname = itemInfo.Value<string>("nickname");
 
-                 bool online = itemInfo.Value<bool>("online");
 
-                 long offlineTime = itemInfo.Value<long>("offlineTime");
 
-                 GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
 
-                 o.SetActive(true);
 
-                 o.name = friendID.ToString();
 
-                 Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
 
-                 RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
 
-                 o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
 
-                 TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
 
-                 TimeUtil.SetOfflineTimeTextKey(offlineTime, online, timeTip);
 
-                 if (online) {
 
-                     ColorUtility.TryParseHtmlString("#12B525", out outColor);
 
-                 } else {
 
-                     ColorUtility.TryParseHtmlString("#A8B2BD", out outColor);
 
-                 }
 
-                 timeTip.GetComponent<Text>().color = outColor;
 
-             }
 
-         }
 
-     }
 
-     IEnumerator RefreshFriendRankBar() {
 
-         if (friendItemPrefab == null) {
 
-             friendItemPrefab = transform.Find("FriendBar/Scroll View/Viewport/Content/Item").gameObject;
 
-             Destroy(friendItemPrefab.GetComponent<Image>());
 
-             friendItemPrefab.SetActive(false);
 
-         }
 
-         if (friendBarContent == null) {
 
-             friendBarContent = transform.Find("FriendBar/Scroll View/Viewport/Content");
 
-         }
 
-         while (UserPlayer.ins == null || !UserPlayer.ins.loginAuthed || !UserPlayer.ins.hasGetUserInfo) {
 
-             yield return null;
 
-         }
 
-         Action<JArray> cb = RenderFriendRankList;
 
-         UserPlayer.ins.call("rankComp.getFriendRankList", null, cb);
 
-     }
 
-     void RenderFriendRankList(JArray list) {
 
-         if (flag_SwapFriendAndRank != 1) return;
 
-         for (int i = 1; i < friendBarContent.childCount; i++) {
 
-             Destroy(friendBarContent.GetChild(i).gameObject);
 
-         }
 
-         if (list.Count > 0) {
 
-             foreach (var itemInfo in list) {
 
-                 int userID = itemInfo.Value<int>("id");
 
-                 int avatarID = itemInfo.Value<int>("avatarID");
 
-                 string avatarUrl = itemInfo.Value<string>("avatarUrl");
 
-                 string nickname = itemInfo.Value<string>("nickname");
 
-                 bool online = itemInfo.Value<bool>("online");
 
-                 long offlineTime = itemInfo.Value<long>("offlineTime");
 
-                 int rankNum = itemInfo.Value<int>("rankNum");
 
-                 GameObject o = GameObject.Instantiate(friendItemPrefab, friendBarContent);
 
-                 o.SetActive(true);
 
-                 o.name = userID.ToString();
 
-                 Image avatarImage = o.transform.Find("Avatar").GetComponent<Image>();
 
-                 RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
 
-                 o.transform.Find("Nickname").GetComponent<Text>().text = nickname;
 
-                 TextAutoLanguage2 timeTip = o.transform.Find("Avatar/Line/Text").GetComponent<TextAutoLanguage2>();
 
-                 Action<Text> onApplyToNext = (t) => {
 
-                     if (TextAutoLanguage2.GetLanguage() == 0) {
 
-                         t.text = $"第{rankNum}名";
 
-                     } else {
 
-                         string str = rankNum.ToString();
 
-                         if (str.EndsWith("1")) t.text = $"{rankNum}st";
 
-                         else if (str.EndsWith("2")) t.text = $"{rankNum}nd";
 
-                         else if (str.EndsWith("3")) t.text = $"{rankNum}rd";
 
-                         else t.text = $"{rankNum}th";
 
-                     }
 
-                     Color outColor;
 
-                     if (rankNum == 1) ColorUtility.TryParseHtmlString("#F0E68C", out outColor);   
 
-                     else if (rankNum == 2) ColorUtility.TryParseHtmlString("#E0FFFF", out outColor);    
 
-                     else if (rankNum == 3) ColorUtility.TryParseHtmlString("#CD8162", out outColor);      
 
-                     else ColorUtility.TryParseHtmlString("#EEE5DE", out outColor);
 
-                     t.color = outColor;
 
-                 };
 
-                 timeTip.onApplyToNext += onApplyToNext;
 
-             }
 
-         }
 
-     }
 
-     int flag_SwapFriendAndRank = 0;
 
-     public void OnClick_SwapFriendAndRank() {
 
-         AudioMgr.ins.PlayBtn();
 
-         if (flag_SwapFriendAndRank == 0) {
 
-             flag_SwapFriendAndRank = 1;
 
-             transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("rank_title");
 
-         } else if (flag_SwapFriendAndRank == 1) {
 
-             flag_SwapFriendAndRank = 0;
 
-             transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("friend_title");
 
-         }
 
-         RefreshFriendBarAccordingCurrentBar();
 
-     }
 
-     //根据栏目类型,调用对应的接口请求
 
-     public void RefreshFriendBarAccordingCurrentBar()
 
-     {
 
-         if (flag_SwapFriendAndRank == 0)
 
-             StartCoroutine(RefreshFriendBar());
 
-         else if (flag_SwapFriendAndRank == 1)
 
-             StartCoroutine(RefreshFriendRankBar());
 
-     }
 
-     public void OnClick_ShowDetail() {
 
-         AudioMgr.ins.PlayBtn();
 
-         if (flag_SwapFriendAndRank == 0) {
 
-             ViewMgr.Instance.ShowView<FriendView>();
 
-         } else if (flag_SwapFriendAndRank == 1) {
 
-             ViewMgr.Instance.ShowView<RankView>();
 
-         }
 
-     }   
 
-     //检测是否需要提示有人加我好友
 
-     bool _old_hasFriendRequest = false;
 
-     int _old_flag_SwapFriendAndRank = 0;
 
-     void UpdateCheckRenderFriendTip()
 
-     {
 
-         if (UserPlayer.ins == null) return;
 
-         if (
 
-             UserPlayer.ins.tempData.hasFriendRequest == _old_hasFriendRequest &&
 
-             flag_SwapFriendAndRank == _old_flag_SwapFriendAndRank
 
-         ) return;
 
-         _old_hasFriendRequest = UserPlayer.ins.tempData.hasFriendRequest;
 
-         _old_flag_SwapFriendAndRank = flag_SwapFriendAndRank;
 
-         friendBarTipTop.SetActive(
 
-             flag_SwapFriendAndRank == 1 &&
 
-             UserPlayer.ins.tempData.hasFriendRequest);
 
-         friendBarTipBottom.SetActive(
 
-             flag_SwapFriendAndRank == 0 &&
 
-             UserPlayer.ins.tempData.hasFriendRequest);
 
-     }
 
-     public void RenderBattery(int deviceID, int value)
 
-     {
 
-         Image img = betteryBar.GetComponent<Image>();
 
-         img.fillAmount = value / 100f;
 
-     }
 
-     public void RenderBattery2() {
 
-         int value = BluetoothAim.ins.get2PBattery();
 
-         Image img = betteryBar2.GetComponent<Image>();
 
-         img.fillAmount = value / 100f;
 
-     }
 
-     public void UpdateParent() {
 
-         TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
 
-         if (bettery != null)
 
-         {
 
-             bettery.transform.SetParent(topBarButtonInfo.container.transform);
 
-         }
 
-         if (bettery2 != null)
 
-         {
 
-             bettery2.transform.SetParent(topBarButtonInfo.container.transform);
 
-         }
 
-     }
 
-     void updateBatteryStatus() {
 
-         if (BluetoothAim.ins == null) return;
 
-         //更新电池图标显示
 
-         if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
 
-         {
 
-             if (!bettery.activeSelf)
 
-             {
 
-                 TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();  
 
-                 bettery.transform.SetParent(topBarButtonInfo.container.transform);
 
-                 bettery.SetActive(true);
 
-             }
 
-         }
 
-         else
 
-         {
 
-             if (bettery.activeSelf)
 
-             {
 
-                 bettery.SetActive(false);
 
-             }
 
-         }
 
-         //更新设备2电池图标显示
 
-         if (BluetoothAim.ins.getSmartBowHelper2P() != null &&
 
-             BluetoothAim.ins.getSmartBowHelper2P().GetBluetoothStatus() == SmartBowSDK.BluetoothStatusEnum.Connected)
 
-         {
 
-             if (!bettery2.activeSelf)
 
-             {
 
-                 TopBarButtonInfo topBarButtonInfo = topBarView.GetCurrentTopBarButtonInfo();
 
-                 bettery2.transform.SetParent(topBarButtonInfo.container.transform);
 
-                 bettery2.SetActive(true);
 
-             }
 
-         }
 
-         else
 
-         {
 
-             if (bettery2.activeSelf)
 
-             {
 
-                 bettery2.SetActive(false);
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |