Files
5.24BuYu/Assets/MyGame/aa/UI/Game/ChineseChess/UIChineseChessDistrict.cs
T
2026-06-26 19:32:33 +08:00

133 lines
4.8 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 UnityEngine;
using UnityEngine.UI;
using static Assets.MyGame.Scripts.Net.WebResponses.ChineseChess.ChineseChessGameClassList;
public class UIChineseChessDistrict : SubUIBase
{
public Button panel_RoomItemPrefab;
public Transform panel_RoomItemParent;
public ScrollRect scroll;
//public Dictionary<Transform, List<Transform>> itemListDic=new Dictionary<Transform, List<Transform>>();
public Dictionary<string, Transform> itemListDic = new Dictionary<string, Transform>();
float horizontalNormalizedPosition;
public override void Awake()
{
base.Awake();
//btn_Close.onClick.AddListener(() =>
//{
// UIManager.Instance.Close(UIPanel.MainGamePanelZGXQ);
// UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel);
//});
}
private void Update()
{
scroll.horizontalNormalizedPosition = Mathf.Lerp(scroll.horizontalNormalizedPosition, horizontalNormalizedPosition, 0.5f);
}
public override void Hide()
{
base.Hide();
}
public override void Show(object args = null)
{
base.Show(args);
if (args != null)
{
int i = 0;
var v = JsonConvert.DeserializeObject<WebSocketResponseBase<List<ChessGameRoom>>>(args.ToString());
//var v = args as List<GetRoomList>;
var basePanel = (ChineseChessMainPanel)uIManager.parentUIBase;
foreach (var item in v.arguments[0])
{
//itemListDic.Add Instantiate(panel_RoomItemPrefab, itemPage[(int)(i/15)-1]);
var tran = Instantiate(panel_RoomItemPrefab.gameObject, panel_RoomItemParent).transform;
tran.GetComponent<Button>().onClick.AddListener(() =>
{
//GameManager.Instance.StartGame();
switch (ChineseChessMainPanel.dic_RoomData[ item.roomId].state)
{
case 1:
int temp = ChineseChessMainPanel.dic_RoomData[item.roomId].users.Count;
if (temp == 2)
{
UIManager.Instance.ShowBoardError("玩家满员");
}
else if (temp == 1)
{
uIManager.ShowAsync(UIPanel.ZGXQJoinGame, item);
}
break;
case 2:
UIManager.Instance.ShowBoardError("房间已经开始");
break;
case 3:
case 0:
uIManager.ShowAsync(UIPanel.ZGXQCreateRoom, item);
break;
default:
break;
}
});
tran.name = item.roomId;
itemListDic.Add(item.roomId, tran);
ChineseChessMainPanel.dic_RoomData[item.roomId]=(item);
var slider = tran.transform.GetChild(0).GetComponent<Slider>();
int allPlayerCount = item.users.Count;
//int allPlayerCount = item.currentOnlinePlayerCount + item.robotCount;
slider.value = (float)allPlayerCount / 2;
if (allPlayerCount == 2)
{
slider.fillRect.GetChild(0).gameObject.SetActive(true);
}
else
{
slider.fillRect.GetChild(0).gameObject.SetActive(false);
}
tran.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = allPlayerCount + "/" + 2;
tran.transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = item.roomId.Substring(2).ToString();
i++;
}
scroll.horizontalNormalizedPosition = 0;
}
}
public void UpdataRoom(ChessGameRoom item)
{
string roomID= item.roomId;
ChineseChessMainPanel.dic_RoomData[roomID] = item;
var tran=itemListDic[roomID];
var slider = tran.transform.GetChild(1).GetComponent<Slider>();
int allPlayerCount = item.users.Count;
slider.value = (float)allPlayerCount / 2;
if (allPlayerCount == 2)
{
slider.fillRect.GetChild(0).gameObject.SetActive(true);
}
else
{
slider.fillRect.GetChild(0).gameObject.SetActive(false);
}
tran.transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = allPlayerCount + "/" + 2;
}
}