148 lines
4.6 KiB
C#
148 lines
4.6 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SocialFriends : MonoBehaviour
|
|
{
|
|
List<Toggle> toggleList = new List<Toggle>();
|
|
List<GameObject> selected_tab = new List<GameObject>();
|
|
FishingFriendAddPanel addfriends;
|
|
GameObject addfriendsOb;
|
|
GameObject listOb;
|
|
GameObject timelineOb;
|
|
#region 事件
|
|
//Button btn_event;
|
|
#endregion
|
|
|
|
#region 好友列表
|
|
public GameObject item;
|
|
public PanelScroll scrollRect;
|
|
GameObject empty;
|
|
float itemHigh;
|
|
public int curSelfRank;
|
|
SocialFriendItem selfItem;
|
|
Button btn_add;
|
|
#endregion
|
|
public void InitUI()
|
|
{
|
|
for (int i = 1; i <= 3; i++)
|
|
{
|
|
toggleList.Add(transform.Find($"tab/text_tab{i}").GetComponent<Toggle>());
|
|
selected_tab.Add(transform.Find($"tab/selected_tab{i}").gameObject);
|
|
}
|
|
addfriendsOb = transform.Find("addfriends").gameObject;
|
|
listOb = transform.Find("list").gameObject;
|
|
timelineOb = transform.Find("timeline").gameObject;
|
|
|
|
//btn_event = transform.Find("btn_event").GetComponent<Button>();
|
|
|
|
empty = transform.Find("list/empty").gameObject;
|
|
btn_add = transform.Find("list/empty/btn_add/btn_green").GetComponent<Button>();
|
|
scrollRect = transform.Find("list/rank/ScrollView").GetComponent<PanelScroll>();
|
|
item = transform.Find("list/rank/ScrollView/Viewport/Content/Item").gameObject;
|
|
selfItem = transform.Find("list/rank/ScrollView/Viewport/Item").GetComponent<SocialFriendItem>();
|
|
itemHigh = item.GetComponent<RectTransform>().sizeDelta.y;
|
|
scrollRect.loop = false;
|
|
}
|
|
private void Start()
|
|
{
|
|
//btn_event.onClick.AddListener(OnEventClick);
|
|
btn_add.onClick.AddListener(OnAddClick);
|
|
SetScroll();
|
|
|
|
selected_tab[0].SetActive(true);
|
|
selected_tab[1].SetActive(false);
|
|
selected_tab[2].SetActive(false);
|
|
|
|
toggleList[0].onValueChanged.AddListener(OnToggleAddFriends);
|
|
toggleList[1].onValueChanged.AddListener(OnToggleList);
|
|
toggleList[2].onValueChanged.AddListener(OnToggleTimeLine);
|
|
toggleList[0].isOn = true;
|
|
OnToggleAddFriends(true);
|
|
}
|
|
|
|
void OnToggleAddFriends(bool isOn)
|
|
{
|
|
addfriendsOb.SetActive(isOn);
|
|
selected_tab[0].SetActive(isOn);
|
|
}
|
|
|
|
void OnToggleList(bool isOn)
|
|
{
|
|
listOb.SetActive(isOn);
|
|
selected_tab[1].SetActive(isOn);
|
|
}
|
|
|
|
void OnToggleTimeLine(bool isOn)
|
|
{
|
|
timelineOb.SetActive(isOn);
|
|
selected_tab[2].SetActive(isOn);
|
|
}
|
|
|
|
public void SetScroll()
|
|
{
|
|
curSelfRank = -1;
|
|
var friendList = new List<SocialFriendItemData>();
|
|
|
|
var LeadboardDataList = GContext.container.Resolve<FriendService>().FriendList;
|
|
for (int i = 0; i < LeadboardDataList.Count; i++)
|
|
{
|
|
friendList.Add(new SocialFriendItemData()
|
|
{
|
|
rank = LeadboardDataList[i].rank,
|
|
lv = LeadboardDataList[i].value / LeadboardData.LV_MODELING,
|
|
infiniteBuildingLevel = LeadboardDataList[i].value % LeadboardData.LV_MODELING,
|
|
playFabId = LeadboardDataList[i].playFabId,
|
|
displayName = LeadboardDataList[i].displayName,
|
|
avatarUrl = LeadboardDataList[i].avatarUrl
|
|
});
|
|
}
|
|
|
|
empty.SetActive(friendList.Count == 0);
|
|
|
|
for (int i = 0; i < friendList.Count; i++)
|
|
{
|
|
if (friendList[i].playFabId == GContext.container.Resolve<IUserService>().UserId)
|
|
{
|
|
curSelfRank = i;
|
|
selfItem.data = friendList[i];
|
|
break;
|
|
}
|
|
}
|
|
scrollRect.Init<SocialFriendItem, SocialFriendItemData>(itemHigh, item, null, friendList);
|
|
SetSelfItem();
|
|
}
|
|
|
|
void SetSelfItem()
|
|
{
|
|
if (curSelfRank >= 0)
|
|
{
|
|
float selfPos = itemHigh * curSelfRank - scrollRect.viewport.rect.height + itemHigh;
|
|
selfItem.gameObject.SetActive(scrollRect.content.anchoredPosition.y < selfPos);
|
|
selfItem.OnInit();
|
|
|
|
scrollRect.onValueChanged.AddListener((Vector2 v2) =>
|
|
{
|
|
selfItem.gameObject.SetActive(scrollRect.content.anchoredPosition.y < selfPos);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
selfItem.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
async void OnEventClick()
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.EventReportPopupPanel);
|
|
}
|
|
|
|
async void OnAddClick()
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.FishingSocialFriendSearchPanel);
|
|
}
|
|
}
|