113 lines
3.5 KiB
C#
113 lines
3.5 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
public class EventLeadboardItem : PanelItemBase<EventLeadboardItemData>
|
|
{
|
|
GameObject bg_myself;
|
|
List<GameObject> rank = new List<GameObject>();
|
|
TMP_Text text_rank;
|
|
TMP_Text text_name;
|
|
Head head;
|
|
Transform reward_panel;
|
|
RewardItem require_item;
|
|
RewardItemNew[] rewardItems;
|
|
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>();
|
|
head = transform.Find("btn_head").GetComponent<Head>();
|
|
reward_panel = transform.Find("reward_panel");
|
|
rewardItems = reward_panel.GetComponentsInChildren<RewardItemNew>();
|
|
require_item = transform.Find("icon_rank").GetComponent<RewardItem>();
|
|
Transform rank_panel = transform.Find("rank");
|
|
for (int i = 0; i < rank_panel.childCount; i++)
|
|
{
|
|
rank.Add(rank_panel.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
public override void OnInit()
|
|
{
|
|
if (bg_myself == null)
|
|
{
|
|
return;
|
|
}
|
|
playFabId = data.playFabId;
|
|
bg_myself.SetActive(data.isMe);
|
|
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();
|
|
require_item.SetData(data.value);
|
|
require_item.text_num.text = ConvertTools.GetNumberString2((int)data.value.count);
|
|
SetReward(data.itemDatas);
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
if (data.playFabId == userService.UserId)
|
|
{
|
|
text_name.text = userService.DisplayName;
|
|
head.SetData(userService.AvatarUrl);
|
|
}
|
|
else
|
|
{
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
|
SetAvatar(clubPlayInfo);
|
|
}
|
|
}
|
|
public void SetAvatar(PlayInfo clubPlayInfo)
|
|
{
|
|
if (clubPlayInfo != null)
|
|
{
|
|
text_name.text = clubPlayInfo.name;
|
|
head.SetData(clubPlayInfo.avatarUrl);
|
|
}
|
|
}
|
|
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 void SetReward(List<ItemData> itemDatas)
|
|
{
|
|
for (int i = 0; i < rewardItems.Length; i++)
|
|
{
|
|
if (i < itemDatas.Count)
|
|
{
|
|
rewardItems[i].gameObject.SetActive(true);
|
|
rewardItems[i].SetData(itemDatas[i]);
|
|
rewardItems[i].text_num.text = $"x{ConvertTools.GetNumberString((int)itemDatas[i].count)}";
|
|
}
|
|
else
|
|
{
|
|
rewardItems[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class EventLeadboardItemData
|
|
{
|
|
public int position;
|
|
public long rank;
|
|
public ItemData value;
|
|
public string playFabId;
|
|
public bool isMe;
|
|
public List<ItemData> itemDatas;
|
|
}
|