2024-12-11 14:24:06 +08:00
|
|
|
|
using System;
|
2024-12-06 11:29:20 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
public enum TaskState
|
2024-12-11 20:16:45 +08:00
|
|
|
|
{
|
2024-12-13 17:19:27 +08:00
|
|
|
|
NotStarted, // δ<><CEB4>ʼ
|
|
|
|
|
InProgress, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Completed, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Failed // ʧ<><CAA7>
|
2024-12-11 20:16:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
|
2024-12-06 11:29:20 +08:00
|
|
|
|
public class TaskItem : MonoBehaviour
|
|
|
|
|
{
|
2024-12-13 17:19:27 +08:00
|
|
|
|
public int taskId; // <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
public string taskName; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public TaskState state; // <20><><EFBFBD><EFBFBD>״̬
|
|
|
|
|
public Text taskTxt; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
2024-12-06 11:29:20 +08:00
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
public List<TaskTarget> Targets = new List<TaskTarget>(); // <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>1<EFBFBD>б<EFBFBD>
|
|
|
|
|
private JSONReader jsonReader; // JSON <20><><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1>
|
2024-12-11 20:16:45 +08:00
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
public void SetInfo(int id, JSONReader reader)
|
2024-12-11 20:16:45 +08:00
|
|
|
|
{
|
|
|
|
|
taskId = id;
|
2024-12-13 17:19:27 +08:00
|
|
|
|
jsonReader = reader;
|
|
|
|
|
LoadTaskData();
|
2024-12-11 20:16:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
private void LoadTaskData()
|
2024-12-11 14:24:06 +08:00
|
|
|
|
{
|
2024-12-13 17:19:27 +08:00
|
|
|
|
Task_ info = jsonReader.GetTaskByID(taskId);
|
|
|
|
|
taskName = info.Note;
|
|
|
|
|
state = TaskState.NotStarted;
|
2024-12-11 14:24:06 +08:00
|
|
|
|
|
2024-12-16 15:28:35 +08:00
|
|
|
|
Debug.Log(info.Targets1);
|
2024-12-11 20:54:34 +08:00
|
|
|
|
|
2024-12-06 11:29:20 +08:00
|
|
|
|
UpdateTxt();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|
|
|
|
public void UpdateTxt()
|
2024-12-06 11:29:20 +08:00
|
|
|
|
{
|
2024-12-13 17:19:27 +08:00
|
|
|
|
string progressInfo = "";
|
|
|
|
|
foreach (var target in Targets)
|
|
|
|
|
{
|
|
|
|
|
progressInfo += $"{target.Description}: {target.CurrentProgress}/{target.RequiredProgress}\n";
|
|
|
|
|
}
|
2024-12-16 15:28:35 +08:00
|
|
|
|
Debug.Log(taskName);
|
|
|
|
|
Debug.Log(progressInfo);
|
|
|
|
|
taskTxt.text = $"{taskName}";
|
2024-12-12 14:50:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 17:19:27 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public void UpdateProgress(TargetType targetType, string targetId, int value)
|
2024-12-06 11:29:20 +08:00
|
|
|
|
{
|
2024-12-13 17:19:27 +08:00
|
|
|
|
TaskTarget target = Targets.Find(t => t.Type == targetType && t.TargetID == targetId);
|
|
|
|
|
if (target != null)
|
|
|
|
|
{
|
|
|
|
|
target.UpdateProgress(value);
|
|
|
|
|
UpdateTxt();
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (Targets.TrueForAll(t => t.IsCompleted))
|
|
|
|
|
{
|
|
|
|
|
state = TaskState.Completed;
|
|
|
|
|
TaskPanel.instance.RemoveTask(taskId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-06 11:29:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|