163 lines
5.2 KiB
C#
163 lines
5.2 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SocialClubApplication : MonoBehaviour
|
|
{
|
|
ClubService _socialData;
|
|
public TMP_InputField inputField;
|
|
public Button btn_search;
|
|
public Button btn_delete;
|
|
public Button btn_refresh;
|
|
public Button btn_create;
|
|
|
|
public GameObject empty;
|
|
public GameObject loading;
|
|
public GameObject item;
|
|
public PanelScroll scrollRect;
|
|
public TMP_Text btn_name;
|
|
float itemHigh;
|
|
List<ClubItemData> itemDatas = new List<ClubItemData>();
|
|
private void Awake()
|
|
{
|
|
_socialData = GContext.container.Resolve<ClubService>();
|
|
inputField = transform.Find("InputField_name").GetComponent<TMP_InputField>();
|
|
btn_search = transform.Find("btn_search").GetComponent<Button>();
|
|
btn_delete = transform.Find("InputField_name/Text Area/Text/btn_delete").GetComponent<Button>();
|
|
btn_refresh = transform.Find("bg_recommened/btn_refresh").GetComponent<Button>();
|
|
btn_create = transform.Find("rank/btn_enter/btn_green").GetComponent<Button>();
|
|
empty = transform.Find("rank/empty").gameObject;
|
|
loading = transform.Find("rank/loading").gameObject;
|
|
item = transform.Find("rank/Item").gameObject;
|
|
scrollRect = transform.Find("rank/ScrollView").GetComponent<PanelScroll>();
|
|
btn_name = transform.Find("rank/btn_enter/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
scrollRect.loop = false;
|
|
itemHigh = item.GetComponent<RectTransform>().sizeDelta.y;
|
|
item.SetActive(false);
|
|
btn_search.onClick.AddListener(OnSearch);
|
|
btn_delete.onClick.AddListener(OnDelete);
|
|
btn_refresh.onClick.AddListener(OnRefresh);
|
|
btn_create.onClick.AddListener(OnCreate);
|
|
inputField.onValueChanged.AddListener((str) =>
|
|
{
|
|
btn_delete.gameObject.SetActive(!string.IsNullOrEmpty(str));
|
|
});
|
|
}
|
|
void OnEnable()
|
|
{
|
|
loading.SetActive(true);
|
|
empty.SetActive(false);
|
|
scrollRect.gameObject.SetActive(false);
|
|
OnRefresh();
|
|
btn_name.text = _socialData.IsClubJoined() ? LocalizationMgr.GetText("UI_FishingSocialPanel_18") : LocalizationMgr.GetText("UI_FishingSocialPanel_17");
|
|
}
|
|
async void OnSearch()
|
|
{
|
|
string name = inputField.text;
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
return;
|
|
}
|
|
//搜索俱乐部
|
|
var group = await _socialData.GetClubs(name);
|
|
OnRefreshList(group);
|
|
}
|
|
void OnDelete()
|
|
{
|
|
inputField.text = "";
|
|
btn_delete.gameObject.SetActive(false);
|
|
OnRefresh();
|
|
}
|
|
async void OnRefresh()
|
|
{
|
|
var group = await _socialData.GetClubs("");
|
|
OnRefreshList(group);
|
|
}
|
|
void OnRefreshList(List<ClubInfo> clubInfos)
|
|
{
|
|
if (this == null || !enabled)
|
|
{
|
|
return;
|
|
}
|
|
itemDatas.Clear();
|
|
if (clubInfos != null)
|
|
{
|
|
foreach (var item in clubInfos)
|
|
{
|
|
ClubItemData data = new ClubItemData();
|
|
data.name = item.clubSettingData.clubName;
|
|
data.id = item.id;
|
|
data.icon = item.clubSettingData.icon;
|
|
data.desc = item.clubSettingData.description;
|
|
data.trophy = item.points;
|
|
data.memberCount = item.curMembers;
|
|
data.memberLimit = item.maxMembers;
|
|
data.type = (EClubType)item.clubSettingData.type;
|
|
data.required = item.clubSettingData.gradeReq;
|
|
itemDatas.Add(data);
|
|
}
|
|
}
|
|
loading.SetActive(false);
|
|
bool isShow = itemDatas.Count > 0;
|
|
//empty.SetActive(!isShow);
|
|
if (!isShow)
|
|
{
|
|
inputField.text = "";
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_107"));
|
|
}
|
|
scrollRect.gameObject.SetActive(isShow);
|
|
if (isShow)
|
|
{
|
|
scrollRect.Init<ClubItem, ClubItemData>(itemHigh, item, OnClickItem, itemDatas);
|
|
}
|
|
}
|
|
bool isLoadClubInfoPopupPanel = false;
|
|
async void OnClickItem(ClubItem item)
|
|
{
|
|
if (isLoadClubInfoPopupPanel)
|
|
{
|
|
return;
|
|
}
|
|
isLoadClubInfoPopupPanel = true;
|
|
//俱乐部详情
|
|
_socialData.ClubItemData = item.data;
|
|
await UIManager.Instance.ShowUI(UITypes.ClubInfoPopupPanel);
|
|
isLoadClubInfoPopupPanel = false;
|
|
}
|
|
async void OnCreate()
|
|
{
|
|
btn_create.enabled = false;
|
|
if (_socialData.IsClubJoined())
|
|
{
|
|
//已经加入俱乐部
|
|
GContext.Publish(new ClubStateChangeEvent() { state = 2 });
|
|
}
|
|
else
|
|
{
|
|
//创建俱乐部窗口
|
|
await UIManager.Instance.ShowUI(UITypes.ClubCreatePopupPanel);
|
|
}
|
|
btn_create.enabled = true;
|
|
}
|
|
}
|
|
public class ClubItemData
|
|
{
|
|
public string name;
|
|
public ulong id;
|
|
public string icon;
|
|
public string desc;
|
|
public int trophy = 0;
|
|
public int memberCount = 0;
|
|
public int memberLimit = 10;
|
|
public EClubType type;
|
|
public int required;
|
|
}
|