Files
test/Assets/PerfectWorld/Scripts/Task/UI/DlgTaskTrace.cs
2026-04-13 12:31:49 +07:00

1058 lines
48 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BrewMonster.UI;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
using CSNetwork.GPDataType;
using BrewMonster.Network;
using ModelRenderer.Scripts.GameData;
using ModelRenderer.Scripts.Common;
using PerfectWorld.Scripts.Managers;
using BrewMonster.Scripts.Managers;
using BrewMonster.Scripts.World;
using BrewMonster.Scripts.UI;
namespace BrewMonster.Scripts.Task.UI
{
public enum ShowType
{
ST_NONE, // ʼֵ
ST_TRACED, // ʾǰ׷
ST_TITLE, // ʾѽӳƺ
ST_CONTRIBUTION, // ʾѵĹ׶
}
//New show type in Unity version
public enum ShowType2
{
ST_NONE,
ST_RECIEVED,
ST_NOT_RECIEVED,
}
public class DlgTaskTrace : DlgNameLink
{
static string COLOR_YELLOW = "<color=#ffcb4a>";
static string COLOR_RED = "<color=#ff0000>";
static string COLOR_WHITE = "<color=#FFFFFF>";
static string INDENTATION = " ";
protected StringRef m_Buffer;
[SerializeField] protected StyledTaskTraceText m_pTxt_Desc;
protected Dictionary<string, int> m_uniqueNameCountMap = new Dictionary<string, int>();
// [SerializeField] protected Button m_pBtnUnTrace;
// [SerializeField] protected Button m_pBtnMap;
// [SerializeField] protected Button m_pBtnChat;
[SerializeField] protected Button m_pBtnFinishTaskByContribution;
[SerializeField] protected Button m_pBtnContributionTaskHelp;
[SerializeField] protected Toggle m_pToggleReceived;
[SerializeField] protected Toggle m_pToggleNotReceived;
protected int m_nLastTracedTasks; // ʾݶӦ׷ijЩбл
protected ShowType m_nLastShowType; // ʾݶӦб
protected ShowType2 m_nLastShowType2;
protected int m_nTraceWorldID; // ʾϢ׷ϢӦĵͼID
protected int m_iContributionCurrentPage;
protected int m_iContributionTotalPage;
protected int m_iIndexForContribution;
protected bool m_bShowTrace;
public void Awake()
{
//AUI_ON_COMMAND("Chk_Collapse", OnCommand_SwitchCollapse);
//m_pChk_Collapse.onValueChanged.AddListener(OnCommand_SwitchCollapse);
//AUI_ON_COMMAND("Rdo_Quest*", OnCommand_SwitchShowType)
//Not sure if we need this
//AUI_ON_COMMAND("Btn_UnTrace", OnCommand_UnTraceTask)
// m_pBtnUnTrace.onClick.AddListener(OnCommand_UnTraceTask);
// //AUI_ON_COMMAND("Btn_Map", OnCommand_Map)
// m_pBtnMap.onClick.AddListener(OnCommand_Map);
// //AUI_ON_COMMAND("Btn_ForChat", OnCommand_Chat)
// m_pBtnChat.onClick.AddListener(UpdateContributionTask);
//AUI_ON_COMMAND("Btn_Finish", OnCommand_FinishTask)
//m_pBtnFinishTaskByContribution.onClick.AddListener(() => OnCommand_FinishTask(null));
// AUI_ON_EVENT("Edit_Title", WM_LBUTTONDBLCLK, OnEventDBClk_Title)
// AUI_ON_EVENT("Txt_Title", WM_LBUTTONDBLCLK, OnEventDBClk_Title)
// AUI_ON_EVENT("Txt_Link_Trace", WM_RBUTTONDOWN, OnEventRButton_Txt_Link_Trace)
// AUI_ON_EVENT("Txt_Link_Trace", WM_RBUTTONUP, OnEventRButton_Txt_Link_Trace)
// AUI_ON_EVENT("Txt_Link_Trace", WM_LBUTTONDOWN, OnEventLButton_Txt_Link_Trace)
// AUI_ON_EVENT("Txt_Link_Trace", WM_LBUTTONUP, OnEventLButton_Txt_Link_Trace)
// AUI_ON_EVENT("Txt_Link_Trace", WM_MOUSEWHEEL, OnMouseWheel)
}
public override void Show(bool value)
{
// RefreshTaskTrace calls Show(true) every tick while visible; do not reset filter or re-wire toggles then.
// RefreshTaskTrace 每帧对已显示窗口调用 Show(true);勿重置“已接/可接”筛选,也勿重复注册 Toggle。
bool wasActive = gameObject.activeSelf;
gameObject.SetActive(value);
m_bShow = value;
if (value && !wasActive)
m_nLastShowType2 = ShowType2.ST_RECIEVED;
// Remove-before-Add in OnShowDialogue keeps this safe when RefreshTaskTrace calls Show(true) every frame.
OnShowDialogue();
}
public override void OnShowDialogue()
{
base.OnShowDialogue();
if (m_pToggleReceived != null && m_pToggleNotReceived != null)
{
m_pToggleReceived.onValueChanged.RemoveListener(OnToggleReceivedValueChanged);
m_pToggleNotReceived.onValueChanged.RemoveListener(OnToggleNotReceivedValueChanged);
if (m_bShow)
{
m_pToggleReceived.onValueChanged.AddListener(OnToggleReceivedValueChanged);
m_pToggleNotReceived.onValueChanged.AddListener(OnToggleNotReceivedValueChanged);
}
}
//m_pTxt_Desc = dynamic_cast<PAUITEXTAREA>(GetDlgItem("Txt_Link_Trace"));
//if(m_pTxt_Desc) m_pTxt_Desc->SetForceRenderScroll(false);
//m_pChk_Collapse = dynamic_cast<PAUICHECKBOX>(GetDlgItem("Chk_Collapse"));
// if (m_szName == "Win_QuestMinion") {
// m_pBtnUnTrace.gameObject.SetActive(false);
// m_pBtnMap.gameObject.SetActive(false);
// m_pBtnChat.gameObject.SetActive(false);
// m_pBtnFinishTaskByContribution.gameObject.SetActive(false);
// m_pBtnContributionTaskHelp.gameObject.SetActive(false);
// }
// GameObject pObjRadio = transform.Find("Rdo_Quest1").gameObject;
// if (pObjRadio) SetShowType(ShowType.ST_TRACED);
// pObjRadio = transform.Find("Rdo_Quest2").gameObject;
// if (pObjRadio) pObjRadio.gameObject.SetActive(
// //todo: get from config
// //CECUIConfig::Instance().GetGameUI().bEnableTitle
// true
// );
// ׷ٽʾĬб
}
public void OnToggleReceivedValueChanged(bool value)
{
if(value)
{
m_nLastShowType2 = ShowType2.ST_RECIEVED;
}
}
public void OnToggleNotReceivedValueChanged(bool value)
{
if(value)
{
m_nLastShowType2 = ShowType2.ST_NOT_RECIEVED;
DlgTask.RebuildAcceptableQuestCache();
}
}
public void OnShowDialog()
{
GameObject pObjRadio = transform.Find("Rdo_Quest3").gameObject;
if (pObjRadio) {
int levelLimit =
//todo: get from config
//CECUIConfig::Instance().GetGameUI().nContributionTaskLevelLimit
0;
CECHostPlayer pHost = GetHostPlayer();
if (pHost && pHost.GetMaxLevelSofar() >= levelLimit)
pObjRadio.gameObject.SetActive(true);
}
}
private void OnChangeLayoutEnd(bool bAllDone)
{
if (m_szName == "Win_QuestMinion" && !m_bShowTrace) {
// Vector2 cur = this->GetSize();
// Vector2 desc = m_pTxt_Desc->GetSize();
// cur.cy -= desc.cy;
// this->SetSize(cur.cx, cur.cy);
// m_pChk_Collapse->Check(false);
}
}
public void RefreshTaskTrace(int[] traced, int nTraced, int[] titletasks, int num, bool withName)
{
if(!m_bShow)
return;
ShowType showType = GetShowType();
m_pTxt_Desc.RefreshLinkCommands();
if (nTraced == 0 && num == 0)
{
return;
}
int size = 0;
int[] tasks = null;
if (showType == ShowType.ST_NONE) {
showType = ShowType.ST_TRACED;
}
switch (showType)
{
case ShowType.ST_TRACED: size = nTraced; tasks = traced; break;
case ShowType.ST_TITLE: size = num; tasks = titletasks; break;
}
//bool bShow = !GetGameUIMan()->IsCustomizeCharacter();
//if(IsShow() != bShow) Show(bShow);
Show(true);
int idWorld = 0;
var gameRun = EC_Game.GetGameRun();
if (gameRun != null && gameRun.GetWorld() != null)
{
idWorld = gameRun.GetWorld().GetInstanceID();
}
else if (CECGameRun.Instance?.GetWorld() != null)
{
idWorld = CECGameRun.Instance.GetWorld().GetInstanceID();
}
if (IsShow())
{ // ѽϢʵʱ
if (m_nTraceWorldID != idWorld || // ͼб䣬׷Ϣ
showType == ShowType.ST_TRACED || // ѽϢʵʱ
showType == ShowType.ST_TITLE) // ѽӳƺϢʵʱ
{
PrepareRebuildTaskTrace();
for (int i = size-1; i >= 0; i--)
{
FormatTaskTraceDesc(tasks[i], withName, "", false, size - i);
}
KeepScrollBarPosition();
m_nTraceWorldID = idWorld;
}
}
m_nLastTracedTasks = nTraced;
m_pTxt_Desc.Set(m_Buffer.Value);
}
public void RefreshTaskTrace(int[] tasks, int size, bool withName)
{
bool bShow = size > 0;
// show/hide the trace dialog
if(IsShow() != bShow)
{
Show(bShow);
}
if (!IsShow())
return;
PrepareRebuildTaskTrace();
// get the formatted desc
for(int i=(int)size-1; i>=0; i--)
{
FormatTaskTraceDesc(tasks[i], withName, "");
}
m_pTxt_Desc.Set(m_Buffer.Value);
}
public void SetShowType(ShowType rhs)
{
int nCheck = 0;
switch (rhs)
{
case ShowType.ST_TRACED:
nCheck = 0; break;
case ShowType.ST_TITLE:
nCheck = 1; break;
case ShowType.ST_CONTRIBUTION:
nCheck = 2; break;
default: Debug.LogError("Invalid show type"); break;
}
//todo: check radio button
//CheckRadioButton(0, nCheck);
m_nLastShowType = rhs;
}
protected void AppendCommand(string pName, int idTarget, int idTask)
{
string strName = pName;
if(!string.IsNullOrEmpty(strName))
{
//todo: MakeNameUnique(not implemented)
string strUniqueName = MakeNameUnique(strName);
if (!string.IsNullOrEmpty(strUniqueName)){
//Currently get npc method is bugging so BindlinkCommand cant not get true format of this sting.
//BUG: EC_Game.GetTaskTemplateMan().TryGetTaskNPCInfo((uint)idTarget, out NPC_INFO pInfo)
//Work around by using this magic string to give us the visual effect of the link.
//TODO: Fix the Get npc method bug.
strUniqueName = string.Format("<color=#FFA500><u><link=\"npc\">{0}</link></u></color>",strUniqueName);
TraceLinkCommand cmd = new TraceLinkCommand(m_Buffer, idTarget, strUniqueName, idTask);
m_pTxt_Desc.AddLinkCommand(cmd);
BindLinkCommand(m_pTxt_Desc.tmp, strUniqueName, cmd);
}
}
}
public void AppendCommand(int worldid, Task_Region[] pRegions, int size)
{
List<OBJECT_COORD> instCoord = new List<OBJECT_COORD>(), tempCoord = new List<OBJECT_COORD>();
int cur = CECGameRun.Instance?.GetWorld()?.GetInstanceID() ?? 161;
CECInstance pInstance = EC_Game.GetGameRun().GetInstance(cur);
string strCurMap = pInstance.GetPath();
// find the entrance of instance
pInstance = EC_Game.GetGameRun().GetInstance(worldid);
string mapName = pInstance != null ? pInstance.GetPath() : "";
if(cur != worldid)
{
EC_Game.GetObjectCoord(mapName, out tempCoord);
var iter = tempCoord.Find(coord => coord.strMap == strCurMap);
instCoord.Add(iter);
}
else if(size > 0 && pRegions != null)
{
for(int i=0;i<size;i++)
{
Task_Region reg = pRegions[i];
OBJECT_COORD coor = new OBJECT_COORD();
coor.strMap = mapName;
coor.vPos.x = (reg.zvMax.x - reg.zvMin.x) / 2 + reg.zvMin.x;
coor.vPos.y = (reg.zvMax.y - reg.zvMin.y) / 2 + reg.zvMin.y;
coor.vPos.z = (reg.zvMax.z - reg.zvMin.z) / 2 + reg.zvMin.z;
instCoord.Add(coor);
}
}
// find the targets
if(instCoord.Count > 0)
{
string strName;
A3DVECTOR3 vPos = instCoord[0].vPos;
strName = FormatFromTable(9393, ((int)vPos.x+4000)/10, ((int)vPos.z+5500)/10);
strName = string.Format("<link=\"coord\">{0}</link>", strName);
//FormatFromTable(9393, ((int)vPos.x+4000)/10, ((int)vPos.z+5500)/10);
TraceLinkCommand cmd = new TraceLinkCommand(m_Buffer, instCoord, strName);
m_pTxt_Desc.AddLinkCommand(cmd);
BindLinkCommand(m_pTxt_Desc.tmp, strName, cmd);
}
}
void ResetNameUnique(){
m_uniqueNameCountMap.Clear();
}
string MakeNameUnique(string strName)
{
string result = strName;
// if (!strName.IsEmpty())
// {
// ACString strTrimmedName = strName;
// strTrimmedName.TrimLeft();
// strTrimmedName.TrimRight();
// if (!strTrimmedName.IsEmpty()){
// UniqueNameCountMap::iterator it = m_uniqueNameCountMap.find(strTrimmedName);
// if (it == m_uniqueNameCountMap.end()){
// m_uniqueNameCountMap[strTrimmedName] = 1;
// }else{
// ++ it->second;
// }
// result = strTrimmedName;
// if (int spaceCount = m_uniqueNameCountMap[strTrimmedName]-1){
// ACString strMakeUniqueSuffix(_AL(' '), spaceCount);
// result += strMakeUniqueSuffix;
// }
// }
// }
return result;
}
void AppendText(string text)
{
m_Buffer.Value += text;
}
public ShowType GetShowType()
{
return m_nLastShowType;
}
public ShowType2 GetShowType2()
{
return m_nLastShowType2;
}
void PrepareRebuildTaskTrace(){
m_Buffer = new StringRef();
m_Buffer.Value = "";
ClearCommands();
ResetNameUnique();
}
void DeleteColorStr(string strName)
{
//Delete all ^ffffff
if (strName.StartsWith("^")) {
strName = strName.Substring(7);
}
}
void OnCommand_UnTraceTask(string szCommand)
{
LinkCommand cmd = GetLinkCommand(m_pTxt_Desc.tmp, szCommand);
if (cmd != null) {
cmd.Execute(m_pTxt_Desc.tmp);
}
}
void FinishTaskSpendingContribution(int taskID)
{
var pTask = GetHostPlayer().GetTaskInterface();
var pMan = EC_Game.GetTaskTemplateMan();
var pTemp = pMan.GetTaskTemplByID((uint)taskID);
var pActiveLst = pTask.GetActiveTaskList();
var pEntry = pActiveLst.GetEntry((uint)taskID);
if (pTemp!=null && pEntry!=null && !pEntry.IsFinished()) {
if (pTemp.m_Award_S.m_ulCandItems > 1) {
//TODO: add Win_Award dialog
var pAward = GetGameUIMan().GetDialog("Win_Award");
if (pAward != null) {
//pAward.UpdateAwardItem(taskID, false, true);
//pAward.Show(true);
}
}
else pTask.FinishTaskSpendingWorldContribution(taskID);
UpdateContributionTask();
}
}
public void UpdateContributionTask()
{
if (GetShowType() != ShowType.ST_CONTRIBUTION)
{
//return;
}
var pHost = GetHostPlayer();
var pTask = pHost.GetTaskInterface();
var pStorageList = pTask.GetStorageTaskList();
var pActiveLst = pTask.GetActiveTaskList();
var pTaskMan = EC_Game.GetTaskTemplateMan();
var pElementDataMan = EC_Game.GetElementDataMan();
PrepareRebuildTaskTrace();
// ʾ׶Ⱥѹ׶
string strText;
strText = string.Format("{0}{1}{2}{3} {4}{5}{6}{7}/{8}", GetStringFromTable(11289), GetStringFromTable(11280),
GetStringFromTable(11292), pHost.GetWorldContribution(), GetStringFromTable(11289), GetStringFromTable(11281),
GetStringFromTable(11292), pHost.GetWorldContributionSpend(),
pHost.HaveHealthStones() ? 9999 : TaskInterfaceConstants.TASK_WORLD_CONTRIBUTION_SPEND_PER_DAY);
AppendText(strText);
AppendText("\n");
m_iIndexForContribution = 0;
bool storageListCheck = pStorageList.m_StoragesTaskSetCount.Length > 0;
bool taskListCheck = pActiveLst.m_TaskEntries.Length > 0;
if (storageListCheck && taskListCheck && pElementDataMan != null && pActiveLst != null) {
int weightTaskStorageCount = 0;
for (int i = 1; i <= TaskInterfaceConstants.TASK_STORAGE_COUNT; ++i) {
var pEssence = pTaskMan.GetWeightTasksEssence((uint)i, out bool result);
if (result) {
if (m_iContributionCurrentPage == weightTaskStorageCount) {
var TaskSetIDs = new HashSet<int>();
var TaskIDs = new HashSet<int>();
// ׶ȵ
for (int j = 0; j < pStorageList.m_StoragesTaskSetCount[i - 1]; ++j) {
int id = pStorageList.m_Storages[(i - 1) * TaskTemplConstants.TASK_STORAGE_LEN + j];
if (id == 0) break;
AddTaskSetString(id, true, i);
TaskSetIDs.Add(id);
}
for (int j = pStorageList.m_StoragesTaskSetCount[i - 1]; j < TaskTemplConstants.TASK_STORAGE_LEN; ++j) {
int id = pStorageList.m_Storages[(i - 1) * TaskTemplConstants.TASK_STORAGE_LEN + j];
if (id == 0) break;
AddTaskString(id, true, INDENTATION, true);
TaskIDs.Add(id);
}
AppendText(GetStringFromTable(11290));
// ׶ȵȡδɵ
var aEntries = pActiveLst.m_TaskEntries;
var count = pEssence.uniform_weight_list.Length;
for (int j = 0; j < pActiveLst.m_uTaskCount; ++j) {
var CurEntry = aEntries[j];
if (CurEntry.IsFinished())
continue;
int id = CurEntry.m_ID;
for (int k = 0; k < count; ++k) {
int taskSetID = (int)pEssence.uniform_weight_list[k].task_list_config_id;
if (taskSetID == 0) break;
if (!TaskSetIDs.Contains(taskSetID) && TaskListHasID(taskSetID, id)) {
AddTaskSetString(taskSetID, false, i);
TaskSetIDs.Add(taskSetID);
}
}
if (!TaskIDs.Contains(id) && TaskListHasID((int)pEssence.other_task_list_config_id, id)) {
AddTaskString(id, false, INDENTATION, true);
TaskIDs.Add(id);
}
}
// ׶ȵ
for (int j = 0; j < (int)count; ++j) {
int id = (int)pEssence.uniform_weight_list[j].task_list_config_id;
if (!TaskSetIDs.Contains(id))
AddTaskSetString(id, false, i);
}
DATA_TYPE dt = DATA_TYPE.DT_INVALID;
var temp = pElementDataMan.get_data_ptr(pEssence.other_task_list_config_id, ID_SPACE.ID_SPACE_CONFIG, ref dt);
if (temp == null && dt != DATA_TYPE.DT_TASK_LIST_CONFIG) {
return;
}
var pConfig = (TASK_LIST_CONFIG)temp;
if (dt == DATA_TYPE.DT_TASK_LIST_CONFIG) {
count = pConfig.id_tasks.Length;
for (int j = 0; j < (int)count; ++j) {
int id = (int)pConfig.id_tasks[j];
if (id == 0) break;
if (!TaskIDs.Contains(id))
AddTaskString(id, false, INDENTATION, true);
}
}
}
weightTaskStorageCount++;
}
}
m_iContributionTotalPage = weightTaskStorageCount;
}
KeepScrollBarPosition();
}
bool TaskListHasID(int listID, int taskID)
{
var pElementDataMan = ElementDataManProvider.GetElementDataMan();
DATA_TYPE dt = DATA_TYPE.DT_INVALID;
var temp = pElementDataMan.get_data_ptr((uint)listID, ID_SPACE.ID_SPACE_CONFIG, ref dt);
if (temp == null && dt != DATA_TYPE.DT_TASK_LIST_CONFIG) {
return false;
}
var pConfig = (TASK_LIST_CONFIG)temp;
if (dt == DATA_TYPE.DT_TASK_LIST_CONFIG) {
var count = pConfig.id_tasks.Length;
for (int i = 0; i < count; ++i) {
int id = (int)pConfig.id_tasks[i];
if (id == 0) break;
if (id == taskID)
return true;
}
}
return false;
}
void AddTaskSetString(int id, bool hasContributionAward, int idStorage)
{
var pElementDataMan = ElementDataManProvider.GetElementDataMan();
var pTask = GetHostPlayer().GetTaskInterface();
var pActiveLst = pTask.GetActiveTaskList();
var dt = DATA_TYPE.DT_INVALID;
var temp = pElementDataMan.get_data_ptr((uint)id, ID_SPACE.ID_SPACE_CONFIG, ref dt);
if (temp == null && dt != DATA_TYPE.DT_TASK_LIST_CONFIG)
{
return;
}
var pConfig = (TASK_LIST_CONFIG)temp;
var pStorage = EC_Game.GetTaskTemplateMan().GetWeightTasksEssence((uint)idStorage, out bool result);
//pconfig is check null above so skip check here
if (result) {
var count = pStorage.uniform_weight_list.Length;
int weight = 0;
for (int i = 0; i < count; ++i) {
if(pStorage.uniform_weight_list[i].task_list_config_id == 0) {
Debug.LogError("Uniform weight list task config id is 0");
return;
}
if (pStorage.uniform_weight_list[i].task_list_config_id == id) {
weight = pStorage.uniform_weight_list[i].weight;
break;
}
}
string strColor;
if (hasContributionAward) {
strColor = GetStringFromTable(11286);
AppendText(strColor);
AppendText(GetStringFromTable(11284));
} else {
weight = -weight;
strColor = GetStringFromTable(11287);
AppendText(strColor);
AppendText(GetStringFromTable(11285));
}
string strName = pConfig.Name;
AppendText(strColor + strName);
var aEntries = pActiveLst.m_TaskEntries;
for (int i = 0; i < pActiveLst.m_uTaskCount; ++i) {
var CurEntry = aEntries[i];
int taskID = CurEntry.m_ID;
for (int j = 0; j < pConfig.id_tasks.Length; ++j) {
if (pConfig.id_tasks[j] == taskID) {
AddTaskString(taskID, hasContributionAward, INDENTATION);
break;
}
}
}
}
}
void AddTaskString(int id, bool hasContributionAward, string strIndentIn, bool topLevel = false)
{
var pTask = GetHostPlayer().GetTaskInterface();
var pTaskMan = EC_Game.GetTaskTemplateMan();
var pActiveLst = pTask.GetActiveTaskList();
var pTempl = pTaskMan.GetTaskTemplByID((uint)id);
var pEntry = pActiveLst.GetEntry((uint)id);
if (pTempl != null) {
// 任务名与描述都为空时不显示(数据缺失或损坏) / Hide when both name and description are empty (missing or corrupt data)
if (string.IsNullOrWhiteSpace(pTempl.GetName()) && string.IsNullOrWhiteSpace(pTempl.GetDescription()))
return;
int contribution = 0;
// ׶ȵֻڶʾֵ
if (hasContributionAward) {
contribution = pTempl.m_pParent == null ? pTempl.m_Award_S.m_iWorldContribution : 0;
} else { // ֻײʾֵ
//not sure it is m_fixed data or not
//contribution = pTempl->m_pFirstChild == NULL ? -pTempl->m_iWorldContribution : 0;
contribution = pTempl.m_pFirstChild == null ? -pTempl.m_FixedData.m_iWorldContribution : 0;
}
bool bCanContributionFinish = !hasContributionAward;
// ACString strTask = pTempl->GetName();
string strTask = CECUIHelper.FormatCoordText(pTempl.GetDescription());
// ʾһ
if (topLevel)
{
int indexMark = hasContributionAward ? 11284 : 11285;
int indexColor = bCanContributionFinish ? 11287 : 11286;
AppendText(GetStringFromTable(indexColor));
AppendText(GetStringFromTable(indexMark));
AppendColorText(strTask, GetStringFromTable(indexColor));
}
// ǽ׶ȵȡʱǵʾ
//Todo: this is for event quest. not implemented yet
// if (hasContributionAward && pEntry != null) {
// ulong ulCurTime = pTask.GetCurTime();
// unsigned long ulTaskTime = pEntry->m_ulTaskTime;
// tm tmCur, tmTask;
// ulCurTime -= unsigned long(TaskInterface::GetTimeZoneBias() * 60);
// ulTaskTime -= unsigned long(TaskInterface::GetTimeZoneBias() * 60);
// if ((long)(ulCurTime) < 0)
// ulCurTime = 0;
// if ((long)(ulTaskTime) < 0)
// ulTaskTime = 0;
// tmCur = *gmtime((time_t*)&ulCurTime);
// tmTask = *gmtime((time_t*)&ulTaskTime);
// if (!(tmCur.tm_year == tmTask.tm_year && tmCur.tm_yday == tmTask.tm_yday))
// return;
// }
if (pTask.HasTask((uint)id)) {
FormatTaskTraceDesc((int)pTempl.m_ID, true, strIndentIn, false, ++m_iIndexForContribution, bCanContributionFinish, contribution);
}
var aEntries = pActiveLst.m_TaskEntries;
for (int j = 0; j < pActiveLst.m_uTaskCount; ++j) {
var CurEntry = aEntries[j];
int taskID = CurEntry.m_ID;
if (CurEntry.m_ParentIndex != 0xff) {
var ParentEntry = aEntries[CurEntry.m_ParentIndex];
if (ParentEntry.m_ID == id)
AddTaskString(taskID, hasContributionAward, strIndentIn + INDENTATION);
}
}
}
}
void AppendColorText(string strTask, string strColor)
{
DeleteColorStr(strTask);
string strText = strColor + strTask;
AppendText(strText);
AppendText("\n");
}
void FormatTaskTraceDesc(int idTask, bool withName, string strIndentIn, bool requireActive = false, int index = 0, bool bCanContributionFinish = false, int contribution = 0)
{
int j;
ATaskTemplMan pMan = EC_Game.GetTaskTemplateMan();
elementdataman pDataMan = EC_Game.GetElementDataMan();
CECTaskInterface pTask = GetHostPlayer().GetTaskInterface();
CECGameUIMan pUIMan = GetGameUIMan();
bool bActiveTask = pTask.HasTask((uint)idTask);
if (requireActive && !bActiveTask) return;
ATaskTempl pTemp = pMan.GetTaskTemplByID((uint)idTask);
if (pTemp != null)
{
Task_State_info tsi=default;
pTask.GetTaskStateInfo((uint)idTask, ref tsi, bActiveTask);
// check if the task is in the reach site
float[] vMin = new float[3] {-6000.0f,-6000.0f,-6000.0f};
float[] vMax = new float[3] {6000.0f,6000.0f,6000.0f};
if(pTemp.m_FixedData.m_ulReachSiteCnt > 0
&& pTemp.is_in_zone(pTemp.m_FixedData.m_pReachSite[0].zvMin,pTemp.m_FixedData.m_pReachSite[0].zvMax,vMin)
&& pTemp.is_in_zone(pTemp.m_FixedData.m_pReachSite[0].zvMin,pTemp.m_FixedData.m_pReachSite[0].zvMax,vMax))
return;
// append the name
if (withName)
{
AppendText(strIndentIn);
string strName = pTemp.GetName();
DeleteColorStr(strName);
strName = " " + strName;
TaskNameHoverCommand cmd = new TaskNameHoverCommand(m_Buffer, strName, idTask, tsi.m_ulErrCode != 0, bCanContributionFinish);
BindLinkCommand(m_pTxt_Desc.tmp, strName, cmd);
if (contribution != 0) {
int colorIndex = contribution > 0 ? 11288 : 11291;
strName = string.Format(" {0} {1}", GetStringFromTable(colorIndex), contribution);
AppendText(strName);
}
AppendText("\n");
}
// init the indent
string strIndent = withName ? strIndentIn + INDENTATION : "";
// δʱʾNPC
int nDNPC = (int)pTemp.GetDeliverNPC();
if (!bActiveTask && nDNPC > 0)
{
DATA_TYPE dt = DATA_TYPE.DT_INVALID;
var temp = pDataMan.get_data_ptr((uint)nDNPC, ID_SPACE.ID_SPACE_ESSENCE, ref dt);
if(temp == null && dt != DATA_TYPE.DT_NPC_ESSENCE) {
return;
}
var pNPC = (NPC_ESSENCE)temp;
if (dt == DATA_TYPE.DT_NPC_ESSENCE)
{
AppendText(strIndent);
AppendText(GetStringFromTable(9764));
AppendCommand(pNPC.Name, nDNPC, idTask);
AppendText("\n");
}
}
// check whether can finish the task
ulong nANPC = pTemp.GetAwardNPC();
// ͱȽʱҪ
bool bSpecialAwardType = pTemp.GetAwardType_S() != (uint)TaskAwardType.enumTATNormal;
if(nANPC > 0 && pTask.CanFinishTask((uint)idTask) && !bSpecialAwardType)
{
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
var temp = pDataMan.get_data_ptr((uint)nANPC, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
if(temp == null && DataType != DATA_TYPE.DT_NPC_ESSENCE) {
return;
}
var pNPC = (NPC_ESSENCE)temp;
if (DataType == DATA_TYPE.DT_NPC_ESSENCE)
{
AppendText(strIndent);
AppendText(GetStringFromTable(9391));
AppendCommand(pNPC.Name, (int)nANPC, idTask);
AppendText("\n");
return;
}
}
// append global task character
for(int i = 0; i < (int)tsi.m_TaskCharArr._finish; i++)
{
string strPrefix = strIndent;
strPrefix += "<color=#00FF00>";
strPrefix += tsi.m_TaskCharArr._start + i;
strPrefix += "\n";
AppendText(strPrefix);
}
for( j = 0; j < TaskInterfaceConstants.MAX_ITEM_WANTED; j++ )
{
uint itemid = tsi.m_ItemsWanted[j].m_ulItemId;
if( itemid <= 0 )
break;
uint gained = tsi.m_ItemsWanted[j].m_ulItemsGained;
uint toget = tsi.m_ItemsWanted[j].m_ulItemsToGet;
EC_IvtrItem pItem = EC_IvtrItem.CreateItem((int)itemid, 0, 1);
if (pItem != null)
{
string strPrefix = strIndent;
if( gained < toget )
strPrefix += COLOR_WHITE;
else
strPrefix += "<color=#00e83a>";
AppendText(strPrefix);
// track the monster id which contains this item
uint monid = tsi.m_ItemsWanted[j].m_ulMonsterId;
string strName;
if (pTemp.m_FixedData.m_enumMethod != (uint)TaskCompletionMethod.enumTMKillPlayer)
{
if(monid > 0)
{
AppendText(GetStringFromTable(9388));
AppendCommand(pItem.GetName(), (int)monid, idTask);
strName = FormatFromTable(9389, gained, toget);
}
else
{
MINE_ESSENCE pMine = DlgTask.SearchTaskMine(idTask, out bool found);
if(found)
{
AppendText(GetStringFromTable(9388));
AppendCommand(pItem.GetName(), (int)pMine.id, idTask);
strName = FormatFromTable(9389, gained, toget);
}
else
{
strName = FormatFromTable(248, pItem.GetName(), gained, toget);
}
}
}
else
{
AppendText(GetStringFromTable(9388));
AppendText(pItem.GetName());
strName = FormatFromTable(9389, gained, toget);
strName += GetKillPlayerRequirements(tsi,j);
}
AppendText(strName);
}
}
for (j = 0; j < TaskInterfaceConstants.MAX_MONSTER_WANTED; j++)
{
int monid = (int)tsi.m_MonsterWanted[j].m_ulMonsterId;
if (monid == 0)
break;
int killed = (int)tsi.m_MonsterWanted[j].m_ulMonstersKilled;
int tokill = (int)tsi.m_MonsterWanted[j].m_ulMonstersToKill;
if(killed > 0 || tokill > 0 )
{
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
var temp = pDataMan.get_data_ptr((uint)monid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
if(temp == null && DataType != DATA_TYPE.DT_MONSTER_ESSENCE) {
return;
}
var pMonster = (MONSTER_ESSENCE)temp;
string strPrefix = strIndent;
if(killed < tokill )
strPrefix += COLOR_WHITE;
else
strPrefix += "<color=#00e83a>";
AppendText(strPrefix);
string strName;
if( DataType == DATA_TYPE.DT_MONSTER_ESSENCE )
{
// trace the monster
AppendText(GetStringFromTable(9386));
AppendCommand(pMonster.Name, (int)pMonster.id, idTask);
strName = FormatFromTable(9387, killed, tokill);
}
else
{
strName = FormatFromTable(256, killed);
}
AppendText(strName);
}
}
for(int i = 0; i < TaskInterfaceConstants.MAX_PLAYER_WANTED; i++ )
{
if (tsi.m_PlayerWanted[i].m_ulPlayersToKill == 0)
break;
if (tsi.m_ItemsWanted[i].m_ulItemId > 0)
{
continue;
}
int killed = (int)tsi.m_PlayerWanted[j].m_ulPlayersKilled;
int tokill = (int)tsi.m_PlayerWanted[j].m_ulPlayersToKill;
string strPrefix = strIndent;
if(killed < tokill )
strPrefix += COLOR_WHITE;
else
strPrefix += "<color=#00e83a>";
AppendText(strPrefix);
AppendText(GetStringFromTable(7630));
AppendText(GetKillPlayerRequirements(tsi,i));
}
if( tsi.m_ulTimeLimit > 0 )
{
int nSec = bActiveTask ? Mathf.Max(0, (int)tsi.m_ulTimeLimit - (int)tsi.m_ulTimePassed) : (int)tsi.m_ulTimeLimit;
string strPrefix = strIndent;
strPrefix += DlgTask.FormatTime(nSec, GetStringFromTable(bActiveTask ? 246 : 245), (int)tsi.m_ulTimeLimit);
AppendText(strPrefix);
}
if( tsi.m_ulWaitTime > 0 )
{
int nSec = Mathf.Max(0, (int)tsi.m_ulWaitTime - (int)tsi.m_ulTimePassed);
string strPrefix = strIndent + COLOR_WHITE;
strPrefix += DlgTask.FormatTime(nSec, GetStringFromTable(199), 0);
AppendText(strPrefix);
}
if( tsi.m_ulNPCToProtect > 0 )
{
AppendText(strIndent);
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
var temp = pDataMan.get_data_ptr((uint)tsi.m_ulNPCToProtect, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
if(temp == null && DataType != DATA_TYPE.DT_MONSTER_ESSENCE) {
return;
}
var pMonster = (MONSTER_ESSENCE)temp;
if( DataType == DATA_TYPE.DT_MONSTER_ESSENCE )
{
// trace the protected npc
AppendText(GetStringFromTable(9390));
AppendCommand(pMonster.Name, (int)pMonster.id, idTask);
AppendText("\n");
}
// update protected time
int nSec = Mathf.Max(0, (int)tsi.m_ulProtectTime - (int)tsi.m_ulTimePassed);
string strTime = DlgTask.FormatTime(nSec, GetStringFromTable(259), (int)tsi.m_ulProtectTime);
AppendText(strTime);
}
if(pTemp.m_FixedData.m_ulReachSiteCnt > 0)
{
AppendText(strIndent);
AppendText(GetStringFromTable(9392));
AppendCommand((int)pTemp.m_FixedData.m_ulReachSiteId, pTemp.m_FixedData.m_pReachSite, (int)pTemp.m_FixedData.m_ulReachSiteCnt);
AppendText("\n");
}
var pHost = GetHostPlayer();
string strTemp = string.Empty;
if (pTemp.m_FixedData.m_ulReachLevel > 0)
{
AppendText(strIndent);
strTemp = FormatFromTable(9396, pHost.GetBasicProps().iLevel, pTemp.m_FixedData.m_ulReachLevel);
AppendText(strTemp);
AppendText("\n");
}
if (pTemp.m_FixedData.m_ulReachRealmLevel > 0)
{
AppendText(strIndent);
strTemp = FormatFromTable(9397,
pUIMan.GetRealmName(pHost.GetRealmLevel()), pUIMan.GetRealmName((int)pTemp.m_FixedData.m_ulReachRealmLevel));
AppendText(strTemp);
AppendText("\n");
}
if (pTemp.m_FixedData.m_ulReachReincarnationCount > 0)
{
AppendText(strIndent);
strTemp = FormatFromTable(9398, pHost.GetReincarnationCount(), pTemp.m_FixedData.m_ulReachReincarnationCount);
AppendText(strTemp);
AppendText("\n");
}
}
}
string GetKillPlayerRequirements(Task_State_info tsi,int iIndex)
{
//todo: implement this after pK is enabled
return string.Empty;
}
void KeepScrollBarPosition()
{
//Insert UI logic
}
void OnCommand_FinishTask(string szCommand)
{
//UI finish task logic go here
// PAUIOBJECT pObj = GetDlgItem(szCommand);
// if (pObj) {
// int idTask = pObj->GetData();
// if (idTask) {
// const ATaskTempl* pTempl = GetGame()->GetTaskTemplateMan()->GetTaskTemplByID(idTask);
// if (pTempl) {
// CECHostPlayer* pHost = GetHostPlayer();
// CECGameUIMan* pGameUI = GetGameUIMan();
// CECTaskInterface* pTask = pHost->GetTaskInterface();
// Task_State_info tsi;
// pTask->GetTaskStateInfo(idTask, &tsi);
// if (tsi.m_ulErrCode)
// {
// const wchar_t* szMsg = _task_err.GetWideString(tsi.m_ulErrCode);
// if (szMsg)
// {
// ACString strText = szMsg;
// ACString strTemp;
// if (tsi.m_ulErrCode == TASK_AWARD_FAIL_LEVEL_CHECK)
// strTemp.Format(GetStringFromTable(7637), tsi.m_ulPremLevelMin);
// else strTemp = GetStringFromTable(807);
// strText += strTemp;
// strText += _AL("\r");
// strText += COLOR_WHITE;
// pGameUI->MessageBox("", strText, MB_OK, A3DCOLORRGBA(255, 255, 255, 160));
// return;
// }
// }
// if (pHost->GetWorldContribution() < pTempl->m_iWorldContribution)
// pGameUI->MessageBox("", pGameUI->GetStringFromTable(11282), MB_OK, A3DCOLORRGBA(255, 255, 255, 160));
// else if (!pHost->HaveHealthStones() &&
// pHost->GetWorldContributionSpend() + pTempl->m_iWorldContribution > TASK_WORLD_CONTRIBUTION_SPEND_PER_DAY)
// pGameUI->MessageBox("", pGameUI->GetStringFromTable(11283), MB_OK, A3DCOLORRGBA(255, 255, 255, 160));
// else
// FinishTaskSpendingContribution(idTask);
// }
// }
// }
}
void OnEventDBClk_Title(/*WPARAM wParam, LPARAM lParam, AUIObject *pObj*/)
{
SwitchCollapse();
}
void OnCommand_SwitchCollapse(bool value)
{
//SwitchCollapse();
}
void SwitchCollapse()
{
// UI Checkbox Switch logic go here
}
void OnCommand_UnTraceTask()
{
// UI UnTrace Task logic go here
}
void OnCommand_Chat()
{
// UI Chat logic go here
}
void OnCommand_Map()
{
// UI Map logic go here
}
public void OnTaskNew(ulong idTask)
{
// TODO: implement this
}
}
//////////////////////////////////////////////////////////////////////////
// TraceLinkCommandCommand
//////////////////////////////////////////////////////////////////////////
public class TraceLinkCommand : MoveToLinkCommand
{
public StringRef m_Buffer = new StringRef();
public TraceLinkCommand(StringRef buffer, int id, string name, int taskid) : base(id, name, taskid){
m_Buffer = buffer;
}
public TraceLinkCommand(StringRef buffer, List<OBJECT_COORD> targets, string name) : base(targets, name){
m_Buffer = buffer;
}
public TraceLinkCommand(TraceLinkCommand rhs) : base(rhs){
m_Buffer = rhs.m_Buffer;
}
public override LinkCommand Clone()
{
return new TraceLinkCommand(this);
}
public override void AppendText()
{
// do nothing here
m_Buffer.Value += GetLinkText();
}
}
}