173 lines
5.0 KiB
C#
173 lines
5.0 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace Script.UI
|
||
{
|
||
public class TeamPanel : PanelBase
|
||
{
|
||
public GameObject item;
|
||
public Button btn_Close;
|
||
public Button btn_Stop;
|
||
|
||
class TeamPanelData
|
||
{
|
||
private GameObject go;
|
||
private Text txt_ID;
|
||
private Text txt_Team;
|
||
|
||
public TeamPanelData(GameObject go, string idStr, string teamNameStr = "")
|
||
{
|
||
txt_ID = go.transform.Find("txt_ID").GetComponent<Text>();
|
||
txt_Team = go.transform.Find("txt_Team").GetComponent<Text>();
|
||
txt_ID.text = idStr;
|
||
txt_Team.text = teamNameStr;
|
||
}
|
||
|
||
public void SetTeamName(string teamName)
|
||
{
|
||
this.txt_Team.text = teamName;
|
||
}
|
||
}
|
||
|
||
private Dictionary<int, TeamPanelData> teams = new Dictionary<int, TeamPanelData>();
|
||
// private List<TeamPanelData> teamPanelDatas = new List<TeamPanelData>();
|
||
|
||
// private List<string> teamList = new List<string>();
|
||
|
||
public override void Init()
|
||
{
|
||
base.Init();
|
||
btn_Close.onClick.AddListener(ClickClose);
|
||
btn_Stop.onClick.AddListener(ClickStop);
|
||
|
||
btn_Close.gameObject.SetActive(false);
|
||
btn_Stop.gameObject.SetActive(true);
|
||
}
|
||
|
||
private void ClickStop()
|
||
{
|
||
btn_Close.gameObject.SetActive(true);
|
||
btn_Stop.gameObject.SetActive(false);
|
||
|
||
//
|
||
isRolling = false;
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
base.Dispose();
|
||
btn_Close.onClick.RemoveListener(ClickClose);
|
||
btn_Stop.onClick.RemoveListener(ClickStop);
|
||
}
|
||
|
||
public override void Open()
|
||
{
|
||
base.Open();
|
||
// var teamDataDataInfos = ExcelManager.Instance.GetTeamDatas;
|
||
// foreach (var teamDataDataInfo in teamDataDataInfos)
|
||
// {
|
||
// teamList.Add(teamDataDataInfo.teamName);
|
||
// }
|
||
|
||
InitItem();
|
||
}
|
||
|
||
private void ClickClose()
|
||
{
|
||
var openPanel = UIManager.Instance.GetPanel<HomePanel>(PanelType.Home);
|
||
openPanel.SetTeamFinish();
|
||
UIManager.Instance.OpenPanel(PanelType.Home);
|
||
Close();
|
||
}
|
||
|
||
void InitItem()
|
||
{
|
||
List<SummaryInfo> cache = new List<SummaryInfo>(GlobalManager.Instance.list);
|
||
|
||
foreach (var summaryInfo in cache)
|
||
{
|
||
var teamDataDataInfo = ExcelManager.Instance.GetTeamRandomInfo;
|
||
summaryInfo.team = teamDataDataInfo.teamName;
|
||
}
|
||
|
||
// 排个序
|
||
var list = cache.OrderBy(t => t.id).ToList();
|
||
|
||
foreach (var summaryInfo in list)
|
||
{
|
||
item.SetActive(false);
|
||
GenItem(summaryInfo.id.ToString(), summaryInfo.team);
|
||
}
|
||
|
||
isRolling = true;
|
||
StartCoroutine(RandomRoll());
|
||
}
|
||
|
||
private void GenItem(string id, string team)
|
||
{
|
||
var go = GameObject.Instantiate(item, item.transform.parent);
|
||
go.name = id;
|
||
go.SetActive(true);
|
||
teams.Add(int.Parse(id), new TeamPanelData(go, id, team));
|
||
}
|
||
|
||
private bool isRolling;
|
||
|
||
IEnumerator RandomRoll()
|
||
{
|
||
while (isRolling)
|
||
{
|
||
yield return new WaitForSeconds(0.02f);
|
||
var info = ExcelManager.Instance.GetTeamRandomInfo;
|
||
foreach (var teamPanelData in teams.Values)
|
||
{
|
||
teamPanelData.SetTeamName(info.teamName);
|
||
}
|
||
}
|
||
|
||
ShowResult();
|
||
}
|
||
|
||
void ShowResult()
|
||
{
|
||
List<SummaryInfo> cache = new List<SummaryInfo>(GlobalManager.Instance.list);
|
||
|
||
foreach (var summaryInfo in cache)
|
||
{
|
||
var teamDataDataInfo = ExcelManager.Instance.GetTeamRandomInfo;
|
||
summaryInfo.team = teamDataDataInfo.teamName;
|
||
}
|
||
|
||
// 排个序
|
||
var list = cache.OrderBy(t => t.id).ToList();
|
||
|
||
StringBuilder sb = new StringBuilder();
|
||
|
||
foreach (var summaryInfo in list)
|
||
{
|
||
item.SetActive(false);
|
||
SetItem(summaryInfo.id.ToString(), summaryInfo.team);
|
||
sb.AppendLine($"选手ID:{summaryInfo.id}");
|
||
sb.AppendLine($"选手团型:{summaryInfo.team}");
|
||
sb.AppendLine($"\n");
|
||
}
|
||
|
||
GlobalManager.Instance.list = list;
|
||
|
||
FileManager.Instance.SavePlayerTeamData(sb.ToString());
|
||
}
|
||
|
||
private void SetItem(string id, string team)
|
||
{
|
||
var i = int.Parse(id);
|
||
if (teams.TryGetValue(i, out var data))
|
||
{
|
||
data.SetTeamName(team);
|
||
}
|
||
}
|
||
}
|
||
} |