68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class TaskPanel : MonoBehaviour, ILineView
|
|
{
|
|
#region 索引
|
|
|
|
[SerializeField] private Transform taskRoot;
|
|
[SerializeField] private Transform taskListParent;
|
|
private GameObject _taskItemPrefab;
|
|
private readonly Dictionary<string, GameObject> _taskDict = new();
|
|
|
|
#endregion
|
|
|
|
private void Awake()
|
|
{
|
|
_taskItemPrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.TaskItemName);
|
|
}
|
|
|
|
public void ShowPanel()
|
|
{
|
|
taskRoot.DOLocalMoveX(-7.12f, 1f);
|
|
}
|
|
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}";
|
|
token.TextStart();
|
|
|
|
_taskDict[token.lineInfo.lineId] = taskItem;
|
|
token.TextShown();
|
|
token.ForceAdvance();
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(taskListParent.GetComponent<RectTransform>());
|
|
}
|
|
}
|
|
} |