116 lines
3.9 KiB
C#
116 lines
3.9 KiB
C#
using Assets.MyGame.Scripts.Net;
|
|
using Assets.MyGame.Scripts.Net.WebResponses;
|
|
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIHome_BY_MySelectRoomPanel : SubUIBase
|
|
{
|
|
public GameObject panel_PanelParent;
|
|
public Button panel_RoomItemPrefab;
|
|
public Button btn_NextPage;
|
|
public Button btn_UpPage;
|
|
public TextMeshProUGUI text_PageNum;
|
|
public ScrollRect scroll;
|
|
public List<Transform> itemPage = new List<Transform>();
|
|
public GameObject itemPagePrefab;
|
|
public Transform itemPageParent;
|
|
//public Dictionary<Transform, List<Transform>> itemListDic=new Dictionary<Transform, List<Transform>>();
|
|
public Dictionary<string, Transform> itemListDic = new Dictionary<string, Transform>();
|
|
|
|
int pageNum = 1;
|
|
float horizontalNormalizedPosition;
|
|
public override void Awake()
|
|
{
|
|
btn_NextPage.onClick.AddListener(() =>
|
|
{
|
|
|
|
if (pageNum > 1)
|
|
{
|
|
pageNum--;
|
|
}
|
|
text_PageNum.text = pageNum + "/" + itemPage.Count;
|
|
horizontalNormalizedPosition = (float)(pageNum - 1) / (float)(itemPage.Count - 1);
|
|
});
|
|
btn_UpPage.onClick.AddListener(() =>
|
|
{
|
|
if (pageNum < itemPage.Count)
|
|
{
|
|
pageNum++;
|
|
}
|
|
text_PageNum.text = pageNum + "/" + itemPage.Count;
|
|
horizontalNormalizedPosition = (float)(pageNum - 1) / (float)(itemPage.Count - 1);
|
|
});
|
|
btn_Close.onClick.AddListener(() =>
|
|
{
|
|
Hide();
|
|
|
|
});
|
|
panel_RoomItemPrefab.onClick.AddListener(() =>
|
|
{
|
|
GameManager.Instance.StartGame();
|
|
});
|
|
}
|
|
private void Update()
|
|
{
|
|
scroll.horizontalNormalizedPosition = Mathf.Lerp(scroll.horizontalNormalizedPosition, horizontalNormalizedPosition, 0.5f);
|
|
}
|
|
public override void Hide()
|
|
{
|
|
base.Hide();
|
|
panel_PanelParent.SetActive(true);
|
|
}
|
|
public override void Show(object args = null)
|
|
{
|
|
base.Show(args);
|
|
|
|
text_PageNum.text = pageNum + "/" + itemPage.Count;
|
|
panel_PanelParent.SetActive(false);
|
|
if (args != null)
|
|
{
|
|
int i = 0;
|
|
var v = JsonConvert.DeserializeObject<WebSocketResponseBase<List<GetRoomList>>>(args.ToString());
|
|
//var v = args as List<GetRoomList>;
|
|
itemPage.Add(Instantiate(itemPagePrefab, itemPageParent).transform);
|
|
int pageMax = Mathf.FloorToInt(v.arguments[0].Count / 15f);
|
|
for (int j = 0; j < pageMax; j++)
|
|
{
|
|
|
|
itemPage.Add(Instantiate(itemPagePrefab, itemPageParent).transform);
|
|
|
|
}
|
|
|
|
foreach (var item in v.arguments[0])
|
|
{
|
|
|
|
|
|
|
|
//itemListDic.Add Instantiate(panel_RoomItemPrefab, itemPage[(int)(i/15)-1]);
|
|
var tran = Instantiate(panel_RoomItemPrefab.gameObject, itemPage[(int)(i / 15)]).transform;
|
|
tran.name = item.roomId;
|
|
itemListDic.Add(item.roomId, tran);
|
|
var slider = tran.transform.GetChild(1).GetComponent<Slider>();
|
|
int allPlayerCount = item.currentOnlinePlayerCount + item.robotCount;
|
|
slider.value = (float)allPlayerCount / (float)item.maxPlayerCount;
|
|
if (allPlayerCount == item.maxPlayerCount)
|
|
{
|
|
slider.fillRect.GetChild(0).gameObject.SetActive(true);
|
|
}
|
|
tran.transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = allPlayerCount + "/" + item.maxPlayerCount;
|
|
tran.transform.GetChild(3).GetComponent<TextMeshProUGUI>().text = item.roomNumber.ToString();
|
|
i++;
|
|
|
|
|
|
}
|
|
text_PageNum.text = 1 + "/" + itemPage.Count;
|
|
scroll.horizontalNormalizedPosition = 0;
|
|
pageNum = 1;
|
|
}
|
|
|
|
}
|
|
}
|