|
|
@@ -145,6 +145,7 @@ public class HomeView : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
public void RenderFriendList(JArray list) {
|
|
|
+ if (flag_SwapFriendAndRank != 0) return;
|
|
|
for (int i = 1; i < friendBarContent.childCount; i++) {
|
|
|
Destroy(friendBarContent.GetChild(i).gameObject);
|
|
|
}
|
|
|
@@ -173,15 +174,74 @@ public class HomeView : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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 (LoginMgr.myUserInfo.id < 1) {
|
|
|
+ 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 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();
|
|
|
+ o.transform.Find("Avatar").GetComponent<Image>().sprite = RoleMgr.GetAvatar(avatarID);
|
|
|
+ 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");
|
|
|
+ StartCoroutine(RefreshFriendRankBar());
|
|
|
} else if (flag_SwapFriendAndRank == 1) {
|
|
|
flag_SwapFriendAndRank = 0;
|
|
|
transform.Find("FriendBar/FrameBtnTop").GetComponentInChildren<TextAutoLanguage2>().SetTextKey("friend_title");
|
|
|
+ StartCoroutine(RefreshFriendBar());
|
|
|
}
|
|
|
}
|
|
|
|