Files
back_cantanBuilding/Assets/Scripts/UI/Social/ClubInfoPopupPanel.cs
2026-05-26 16:15:54 +08:00

311 lines
13 KiB
C#

using asap.core;
using game;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
using System.Linq;
public class ClubInfoPopupPanel : MonoBehaviour
{
ClubService _socialData;
Button btn_close;
Button btn_mask;
Button btn_apply;
Button btn_apply_gray;
TMP_Text text_name;
TMP_Text text_desc;
TMP_Text text_country;
TMP_Text text_type;
TMP_Text text_required;
ClubHead icon_club;
TMP_Text text_people_num;
TMP_Text text_club_trophy;
GameObject item;
PanelScroll scrollRect;
GameObject club_info;
GameObject club_apply;
GameObject item_apply;
PanelScroll scrollRect_apply;
GameObject more_tips;
Button more_buttonClose;
Button btn_demote;
Button btn_promote;
Button btn_leave;
Button btn_kickout;
float itemHigh;
List<SocialInfoItemData> data;
SocialInfoItemData curSocialInfoItemData;
int dataCount;
bool isEnable = true;
private void Awake()
{
_socialData = GContext.container.Resolve<ClubService>();
btn_close = transform.Find("btn_close").GetComponent<Button>();
btn_mask = transform.Find("mask").GetComponent<Button>();
btn_apply = transform.Find("root/club_apply/btn_apply/btn_green").GetComponent<Button>();
btn_apply_gray = transform.Find("root/club_apply/btn_apply_gray/btn_green").GetComponent<Button>();
text_name = transform.Find("root/text_title").GetComponent<TMP_Text>();
text_desc = transform.Find("root/description/text").GetComponent<TMP_Text>();
text_country = transform.Find("root/head/country/text").GetComponent<TMP_Text>();
text_type = transform.Find("root/head/type/text").GetComponent<TMP_Text>();
text_required = transform.Find("root/head/required/text").GetComponent<TMP_Text>();
icon_club = transform.Find("root/head/btn_head").GetComponent<ClubHead>();
text_people_num = transform.Find("root/info/text_people_num").GetComponent<TMP_Text>();
text_club_trophy = transform.Find("root/info/text_club_trophy").GetComponent<TMP_Text>();
club_info = transform.Find("root/club_info").gameObject;
club_apply = transform.Find("root/club_apply").gameObject;
item = transform.Find("root/club_info/ScrollView/Viewport/Content/Item").gameObject;
item_apply = transform.Find("root/club_apply/ScrollView/Viewport/Content/Item").gameObject;
scrollRect = transform.Find("root/club_info/ScrollView").GetComponent<PanelScroll>();
scrollRect_apply = transform.Find("root/club_apply/ScrollView").GetComponent<PanelScroll>();
more_tips = transform.Find("root/more_tips").gameObject;
more_buttonClose = transform.Find("root/more_tips/ButtonClose").GetComponent<Button>();
btn_demote = transform.Find("root/more_tips/bg/btn_demote/btn_green_c").GetComponent<Button>();
btn_promote = transform.Find("root/more_tips/bg/btn_promote/btn_green_c").GetComponent<Button>();
btn_leave = transform.Find("root/more_tips/bg/btn_leave/btn_green_c").GetComponent<Button>();
btn_kickout = transform.Find("root/more_tips/bg/btn_kickout/btn_green_c").GetComponent<Button>();
GContext.OnEvent<ClubStateChangeEvent>().Subscribe(OnChangeJoinedState).AddTo(this);
}
private async void Start()
{
more_buttonClose.onClick.AddListener(() =>
{
more_tips.SetActive(false);
});
btn_leave.onClick.AddListener(OnClickLeave);
btn_kickout.onClick.AddListener(OnClickKickout);
btn_demote.onClick.AddListener(OnClickDemote);
btn_promote.onClick.AddListener(OnClickPromote);
btn_close.onClick.AddListener(Close);
btn_mask.onClick.AddListener(Close);
btn_apply.onClick.AddListener(OnClickApply);
btn_apply_gray.onClick.AddListener(() => ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_44")));
scrollRect.loop = false;
itemHigh = item.GetComponent<RectTransform>().sizeDelta.y;
item.SetActive(false);
item_apply.SetActive(false);
text_name.text = _socialData.ClubItemData.name;
bool descNull = string.IsNullOrEmpty(_socialData.ClubItemData.desc);
text_desc.text = descNull ? LocalizationMgr.GetText("UI_FishingSocialPanel_27") : _socialData.ClubItemData.desc;//
text_type.text = LocalizationMgr.GetText(_socialData.ClubItemData.type.ToString());
text_required.text = _socialData.ClubItemData.required.ToString();
text_people_num.text = $"{_socialData.ClubItemData.memberCount}/{_socialData.ClubItemData.memberLimit}";
text_club_trophy.text = _socialData.ClubItemData.trophy.ToString();
icon_club.SetData(_socialData.ClubItemData.icon);
bool joined = _socialData.IsClubJoined();
club_info.SetActive(joined);
club_apply.SetActive(!joined);
btn_apply.gameObject.SetActive(false);
btn_apply_gray.gameObject.SetActive(false);
data = await _socialData.GetClubDetails(_socialData.ClubItemData.id, !joined);
if (isEnable)
{
ShowPanel();
}
}
void ShowPanel()
{
bool joined = _socialData.IsClubJoined();
if (!joined)
{
btn_apply.gameObject.SetActive(!_socialData.ApplyState);
btn_apply_gray.gameObject.SetActive(_socialData.ApplyState);
}
if (data == null || data.Count == 0)
{
return;
}
bool showMore = joined && _socialData.CanAccepted && _socialData.ClubItemData.id == _socialData.myClubInfo.id;
IUserService userService = GContext.container.Resolve<IUserService>();
for (int i = 0; i < data.Count; i++)
{
bool isMore = showMore;
if (data[i].playFabId != userService.UserId)
{
if (_socialData.memberRole == EMemberRole.Vice)
{
isMore &= data[i].role == EMemberRole.Elder || data[i].role == EMemberRole.Member;
}
else if (_socialData.memberRole == EMemberRole.Elder)
{
isMore &= data[i].role == EMemberRole.Member;
}
}
data[i].showMore = isMore;
data[i].rank = i + 1;
}
if (joined)
{
scrollRect.Init<SocialInfoItem, SocialInfoItemData>(itemHigh, item, OnClickItem, data);
}
else
{
scrollRect_apply.Init<SocialInfoItem, SocialInfoItemData>(itemHigh, item_apply, OnClickItem, data);
}
}
public bool IsInClub(string playfabID)
{
if (data == null || data.Count < 1) return false;
foreach(var item in data)
{
if (item.playFabId.Equals(playfabID))
{
return true;
}
}
return false;
}
public void OnClickItem(SocialInfoItem memberItem)
{
curSocialInfoItemData = memberItem.data;
IUserService userService = GContext.container.Resolve<IUserService>();
//TODO
more_tips.transform.position = memberItem.btn_more.transform.position;
more_tips.SetActive(true);
btn_leave.transform.parent.gameObject.SetActive(curSocialInfoItemData.playFabId == userService.UserId);
bool iskickout = curSocialInfoItemData.playFabId != userService.UserId;/*_socialData.ClubItemData.id == _socialData.myClubInfo.id*/;
bool isPromote = false;
bool isDemote = false;
EMemberRole role = curSocialInfoItemData.role;
if (_socialData.memberRole == EMemberRole.Owner)
{
isDemote |= role == EMemberRole.Vice || role == EMemberRole.Elder;
isPromote |= role == EMemberRole.Elder || role == EMemberRole.Member;
}
else if (_socialData.memberRole == EMemberRole.Vice)
{
iskickout &= role == EMemberRole.Elder || role == EMemberRole.Member;
isDemote |= role == EMemberRole.Elder;
isPromote |= role == EMemberRole.Member;
}
else if (_socialData.memberRole == EMemberRole.Elder)
{
iskickout &= role == EMemberRole.Member;
}
btn_kickout.transform.parent.gameObject.SetActive(iskickout);
btn_promote.transform.parent.gameObject.SetActive(isPromote);
btn_demote.transform.parent.gameObject.SetActive(isDemote);
}
public async void OnClickApply()
{
//申请加入
if (GContext.container.Resolve<PlayerData>().lv < _socialData.ClubItemData.required)
{
//等级不够
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_40"));
return;
}
btn_apply.gameObject.SetActive(false);
btn_apply_gray.gameObject.SetActive(true);
await _socialData.ApplyClub(_socialData.ClubItemData.id);
}
void OnChangeJoinedState(ClubStateChangeEvent stateData)
{
int state = stateData.state;
if (state == 0)
{
Close();
}
}
async void OnClickLeave()
{
await UIManager.Instance.ShowUI(UITypes.ClubQuitNoticePopupPanel);
more_tips.SetActive(false);
}
async void OnClickDemote()
{
//降职
more_tips.SetActive(false);
if (curSocialInfoItemData.role == EMemberRole.Vice || curSocialInfoItemData.role == EMemberRole.Elder)
{
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
string roleStr = "";
if (curSocialInfoItemData.role == EMemberRole.Vice)
{
roleStr = LocalizationMgr.GetText("UI_ClubInfoPopupPanel_3");
}
else if (curSocialInfoItemData.role == EMemberRole.Elder)
{
roleStr = LocalizationMgr.GetText("UI_ClubInfoPopupPanel_4");
}
IUserService userService = GContext.container.Resolve<IUserService>();
PlayInfo clubPlayInfo = userService.GetPlayInfo(curSocialInfoItemData.playFabId);
string info = LocalizationMgr.GetFormatTextValue("UI_ClubInfoPopupPanel_15", clubPlayInfo.name, roleStr);
string title = LocalizationMgr.GetText("UI_ClubInfoPopupPanel_7");
NoticeConfirmPopupPanel.Init(2, title, info, onClickRight: Demote, btn_left_text: LocalizationMgr.GetText("UI_COMMON_cancel"), btn_right_text: LocalizationMgr.GetText("UI_COMMON_confirm"));
}
}
void Demote()
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_82"));
_socialData.Demote(curSocialInfoItemData.playFabId);
curSocialInfoItemData.role = EMemberRole.Member;
scrollRect.Refresh();
}
async void OnClickPromote()
{
//升职
more_tips.SetActive(false);
if (curSocialInfoItemData.role == EMemberRole.Member || curSocialInfoItemData.role == EMemberRole.Elder)
{
GameObject go = await UIManager.Instance.ShowUI(UITypes.ClubPromotePopupPanel);
var ClubPromotePopupPanel = go.GetComponent<ClubPromotePopupPanel>();
int elderCount = data.Count((x) => x.role == EMemberRole.Elder);
int viceCount = data.Count((x) => x.role == EMemberRole.Vice);
ClubPromotePopupPanel.Init(Promote, curSocialInfoItemData, elderCount, viceCount);
}
}
void Promote(EMemberRole role)
{
if (curSocialInfoItemData.role != role)
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_82"));
_socialData.Promote(curSocialInfoItemData.playFabId, role);
curSocialInfoItemData.role = role;
scrollRect.Refresh();
}
}
async void OnClickKickout()
{
//踢出
more_tips.SetActive(false);
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
string info = LocalizationMgr.GetText("UI_FishingSocialPanel_34");
NoticeConfirmPopupPanel.Init(2,"", info, onClickRight: Kickout, btn_left_text: LocalizationMgr.GetText("UI_COMMON_cancel"), btn_right_text: LocalizationMgr.GetText("UI_COMMON_confirm"));
}
void Kickout()
{
_socialData.ClubItemData.memberCount--;
text_people_num.text = $"{_socialData.ClubItemData.memberCount}/{_socialData.ClubItemData.memberLimit}";
data.Remove(curSocialInfoItemData);
for (int i = 0; i < data.Count; i++)
{
data[i].rank = i + 1;
}
scrollRect.Init<SocialInfoItem, SocialInfoItemData>(itemHigh, item, OnClickItem, data);
_socialData.Kickout(curSocialInfoItemData.playFabId);
PlayInfo clubPlayInfo = GContext.container.Resolve<IUserService>().GetPlayInfo(curSocialInfoItemData.playFabId);
ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_73", clubPlayInfo.name));
}
void Close()
{
UIManager.Instance.DestroyUI(UITypes.ClubInfoPopupPanel);
}
private void OnDestroy()
{
isEnable = false;
}
}