149 lines
4.0 KiB
C#
149 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization.Components;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class TaskPanel : MonoBehaviour, IUIPanel, IDialogView
|
|
{
|
|
private Transform _taskListParent;
|
|
private GameObject _taskItemPrefab;
|
|
|
|
private readonly Dictionary<string, GameObject> _taskDict = new();
|
|
|
|
private void Awake()
|
|
{
|
|
_taskListParent = transform.Find("Record");
|
|
_taskItemPrefab = ResourceKit.LoadAddressableSync<GameObject>(ConstRef.TaskItemName);
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, ClearTasks);
|
|
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Task, this);
|
|
}
|
|
|
|
#region 诊疗单功能
|
|
|
|
public void CompleteTask(string lineId)
|
|
{
|
|
if (_taskDict.TryGetValue(lineId, out var taskItem))
|
|
{
|
|
taskItem.GetComponent<TMP_Text>().fontStyle |= FontStyles.Strikethrough;
|
|
}
|
|
}
|
|
|
|
public void ClearTasks()
|
|
{
|
|
foreach (var task in _taskDict)
|
|
{
|
|
Destroy(task.Value);
|
|
}
|
|
_taskDict.Clear();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 对话框功能实现
|
|
|
|
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
|
|
{
|
|
var taskItem = Instantiate(_taskItemPrefab, _taskListParent);
|
|
// 设置本地化数据
|
|
var localize = taskItem.GetComponent<LocalizeStringEvent>();
|
|
localize.SetTable(DialogController.Instance.GetCurLocalizedTableName());
|
|
localize.SetEntry(lineId);
|
|
_taskDict[lineId] = taskItem;
|
|
|
|
ActionKit.Delay(0.5f, nextStep);
|
|
}
|
|
|
|
public void ShowOptions(DialogOption[] dialogueOptions)
|
|
{
|
|
Debug.Log("Task 面板不能显示选项");
|
|
}
|
|
|
|
public void HideDialog()
|
|
{
|
|
// HideDialog应该由其他函数控制
|
|
}
|
|
|
|
public bool TrySkipLine(bool isForceSkip = false)
|
|
{
|
|
// 这里不能跳过对话
|
|
return true;
|
|
}
|
|
|
|
public void NextStep()
|
|
{
|
|
// 这里不能手动跳到下一行
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 打开和关闭
|
|
|
|
public bool IsOpen { get; private set;}
|
|
|
|
public void Show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
AudioManager.Instance.PlaySfx("event:/Scriptal/taskmanager");
|
|
// 下移
|
|
transform.DOLocalMoveY(-350, 1f).OnComplete(() =>
|
|
{
|
|
IsOpen = true;
|
|
});
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
// 上移
|
|
AudioManager.Instance.PlaySfx("event:/Scriptal/taskmanager");
|
|
transform.DOLocalMoveY(0, 1f).OnComplete(() =>
|
|
{
|
|
gameObject.SetActive(false);
|
|
IsOpen = false;
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public static class TaskYarnCommand
|
|
{
|
|
private static TaskPanel TaskPanel => UIManager.Instance.GetComponent<TaskPanel>();
|
|
|
|
[YarnCommand("complete_task")]
|
|
public static void CompleteTask(string lineId)
|
|
{
|
|
TaskPanel.CompleteTask(lineId);
|
|
}
|
|
|
|
[YarnCommand("clear_tasks")]
|
|
public static void ClearTasks()
|
|
{
|
|
TaskPanel.ClearTasks();
|
|
}
|
|
|
|
[YarnCommand("task_moveIn")]
|
|
public static IEnumerator ShowTask()
|
|
{
|
|
UIManager.Instance.ShowPanel<TaskPanel>();
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
|
|
[YarnCommand("task_moveOut")]
|
|
public static IEnumerator HideTask()
|
|
{
|
|
UIManager.Instance.HidePanel<TaskPanel>();
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
}
|
|
}
|