cheat UI
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BrewMonster.Scripts
|
||||
{
|
||||
public class DebugCmdHistoryListView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] DlgConsole _console;
|
||||
[SerializeField] Transform _content;
|
||||
[SerializeField] DebugCmdHistoryListItem _itemPrefab;
|
||||
[SerializeField] TMP_Text _emptyText;
|
||||
[SerializeField] Button _btnClear;
|
||||
|
||||
private readonly List<DebugCmdHistoryListItem> _items = new List<DebugCmdHistoryListItem>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_btnClear != null)
|
||||
_btnClear.onClick.AddListener(OnClearClicked);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_console != null)
|
||||
_console.HistoryChanged += Rebuild;
|
||||
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_console != null)
|
||||
_console.HistoryChanged -= Rebuild;
|
||||
}
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
if (_content == null || _itemPrefab == null || _console == null)
|
||||
{
|
||||
SetEmptyTextVisible(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ClearItems();
|
||||
|
||||
var history = _console.GetHistory();
|
||||
if (history == null || history.Count == 0)
|
||||
{
|
||||
SetEmptyTextVisible(true);
|
||||
return;
|
||||
}
|
||||
|
||||
SetEmptyTextVisible(false);
|
||||
for (int i = 0; i < history.Count; i++)
|
||||
{
|
||||
var item = Instantiate(_itemPrefab, _content);
|
||||
item.gameObject.SetActive(true);
|
||||
item.Bind(_console, history[i]);
|
||||
_items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClearClicked()
|
||||
{
|
||||
if (_console != null)
|
||||
_console.ClearHistory();
|
||||
}
|
||||
|
||||
private void ClearItems()
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
if (_items[i] != null)
|
||||
Destroy(_items[i].gameObject);
|
||||
}
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
private void SetEmptyTextVisible(bool visible)
|
||||
{
|
||||
if (_emptyText != null)
|
||||
_emptyText.gameObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user