using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ListPanel : BasePanel { public static ListPanel instance; public Button returnBtn; public Toggle toggle1; // 第一个 Toggle public Toggle toggle2; // 第二个 Toggle public GameObject panel1; // 第一个面板 public GameObject panel2; // 第二个面板 public Transform tog1; public Transform tog2; public Transform parent1;//蒙板父物体 public Transform parent2; public Transform Orparent1;//原始父物体 public Transform Orparent2; public GameObject ListItemPre;//排行预制体 public List ItemList; public List ItemListLastDay; public Transform CreateParentToDay; public Transform CreateParentLastDay; public ListItem SelfListToDay;//自己排名 public ListItem SelfListLastDay;//自己排名 public AllHouseContro allHouseContro; public MotherFuck118 MotherFuck118; public Directlist directlist; public MotherFuck119 MotherFuck119; public Directlist wokelist; public bool ToShow; public override void Start() { base.Start(); instance = this; returnBtn.onClick.AddListener(OnClickReBtn); if (allHouseContro!=null) { allHouseContro.GetInfo518(); allHouseContro.GetInfo518(1); } // 初始化 Toggle 的监听事件 toggle1.onValueChanged.AddListener(OnToggle1Changed); toggle2.onValueChanged.AddListener(OnToggle2Changed); // 初始化面板状态,根据 Toggle 的初始值 UpdatePanels(); if (ToShow) { SetInfo118(); SetInfo119(); ShowPanel(); } } // 第一个 Toggle 的变化事件 private void OnToggle1Changed(bool isOn) { if (isOn) { SetMarsk(2); panel1.SetActive(true); panel2.SetActive(false); SelfListToDay.gameObject.SetActive(true); SelfListLastDay.gameObject.SetActive(false); } } // 第二个 Toggle 的变化事件 private void OnToggle2Changed(bool isOn) { if (isOn) { SetMarsk(1); panel1.SetActive(false); panel2.SetActive(true); SelfListLastDay.gameObject.SetActive(true); SelfListToDay.gameObject.SetActive(false); //allHouseContro.GetInfo518(1); } } // 根据当前 Toggle 的状态初始化面板 public void UpdatePanels() { panel1.SetActive(toggle1.isOn); panel2.SetActive(toggle2.isOn); SelfListToDay.gameObject.SetActive(toggle1.isOn); SelfListLastDay.gameObject.SetActive(toggle2.isOn); } public void ShowPanels()//显示所有面板 { panel1.SetActive(true); panel2.SetActive(true); } void OnDestroy() { // 取消监听事件,避免内存泄漏 toggle1.onValueChanged.RemoveListener(OnToggle1Changed); toggle2.onValueChanged.RemoveListener(OnToggle2Changed); } public void OnClickReBtn() { HidePanel(); } public void SetMarsk(int i) { if (i==1) { tog1.SetParent(parent1); tog2.SetParent(Orparent2); } else { tog1.SetParent(Orparent1); tog2.SetParent(parent2); } } public void CreateListItem(List gameData,Transform parent,int flag=0) { foreach (gameEscapeUserBetResponseVoList item in gameData) { GameObject newPanel = Instantiate(ListItemPre, parent); ListItem panelComponent = newPanel.GetComponent(); // 设置实例化对象的内容 panelComponent.list=item.orderNo; panelComponent.listText.text= item.orderNo.ToString(); panelComponent.nameText.text=item.nickName; panelComponent.numText.text = item.bet.ToString(); if (flag==0) { // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemList) { if (panel.GetComponent().list == item.orderNo) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemList.Add(newPanel); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } else { // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemListLastDay) { if (panel.GetComponent().list == item.orderNo) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemListLastDay.Add(newPanel); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } } } public void SetSelfList(userBetInfo info,int flag=0) { if (flag==0) { SelfListToDay.listText.text = info.orderNo; SelfListToDay.nameText.text = info.nickName; SelfListToDay.numText.text = info.bet.ToString(); SelfListToDay.headPath = info.headImg; SelfListToDay.SetListImage(); SelfListToDay.ListBgImage(); } else { SelfListLastDay.listText.text = info.orderNo; SelfListLastDay.nameText.text = info.nickName; SelfListLastDay.numText.text = info.bet.ToString(); SelfListLastDay.headPath = info.headImg; SelfListLastDay.SetListImage(); SelfListLastDay.ListBgImage(); } } public void SetDirectSelfList(userResponseVo info, int flag = 0) { if (flag == 0) { bool ishave = false; foreach (GameObject listItem in ItemList) { if (listItem.GetComponent().UserId != info.UserId) { continue; } else { SelfListToDay.listText.text = listItem.GetComponent().list.ToString(); ishave = true; break; } } if (!ishave) { SelfListToDay.listText.text = "100+"; } SelfListToDay.nameText.text = info.NickName; SelfListToDay.numText.text = info.VoluteCoin.ToString("F1"); SelfListToDay.headPath = info.HeadImg; SelfListToDay.SetListImage(); SelfListToDay.ListBgImage(); SelfListToDay.snailCoinImage.gameObject.SetActive(false); } else { bool ishave=false; foreach (GameObject listItem in ItemListLastDay) { if (listItem.GetComponent().UserId != info.UserId) { continue; } else { SelfListLastDay.listText.text = listItem.GetComponent().list.ToString(); ishave = true; break; } } if (!ishave) { SelfListLastDay.listText.text = "100+"; } SelfListLastDay.nameText.text = info.NickName; SelfListLastDay.numText.text = info.VoluteCoin.ToString("F1"); SelfListLastDay.headPath = info.HeadImg; SelfListLastDay.SetListImage(); SelfListLastDay.ListBgImage(); SelfListLastDay.snailCoinImage.sprite = SelfListLastDay.woke; } } public void CreateDirectListItem(List gameData, Transform parent, int flag = 0) { int num = 1; foreach (userResponseVoList item in gameData) { GameObject newPanel = Instantiate(ListItemPre, parent); ListItem panelComponent = newPanel.GetComponent(); // 设置实例化对象的内容 panelComponent.list = num; panelComponent.listText.text = num.ToString(); panelComponent.nameText.text = item.NickName; panelComponent.numText.text = item.VoluteCoin.ToString("F1"); panelComponent.UserId = (int)(item.UserId); if (flag == 0) { panelComponent.snailCoinImage.gameObject.SetActive(false); // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemList) { if (panel.GetComponent().list == (int)item.UserId) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemList.Add(newPanel); num++; } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } else { panelComponent.snailCoinImage.sprite= panelComponent.woke; // 判断是否已存在 bool exists = false; foreach (GameObject panel in ItemListLastDay) { if (panel.GetComponent().list == (int)item.UserId) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { ItemListLastDay.Add(newPanel); num++; } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } } } public async void SetInfo118() { directlist = await MotherFuck118.directlistResult(); CreateDirectListItem(directlist.data.UserResponseVoList, CreateParentToDay, 0); SetDirectSelfList(directlist.data.userResponseVo, 0); } public async void SetInfo119() { wokelist = await MotherFuck119.directlistResult(); CreateDirectListItem(wokelist.data.UserResponseVoList, CreateParentLastDay, 1); SetDirectSelfList(wokelist.data.userResponseVo, 1); } }