114 lines
3.5 KiB
C#
114 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class TaskScreen : MonoBehaviour, IDialogView
|
|
{
|
|
#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);
|
|
}
|
|
|
|
#region 对话框功能实现
|
|
|
|
// TODO 随时切换回头再加,先直接赋值
|
|
// public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
|
|
// {
|
|
// var taskItem = Instantiate(_taskItemPrefab, _taskListParent);
|
|
// // 设置本地化数据
|
|
//
|
|
// var localize = taskItem.GetComponent<LocalizedText>();
|
|
// localize.SetLocalizedText(DialogController.Instance.GetCurLocalizedTableName(), lineId);
|
|
// _taskDict[lineId] = localize;
|
|
//
|
|
// EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
|
// EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
|
|
// nextStep.Invoke();
|
|
// LayoutRebuilder.ForceRebuildLayoutImmediate(_taskListParent.GetComponent<RectTransform>());
|
|
// }
|
|
|
|
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId,
|
|
bool isAutoSkip = false)
|
|
{
|
|
if (_taskDict.ContainsKey(lineId))
|
|
{
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
|
|
nextStep.Invoke();
|
|
return;
|
|
}
|
|
|
|
var taskItem = Instantiate(_taskItemPrefab, _taskListParent);
|
|
var task = taskItem.GetComponent<TMP_Text>();
|
|
task.text = $"\u25cf {dialogLine}";
|
|
|
|
_taskDict[lineId] = taskItem;
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
|
|
nextStep.Invoke();
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(_taskListParent.GetComponent<RectTransform>());
|
|
}
|
|
|
|
public void ShowOptions(DialogOption[] dialogueOptions)
|
|
{
|
|
Debug.Log("Task 面板不能显示选项");
|
|
}
|
|
|
|
public void HideDialog()
|
|
{
|
|
// 无法隐藏
|
|
}
|
|
|
|
public bool TrySkipLine(bool isForceSkip = false)
|
|
{
|
|
// 直接继续不跳过
|
|
return true;
|
|
}
|
|
|
|
public void NextStep()
|
|
{
|
|
// 这里不能手动跳到下一行
|
|
}
|
|
|
|
public void OnLocalizationChanged(string value)
|
|
{
|
|
// TODO 有需要可以调整文本
|
|
}
|
|
|
|
#endregion
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|