using System.Collections; using System.Collections.Generic; using System.Globalization; using TMPro; using UnityEngine; using UnityEngine.UI; public class HistoryPanel : BasePanel { public Button returnBtn; public List KillTimesList;//100次击杀统计 public List WinTimesList;//100次夺冠统计 public GameObject historyItemPre;//物品预制体 public Transform ItemPreGrid;//预制体生成后的父物体 public List ItemList; public TextMeshProUGUI throwEggText;//投入蜗牛蛋的文本 public TextMeshProUGUI getEggText;//获得蜗牛蛋的文本 public GameObject JournalPanelPre;//用户参与面板预制体 public Transform JournParent;//用户参与面板父物体 public List journalPanels=new List(); public ScrollRect scrollRect; // 将ScrollRect拖拽到此字段 public override void Start() { scrollRect.vertical = false; // 禁用垂直滚动 base.Start(); returnBtn.onClick.AddListener(OnClickReBtn); // 设置ScrollView默认显示在最上面 } public void OnClickReBtn() { HidePanel(); } public override void HidePanel() { scrollRect.vertical = false; // 禁用垂直滚动 base.HidePanel(); } public override void ShowPanel() { scrollRect.vertical = true; // 启用垂直滚动 base.ShowPanel(); } public void SetKilledText(gameEscapeRoomKillCountResponseVo gameKill)//近100次被杀记录的文本修改方法 { for (int i=0;i gameKnightHorseResponseVoList)//近100次夺冠记录的文本修改方法 { foreach (gameKnightHorseResponseVo gameKnightHorseResponseVo in gameKnightHorseResponseVoList) { for (int i = 0; i < WinTimesList.Count; i++) { if (WinTimesList[i].roomNo ==int.Parse (gameKnightHorseResponseVo.horseNo)) { WinTimesList[i].TextPro.text = gameKnightHorseResponseVo.horseCount + "次";//给次数值 } } } } public void CreateJournalPanel(List gameData) // 创建参与历史记录 { if (journalPanels.Count > 0) { for (int i = 0; i < journalPanels.Count; i++) { Destroy(journalPanels[i]); } journalPanels.Clear(); } foreach (dataList item in gameData) { // 实例化一个新的 JournalPanelPre 对象 GameObject newPanel = Instantiate(JournalPanelPre, JournParent); // 获取新实例的 JournalPanel 组件 JournalPanel panelComponent = newPanel.GetComponent(); // 设置实例化对象的内容 panelComponent.gameNoText.text = item.gameNo + "期"; panelComponent.gameNo = item.gameNo; panelComponent.betText.text = item.bet.ToString(); panelComponent.roomNo = item.roomNo; panelComponent.roomNoKill = item.roomNoKill; panelComponent.beansCoinText.text = item.beansCoin.ToString(); panelComponent.createTimeText.text = item.createTime; panelComponent.outcome = item.outcome; // 判断是否已存在 bool exists = false; foreach (GameObject panel in journalPanels) { if (panel.GetComponent().gameNo == item.gameNo) { exists = true; break; } } // 如果不存在,则添加到列表 if (!exists) { journalPanels.Add(newPanel); } else { // 如果已存在,可以根据需求决定是否销毁该实例 Destroy(newPanel); } } } public void SetKillHouse(List gameEscapeModelList) // 记录近 10 次被击杀的房间 { foreach (gameEscapeModel gameEscape in gameEscapeModelList) { string[] parts = gameEscape.roomNoKill.Split(","); // 根据 ',' 分割字符串 Debug.Log("被击杀的房间号: " + gameEscape.roomNoKill + "---------------"); // 实例化新的对象 GameObject newHistoryItem = Instantiate(historyItemPre, ItemPreGrid); // 设置实例的内容 HistoryItem historyItemComponent = newHistoryItem.GetComponent(); foreach (string killNo in parts) { historyItemComponent.nameTextPro.text += AddName(int.Parse(killNo)); // 房间名字 } historyItemComponent.TextPro.text = gameEscape.gameNo + "期"; // 期号 //historyItemComponent.image.sprite = item.sprite; // 背景图片 // 限制列表最多保存 10 个实例 if (ItemList.Count >= 10) { Destroy(ItemList[0]); // 销毁最早的对象 ItemList.RemoveAt(0); // 从列表移除最早的对象 } // 将新实例添加到列表 ItemList.Add(newHistoryItem); } } public string AddName(int roomId) { string text=""; switch (roomId) { case 1: text = "紫怪屋"; break; case 2: text = "青嬉舍"; break; case 3: text = "粉乐居"; break; case 4: text = "黄逗室"; break; case 5: text = "蓝笑窟"; break; case 6: text = "绿趣巢"; break; } return text; } public string AddRaName(int roomId) { string text = ""; switch (roomId) { case 1: text = "美队蜗"; break; case 2: text = "蜘蛛蜗"; break; case 3: text = "毒液蜗"; break; case 4: text = "钢铁蜗"; break; case 5: text = "蝙蝠蜗"; break; case 6: text = "超人蜗"; break; case 7: text = "雷神蜗"; break; case 8: text = "灭霸蜗"; break; } return text; } public void SetRaKillHouse(List gameKnightModelList) // 记录近 10 次比赛记录 { foreach (GameKnightModelRecord gameKnightMode in gameKnightModelList) { if (gameKnightMode.horseNoAll!="") { string[] parts = gameKnightMode.horseNoAll.Split(","); // 根据 ',' 分割字符串 // 实例化新的对象 GameObject newHistoryItem = Instantiate(historyItemPre, ItemPreGrid); // 设置实例的内容 HistoryItem historyItemComponent = newHistoryItem.GetComponent(); int index = 0; foreach (string RemainNo in parts) { if (index==1)//#A3FBFF //#D7FFA0 //#FFF9A3 //#FEED9F { historyItemComponent.nameTextPro.text += "" + AddRaName(int.Parse(RemainNo)) + ""; // 房间名字 } else if (index==2) { historyItemComponent.nameTextPro.text += "" + AddRaName(int.Parse(RemainNo)) + ""; // 房间名字 } else if (index==3) { historyItemComponent.nameTextPro.text += AddRaName(int.Parse(RemainNo)); // 房间名字 } else { historyItemComponent.nameTextPro.text += "" + AddRaName(int.Parse(RemainNo)) + ""; // 房间名字 } index++; } historyItemComponent.TextPro.text = gameKnightMode.gameNo + "期"; // 期号 //historyItemComponent.image.sprite = item.sprite; // 背景图片 // 限制列表最多保存 10 个实例 if (ItemList.Count >= 10) { Destroy(ItemList[0]); // 销毁最早的对象 ItemList.RemoveAt(0); // 从列表移除最早的对象 } // 将新实例添加到列表 ItemList.Add(newHistoryItem); } } } }