111 lines
2.7 KiB
C#
111 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.UI.Terminal
|
|
{
|
|
public class TerminalRecordPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private TerminalPanelAnimator panelAnimator;
|
|
[SerializeField] private Button backButton;
|
|
[SerializeField] private ScrollRect scrollRect;
|
|
[SerializeField] private Transform recordRoot;
|
|
[SerializeField] private TerminalRecordItemView recordItemPrefab;
|
|
[SerializeField] private TMP_Text emptyText;
|
|
|
|
private readonly List<LineInfo> _recordDataList = new List<LineInfo>();
|
|
|
|
public bool IsOpen => gameObject.activeSelf;
|
|
private TerminalPanel _owner;
|
|
|
|
public void SetOwner(TerminalPanel owner)
|
|
{
|
|
_owner = owner;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
backButton?.onClick.AddListener(ReturnGame);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
backButton?.onClick.RemoveListener(ReturnGame);
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
_owner?.SetHeader("<诊疗记录>", "EMR 511/42 - Clinical Record");
|
|
DrawRecords();
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Show();
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
ClearRecordItems();
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Hide();
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|
|
|
|
public void AppendDialogLine(LineInfo lineInfo)
|
|
{
|
|
_recordDataList.Add(lineInfo);
|
|
}
|
|
|
|
public void ClearDialog()
|
|
{
|
|
_recordDataList.Clear();
|
|
}
|
|
|
|
private void DrawRecords()
|
|
{
|
|
ClearRecordItems();
|
|
var hasRecords = _recordDataList.Count > 0;
|
|
if (emptyText != null)
|
|
{
|
|
emptyText.gameObject.SetActive(!hasRecords);
|
|
}
|
|
|
|
foreach (var recordData in _recordDataList)
|
|
{
|
|
var item = Instantiate(recordItemPrefab, recordRoot);
|
|
item.Init(recordData);
|
|
}
|
|
|
|
if (scrollRect != null)
|
|
{
|
|
scrollRect.verticalNormalizedPosition = 0f;
|
|
}
|
|
}
|
|
|
|
private void ClearRecordItems()
|
|
{
|
|
if (recordRoot != null)
|
|
{
|
|
recordRoot.DestroyAllChildren();
|
|
}
|
|
}
|
|
|
|
private void ReturnGame()
|
|
{
|
|
_owner.Back();
|
|
}
|
|
}
|
|
}
|