62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class TaskScreen : MonoBehaviour, ILineView
|
|
{
|
|
#region 索引
|
|
|
|
private Transform _taskListParent;
|
|
private GameObject _taskItemPrefab;
|
|
private readonly Dictionary<string, GameObject> _taskDict = new();
|
|
|
|
#endregion
|
|
|
|
private void Awake()
|
|
{
|
|
_taskListParent = transform.Find("Record");
|
|
_taskItemPrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.TaskItemName);
|
|
}
|
|
|
|
public void CompleteTask(string lineId)
|
|
{
|
|
if (_taskDict.Remove(lineId, out var taskItem))
|
|
{
|
|
Destroy(taskItem);
|
|
}
|
|
}
|
|
|
|
public void ClearTasks()
|
|
{
|
|
foreach (var task in _taskDict)
|
|
{
|
|
Destroy(task.Value);
|
|
}
|
|
_taskDict.Clear();
|
|
}
|
|
|
|
public void RunLine(LineSyncToken token)
|
|
{
|
|
if (_taskDict.ContainsKey(token.lineInfo.lineId))
|
|
{
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
|
token.ForceAdvance();
|
|
return;
|
|
}
|
|
|
|
var taskItem = Instantiate(_taskItemPrefab, _taskListParent);
|
|
var task = taskItem.GetComponent<TMP_Text>();
|
|
task.text = $"\u25cf {token.lineInfo.lineText}";
|
|
|
|
_taskDict[token.lineInfo.lineId] = taskItem;
|
|
token.ForceAdvance();
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(_taskListParent.GetComponent<RectTransform>());
|
|
}
|
|
}
|
|
}
|