using asap.core; using GameCore; using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace game { public class SocialClubPlayerTips : BasePanel { BFriendInfo m_FriendInfo; #region UI public Button ButtonClose; public RectTransform tips_root; public TMP_Text text_name; public TMP_Text grade_text_num; public GameObject icon_skyscraper; public TMP_Text skyscraper_text_num; public GameObject btn_add_root; public Button btn_add; public GameObject btn_add_gray_root; public Button btn_add_gray; public void SetData(Transform dockTransform, Vector2 offset, BFriendInfo friendInfo) { if (dockTransform == null || friendInfo == null) return; m_FriendInfo = friendInfo; tips_root.position = dockTransform.position + new Vector3(offset.x, offset.y, 0); if (text_name != null) { if (string.IsNullOrEmpty(m_FriendInfo.DisplayName)) { text_name.text = GContext.container.Resolve().GetDefaultName(m_FriendInfo.PlayFabId); } else { text_name.text = m_FriendInfo.DisplayName; } } //int level = friendInfo.Level / LeadboardData.LV_MODELING; //int infiniteBuildingLevel = friendInfo.Level % LeadboardData.LV_MODELING; //if (grade_text_num != null) //{ // grade_text_num.text = "" + level; //} //if (infiniteBuildingLevel > 0) //{ // icon_skyscraper.SetActive(true); // skyscraper_text_num.text = "" + infiniteBuildingLevel; //} //else //{ // icon_skyscraper.SetActive(false); //} IUserService userService = GContext.container.Resolve(); if (userService != null && userService.UserId.Equals(m_FriendInfo.PlayFabId)) { btn_add_root.SetActive(false); btn_add_gray_root.SetActive(false); icon_skyscraper.SetActive(false); if (grade_text_num != null) { grade_text_num.text = "" + GContext.container.Resolve().lv; } this.gameObject.SetActive(true); } else { btn_add_root.SetActive(false); btn_add_gray_root.SetActive(false); bool isFriend = GContext.container.Resolve().IsFriend(m_FriendInfo.PlayFabId); if (isFriend) { this.gameObject.SetActive(true); } else { IsFriendWaitingForAccept(); } SetLv(m_FriendInfo.PlayFabId); } tips_root.gameObject.SetActive(true); } private async void IsFriendWaitingForAccept() { if (m_FriendInfo == null || string.IsNullOrEmpty(m_FriendInfo.PlayFabId)) return; try { string json = await GContext.container.Resolve().IsFriendWaitingForAccept(GContext.container.Resolve().UserId, m_FriendInfo.PlayFabId); if (string.IsNullOrEmpty(json)) return; IsFriendWaitingForAcceptResp resp = Newtonsoft.Json.JsonConvert.DeserializeObject(json); if (resp == null) return; this.gameObject.SetActive(true); if (resp.Code > 0) { btn_add_root.SetActive(false); btn_add_gray_root.SetActive(true); } else { btn_add_root.SetActive(true); btn_add_gray_root.SetActive(false); } } catch (Exception ex) { string msg = "[SocialClubPlayerTips] IsFriendWaitingForAccept encountered a fatal problem."; Debug.LogError($"{msg}-{ex.Message} \r\n {ex.StackTrace}"); btn_add_root.SetActive(false); btn_add_gray_root.SetActive(false); } } public async void SetLv(string playFabId) { icon_skyscraper.SetActive(false); var (playId, lv) = await GContext.container.Resolve().GetPlayLv(playFabId); if (grade_text_num != null) { grade_text_num.text = "" + lv; } //if (infiniteBuildingLevel > 0) //{ // icon_skyscraper.SetActive(true); // skyscraper_text_num.text = "" + infiniteBuildingLevel; //} //else //{ // icon_skyscraper.SetActive(false); //} } #endregion #region 生命周期 protected override void Start() { base.Start(); if (ButtonClose != null) { ButtonClose.onClick.RemoveAllListeners(); ButtonClose.onClick.AddListener(OnBtnCloseClickListener); } if (btn_add != null) { btn_add.onClick.RemoveAllListeners(); btn_add.onClick.AddListener(OnBtnAddClickListener); } if (btn_add_gray != null) { btn_add_gray.onClick.RemoveAllListeners(); btn_add_gray.onClick.AddListener(OnBtnAddGrayClickListener); } tips_root.gameObject.SetActive(false); this.gameObject.SetActive(false); } private void OnBtnAddGrayClickListener() { ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_98")); UIManager.Instance.DestroyUI(UITypes.SocialClubPlayerTips); } private void OnBtnAddClickListener() { if (m_FriendInfo == null) return; btn_add_root.SetActive(false); btn_add_gray_root.SetActive(true); GContext.container.Resolve().StartInvite(m_FriendInfo.PlayFabId); UIManager.Instance.DestroyUI(UITypes.SocialClubPlayerTips); } private void OnBtnCloseClickListener() { UIManager.Instance.DestroyUI(UITypes.SocialClubPlayerTips); } #endregion } }