157 lines
4.9 KiB
C#
157 lines
4.9 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ClubApplyPopupPanel : MonoBehaviour
|
|
{
|
|
public Button btn_mask;
|
|
public Button btn_close;
|
|
public Button btn_ignore;
|
|
public Transform content;
|
|
public GameObject contentPrefab;
|
|
GameObject emply;
|
|
bool isHas = false;
|
|
private void Awake()
|
|
{
|
|
btn_mask = transform.Find("mask").GetComponent<Button>();
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_ignore = transform.Find("root/btn_ignore/btn_green").GetComponent<Button>();
|
|
content = transform.Find("root/ScrollView/Viewport/Content");
|
|
contentPrefab = transform.Find("root/ScrollView/Viewport/Content/Item").gameObject;
|
|
emply = transform.Find("root/text_emply").gameObject;
|
|
}
|
|
|
|
private void OnStart()
|
|
{
|
|
var datas = GContext.container.Resolve<ClubService>().clubPlayerInfos;
|
|
if (datas != null && datas.Count > 0)
|
|
{
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
for (int i = 0; i < datas.Count; i++)
|
|
{
|
|
SocialInfoItemData clubPlayerInfoData = datas[i];
|
|
GameObject go = Instantiate(contentPrefab, content);
|
|
go.SetActive(true);
|
|
ApplyItem applyItem = go.AddComponent<ApplyItem>();
|
|
applyItem.SetData(clubPlayerInfoData);
|
|
}
|
|
isHas = true;
|
|
}
|
|
emply.SetActive(datas == null || datas.Count == 0);
|
|
//btn_ignore.gameObject.SetActive(datas != null && datas.Count > 0);
|
|
}
|
|
public void Start()
|
|
{
|
|
OnStart();
|
|
btn_mask.onClick.AddListener(OnClose);
|
|
btn_close.onClick.AddListener(OnClose);
|
|
btn_ignore.onClick.AddListener(() =>
|
|
{
|
|
if (isHas)
|
|
{
|
|
GContext.container.Resolve<ClubService>().HandleApply(false, "");
|
|
}
|
|
OnClose();
|
|
});
|
|
}
|
|
private void OnClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.ClubApplyPopupPanel);
|
|
}
|
|
|
|
}
|
|
class ApplyItem : MonoBehaviour
|
|
{
|
|
TMP_Text text_name;
|
|
Head head;
|
|
TMP_Text text_count;
|
|
Button btn_accept;
|
|
Button btn_ignore;
|
|
string playFabId;
|
|
//string entityKey;
|
|
SocialInfoItemData data;
|
|
IDisposable disposable;
|
|
private void Awake()
|
|
{
|
|
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
|
|
text_name = transform.Find("text_name").GetComponent<TMP_Text>();
|
|
head = transform.Find("btn_head").GetComponent<Head>();
|
|
text_count = transform.Find("icon_rank/text_num").GetComponent<TMP_Text>();
|
|
btn_accept = transform.Find("btn_accept").GetComponent<Button>();
|
|
btn_ignore = transform.Find("btn_ignore").GetComponent<Button>();
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_accept.onClick.AddListener(OnAccept);
|
|
btn_ignore.onClick.AddListener(OnIgnore);
|
|
}
|
|
public void SetData(SocialInfoItemData data)
|
|
{
|
|
this.data = data;
|
|
playFabId = data.playFabId;
|
|
//entityKey = data.entityKey;
|
|
//head.SetData(data.avatarUrl);
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
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;
|
|
}
|
|
void OnAccept()
|
|
{
|
|
//同意
|
|
GContext.container.Resolve<ClubService>().HandleApply(true, playFabId);
|
|
Destroy(gameObject);
|
|
}
|
|
void OnIgnore()
|
|
{
|
|
//忽略
|
|
GContext.container.Resolve<ClubService>().HandleApply(false, playFabId);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|