136 lines
4.6 KiB
C#
136 lines
4.6 KiB
C#
using System;
|
||
using UnityEngine;
|
||
using Logic;
|
||
using RuntimeData;
|
||
using Animancer;
|
||
using TMPro;
|
||
using UnityEditor.PackageManager.UI;
|
||
using UnityEngine.UI;
|
||
|
||
public class HistoryUI
|
||
{
|
||
private Main _main;
|
||
private MapData _mapData;
|
||
public GameObject ROHistoryUI;
|
||
public GameObject ROTable;
|
||
|
||
public Button StartButton;
|
||
|
||
|
||
public bool NeedShow = false;
|
||
|
||
private bool _isShowing = false;
|
||
private bool _isAnimating = false;
|
||
private float _fadeDuration = 0.2f;
|
||
|
||
public HistoryUI(Main main, MapData mapData)
|
||
{
|
||
_main = main;
|
||
_mapData = mapData;
|
||
ROHistoryUI = UIManager.Instance.ROUIManager.transform.Find("GameUI/HistoryUI").gameObject;
|
||
ROTable = ROHistoryUI.transform.Find("ForceInfoPanel/Scroll/Viewport/Content").gameObject;
|
||
ROHistoryUI.transform.Find("CloseButton").GetComponent<Button>().onClick.AddListener(
|
||
() => {
|
||
Debug.Log("clicked");
|
||
NeedShow = false;
|
||
UIManager.Instance.GameUI.MainUI.NeedShow = true;
|
||
});
|
||
ROHistoryUI.gameObject.SetActive(false);
|
||
ROHistoryUI.gameObject.SetActive(false);
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
if (_isAnimating) return;
|
||
|
||
if (NeedShow && !ROHistoryUI.activeSelf)
|
||
{
|
||
Show();
|
||
}
|
||
else if (!NeedShow && ROHistoryUI.activeSelf)
|
||
{
|
||
Hide();
|
||
}
|
||
|
||
// 设置界面逻辑(如音量滑块变化、按钮监听等)也可写在这里
|
||
}
|
||
|
||
public void UpdateHistoryTable()
|
||
{
|
||
var dataSize = GameRecordManager.Instance.GameRecordData.Records.Count;
|
||
var dataList = GameRecordManager.Instance.GameRecordData.Records;
|
||
if (dataSize > 100) dataSize = 100;
|
||
|
||
var t = ROTable.transform.childCount;
|
||
//如果数量不够,先clone row补足
|
||
if (t < dataSize)
|
||
{
|
||
var sample = ROTable.transform.Find("SampleRow").gameObject;
|
||
for (; t < dataSize; t++)
|
||
{
|
||
GameObject clonedChildB = GameObject.Instantiate(sample, ROTable.transform);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//更新内容
|
||
for (var i = 0; i < dataSize; i++)
|
||
{
|
||
var row = ROTable.transform.GetChild(i).gameObject;
|
||
row.SetActive(true);
|
||
row.transform.GetChild(1).Find("Text").GetComponent<TextMeshProUGUI>().text = "30";
|
||
row.transform.GetChild(2).Find("Text").GetComponent<TextMeshProUGUI>().text = dataList[i].Score.ToString();
|
||
row.transform.GetChild(3).Find("Text").GetComponent<TextMeshProUGUI>().text = "蕾米莉亚";
|
||
row.transform.GetChild(4).Find("Text").GetComponent<TextMeshProUGUI>().text = dataList[i].MapHeight + " × " + dataList[i].MapWidth;
|
||
row.transform.GetChild(5).Find("Text").GetComponent<TextMeshProUGUI>().text = dataList[i].AIDiff.ToString();
|
||
row.transform.GetChild(6).Find("Text").GetComponent<TextMeshProUGUI>().text = dataList[i].PlayerCount.ToString();
|
||
row.transform.GetChild(7).Find("Text").GetComponent<TextMeshProUGUI>().text = "1.0";
|
||
if(DateTime.TryParse(dataList[i].Time,out var dateTime))
|
||
row.transform.GetChild(8).Find("Text").GetComponent<TextMeshProUGUI>().text = dateTime.ToString("yyyy.MM.dd HH:MM");
|
||
}
|
||
|
||
|
||
//将多出来的row设置active=false
|
||
for(var i = dataSize;i < t;i++)
|
||
ROTable.transform.GetChild(i).gameObject.SetActive(false);
|
||
|
||
}
|
||
public void Show()
|
||
{
|
||
if (_isShowing || _isAnimating) return;
|
||
|
||
_isShowing = true;
|
||
_isAnimating = true;
|
||
ROHistoryUI.SetActive(true);
|
||
|
||
UpdateHistoryTable();
|
||
|
||
AnimancerComponent animancer = ROHistoryUI.GetComponent<AnimancerComponent>();
|
||
AnimationClip fadeInClip = Resources.Load<AnimationClip>("Animations/UI/SettingPanelFadeIn");
|
||
if (fadeInClip != null)
|
||
animancer.Play(fadeInClip);
|
||
|
||
Timer.Instance.TimerRegister(ROHistoryUI, () => { _isAnimating = false; }, _fadeDuration);
|
||
}
|
||
|
||
public void Hide()
|
||
{
|
||
if (!_isShowing || _isAnimating) return;
|
||
|
||
_isShowing = false;
|
||
_isAnimating = true;
|
||
|
||
AnimancerComponent animancer = ROHistoryUI.GetComponent<AnimancerComponent>();
|
||
AnimationClip fadeOutClip = Resources.Load<AnimationClip>("Animations/UI/SettingPanelFadeOut");
|
||
if (fadeOutClip != null)
|
||
animancer.Play(fadeOutClip);
|
||
|
||
Timer.Instance.TimerRegister(ROHistoryUI, () =>
|
||
{
|
||
ROHistoryUI.SetActive(false);
|
||
_isAnimating = false;
|
||
}, _fadeDuration);
|
||
}
|
||
}
|