备份CatanBuilding瘦身独立工程
This commit is contained in:
198
Assets/Scripts/UI/Social/SocialInfoItem.cs
Normal file
198
Assets/Scripts/UI/Social/SocialInfoItem.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class SocialInfoItem : PanelItemBase<SocialInfoItemData>
|
||||
{
|
||||
public GameObject bg_myself;
|
||||
List<GameObject> rank = new List<GameObject>();
|
||||
public TMP_Text text_rank;
|
||||
public TMP_Text text_name;
|
||||
public TMP_Text text_time;
|
||||
public Head head;
|
||||
public Button btn_more;
|
||||
GameObject icon_leader1;
|
||||
GameObject icon_leader2;
|
||||
GameObject icon_leader3;
|
||||
public TMP_Text text_count;
|
||||
public Button btn_head;
|
||||
public Transform tips_dock_trans;
|
||||
public Vector2 tips_dock_offset = Vector2.zero;
|
||||
string playFabId;
|
||||
IDisposable disposable;
|
||||
private void Awake()
|
||||
{
|
||||
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
|
||||
bg_myself = transform.Find("bg_myself").gameObject;
|
||||
text_rank = transform.Find("rank/rank/text_rank").GetComponent<TMP_Text>();
|
||||
text_name = transform.Find("text_name").GetComponent<TMP_Text>();
|
||||
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
||||
head = transform.Find("btn_head").GetComponent<Head>();
|
||||
icon_leader1 = transform.Find("btn_head/leader_1").gameObject;
|
||||
icon_leader2 = transform.Find("btn_head/leader_2").gameObject;
|
||||
icon_leader3 = transform.Find("btn_head/leader_3").gameObject;
|
||||
btn_more = transform.Find("btn_more").GetComponent<Button>();
|
||||
btn_more.onClick.AddListener(OnBtnItem);
|
||||
//reward_panel = transform.Find("reward_panel").gameObject;
|
||||
text_count = transform.Find("icon_rank/text_num").GetComponent<TMP_Text>();
|
||||
Transform rank_panel = transform.Find("rank");
|
||||
for (int i = 0; i < rank_panel.childCount; i++)
|
||||
{
|
||||
rank.Add(rank_panel.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
btn_head = transform.Find("btn_head").GetComponent<Button>();
|
||||
if (btn_head != null)
|
||||
{
|
||||
btn_head.onClick.RemoveAllListeners();
|
||||
btn_head.onClick.AddListener(OnBtnHeadClickListener);
|
||||
}
|
||||
}
|
||||
public async void OnBtnHeadClickListener()
|
||||
{
|
||||
if (data == null || !GContext.container.Resolve<ClubService>().IsClubJoined()) return;
|
||||
|
||||
var clubInfoPopupPanelNode = UIManager.Instance.GetContainedUI(UITypes.ClubInfoPopupPanel);
|
||||
if (clubInfoPopupPanelNode == null) return;
|
||||
|
||||
var clubInfoPopupPanel = clubInfoPopupPanelNode.GetComponent<ClubInfoPopupPanel>();
|
||||
if (clubInfoPopupPanel == null) return;
|
||||
|
||||
IUserService userService = GContext.container.Resolve<IUserService>();
|
||||
bool isInClub = clubInfoPopupPanel.IsInClub(userService.UserId);
|
||||
if (!isInClub) return;
|
||||
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.SocialClubPlayerTips);
|
||||
if (go == null) return;
|
||||
|
||||
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
||||
if (clubPlayInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BFriendInfo friendInfo = new BFriendInfo()
|
||||
{
|
||||
PlayFabId = data.playFabId,
|
||||
DisplayName = clubPlayInfo.name,
|
||||
AvatarUrl = clubPlayInfo.avatarUrl,
|
||||
Level = data.lv
|
||||
};
|
||||
|
||||
SocialClubPlayerTips tips = go.GetComponent<SocialClubPlayerTips>();
|
||||
tips.SetData(tips_dock_trans, tips_dock_offset, friendInfo);
|
||||
}
|
||||
string ConvertTime2(int d, int h, int m, int s)
|
||||
{
|
||||
if (d > 0)
|
||||
{
|
||||
return $"{d}d";
|
||||
}
|
||||
if (h > 0)
|
||||
{
|
||||
return $"{h}h";
|
||||
}
|
||||
if (m > 0)
|
||||
{
|
||||
return $"{m}m";
|
||||
}
|
||||
return $"{s}s";
|
||||
}
|
||||
public override void OnInit()
|
||||
{
|
||||
IUserService userService = GContext.container.Resolve<IUserService>();
|
||||
playFabId = data.playFabId;
|
||||
bg_myself.SetActive(data.playFabId == userService.UserId);
|
||||
icon_leader1.SetActive(data.role == EMemberRole.Elder);
|
||||
icon_leader2.SetActive(data.role == EMemberRole.Vice);
|
||||
icon_leader3.SetActive(data.role == EMemberRole.Owner);
|
||||
btn_more.gameObject.SetActive(data.showMore);
|
||||
if (data.isOnline)
|
||||
{
|
||||
text_time.text = LocalizationMgr.GetText("UI_FishingSocialPanel_32");
|
||||
}
|
||||
else
|
||||
{
|
||||
int ClubMaxRecentActiveTime = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubMaxRecentActiveTime;
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow();
|
||||
var now = dateTime - data.lastLoginTime;
|
||||
int days = now.Days;
|
||||
if (days >= ClubMaxRecentActiveTime)
|
||||
{
|
||||
days = ClubMaxRecentActiveTime;
|
||||
}
|
||||
text_time.text = LocalizationMgr.GetFormatTextValue("UI_FishingSocialPanel_33",
|
||||
ConvertTime2(days, now.Hours, now.Minutes, now.Seconds));
|
||||
}
|
||||
for (int i = 0; i < rank.Count - 1; i++)
|
||||
{
|
||||
rank[i].SetActive(data.rank == i + 1);
|
||||
}
|
||||
rank[^1].SetActive(data.rank >= rank.Count);
|
||||
text_rank.text = data.rank.ToString();
|
||||
if (data.playFabId == userService.UserId)
|
||||
{
|
||||
text_name.text = userService.DisplayName;
|
||||
head.SetData(userService.AvatarUrl);
|
||||
text_count.text = GContext.container.Resolve<PlayerData>().lv.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
text_count.text = data.lv.ToString();
|
||||
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
||||
if (clubPlayInfo != null)
|
||||
{
|
||||
text_name.text = clubPlayInfo.name;
|
||||
head.SetData(clubPlayInfo.avatarUrl);
|
||||
}
|
||||
if (data.lv <= 1)
|
||||
{
|
||||
SetLv(data, userService);
|
||||
}
|
||||
}
|
||||
}
|
||||
async void SetLv(SocialInfoItemData curData, IUserService userService)
|
||||
{
|
||||
var (playId, lv) = await userService.GetPlayLv(playFabId);
|
||||
curData.lv = lv;
|
||||
if (playId == playFabId)
|
||||
{
|
||||
text_count.text = lv.ToString();
|
||||
}
|
||||
}
|
||||
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
|
||||
{
|
||||
if (getClubPlayInfoEvent.id == playFabId)
|
||||
{
|
||||
text_name.text = getClubPlayInfoEvent.name;
|
||||
head.SetData(getClubPlayInfoEvent.avatarUrl);
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
public class SocialInfoItemData
|
||||
{
|
||||
public int rank;
|
||||
public int lv = 1;
|
||||
//public string entityKey;
|
||||
public string playFabId;
|
||||
public string displayName;
|
||||
public string avatarUrl;
|
||||
public bool isOnline;
|
||||
public EMemberRole role;
|
||||
public bool showMore;
|
||||
//最后登录时间
|
||||
public DateTime lastLoginTime;
|
||||
}
|
||||
Reference in New Issue
Block a user