From 8793522216d405fa7427648e832499294cfd19e4 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Mon, 13 May 2019 17:31:31 +0500 Subject: [PATCH] Returned tasks with additional and insignificant types (#382 and #392) --- src/xrGame/GameTask.h | 1 + src/xrGame/GameTaskDefs.h | 44 ++++- src/xrGame/GameTask_script.cpp | 5 +- src/xrGame/GametaskManager.cpp | 138 ++++++++----- src/xrGame/GametaskManager.h | 13 +- src/xrGame/UIGameSP.cpp | 23 ++- src/xrGame/map_location.cpp | 5 +- .../script_game_object_inventory_owner.cpp | 7 +- src/xrGame/ui/UISecondTaskWnd.cpp | 82 ++++---- src/xrGame/ui/UISecondTaskWnd.h | 4 +- src/xrGame/ui/UITaskWnd.cpp | 181 ++++++++++++++---- src/xrGame/ui/UITaskWnd.h | 29 ++- 12 files changed, 387 insertions(+), 145 deletions(-) diff --git a/src/xrGame/GameTask.h b/src/xrGame/GameTask.h index a8264ab697f..cec3793efa0 100644 --- a/src/xrGame/GameTask.h +++ b/src/xrGame/GameTask.h @@ -103,6 +103,7 @@ class CGameTask LPCSTR GetTitle_script() { return m_Title.c_str(); } void SetPriority_script(int _prio) { m_priority = _prio; } int GetPriority_script() { return m_priority; } + int GetType_script() { return m_task_type; } void SetType_script(int t) { m_task_type = (ETaskType)t; } LPCSTR GetID_script() { return m_ID.c_str(); } void SetID_script(LPCSTR _id) { m_ID = _id; } diff --git a/src/xrGame/GameTaskDefs.h b/src/xrGame/GameTaskDefs.h index 4a83977fd04..424b0371170 100644 --- a/src/xrGame/GameTaskDefs.h +++ b/src/xrGame/GameTaskDefs.h @@ -10,16 +10,19 @@ enum ETaskState : u32 }; // all task has `storyline`-type now (10.10.2008)(sea) +// reverted sea changes (13.05.2019)(xottab_duty) enum ETaskType { eTaskTypeStoryline = 0, eTaskTypeAdditional, - // eTaskTypeInsignificant, - // eTaskTypeCount, + eTaskTypeInsignificant, + eTaskTypeCount, eTaskTypeDummy = u16(-1) }; -extern shared_str g_active_task_id; +constexpr pcstr g_active_task_no_task___internal = "__xr_no_task_-_nullptr__"; + +extern shared_str g_active_task_id[eTaskTypeCount]; class CGameTask; struct SGameTaskKey : public ISerializable, public IPureDestroyableObject @@ -41,11 +44,40 @@ struct CGameTaskRegistry : public CALifeAbstractRegistry virtual void save(IWriter& stream) { CALifeAbstractRegistry::save(stream); - save_data(g_active_task_id, stream); + for (auto& taskId : g_active_task_id) + { + // valid taskId should contain task name + // or at least g_active_task_no_task___internal + if (!taskId.size()) + taskId = g_active_task_no_task___internal; + + save_data(taskId, stream); + } }; virtual void load(IReader& stream) { CALifeAbstractRegistry::load(stream); - load_data(g_active_task_id, stream); - }; + + auto prevPos = stream.tell(); + + for (auto& taskId : g_active_task_id) + { + // valid taskId should contain task name + // or at least g_active_task_no_task___internal + + load_data(taskId, stream); + + // if it doesn't fit terms above, then it's not valid + // probably save file is old. We can try to + // preserve compatibility with just stream rollback + if (!taskId.size()) + { + taskId = g_active_task_no_task___internal; + stream.seek(prevPos); // rollback + break; // there's no point to continue + } + else // it's valid, remember new pos + prevPos = stream.tell(); + } + } }; diff --git a/src/xrGame/GameTask_script.cpp b/src/xrGame/GameTask_script.cpp index 73f65cdc68e..29d325b9f71 100644 --- a/src/xrGame/GameTask_script.cpp +++ b/src/xrGame/GameTask_script.cpp @@ -21,7 +21,8 @@ SCRIPT_EXPORT(CGameTask, (), .enum_("task_type") [ value("storyline", int(eTaskTypeStoryline)), - value("additional", int(eTaskTypeAdditional)) + value("additional", int(eTaskTypeAdditional)), + value("insignificant", int(eTaskTypeInsignificant)) ], class_("CGameTask") @@ -33,7 +34,7 @@ SCRIPT_EXPORT(CGameTask, (), .def("get_id", &CGameTask::GetID_script) .def("set_id", &CGameTask::SetID_script) .def("set_type", &CGameTask::SetType_script) - //.def("get_type", &CGameTask::GetType_script) + .def("get_type", &CGameTask::GetType_script) .def("set_icon_name", &CGameTask::SetIconName_script) .def("get_icon_name", &CGameTask::GetIconName_script) .def("set_description", &CGameTask::SetDescription_script) diff --git a/src/xrGame/GametaskManager.cpp b/src/xrGame/GametaskManager.cpp index 54b535df527..7ad56a427d0 100644 --- a/src/xrGame/GametaskManager.cpp +++ b/src/xrGame/GametaskManager.cpp @@ -18,7 +18,12 @@ #include #pragma warning(pop) -shared_str g_active_task_id; +shared_str g_active_task_id[eTaskTypeCount] = +{ + g_active_task_no_task___internal, + g_active_task_no_task___internal, + g_active_task_no_task___internal +}; struct FindTaskByID { @@ -47,12 +52,16 @@ CGameTaskManager::CGameTaskManager() m_flags.set(eChanged, TRUE); m_gametasks = NULL; - if (g_active_task_id.size()) + for (auto& taskId : g_active_task_id) { - CGameTask* t = HasGameTask(g_active_task_id, true); - if (t) + if (!taskId.size()) + taskId = g_active_task_no_task___internal; + + if (taskId != g_active_task_no_task___internal) { - SetActiveTask(t); + CGameTask* t = HasGameTask(taskId, true); + if (t) + SetActiveTask(t); } } } @@ -60,7 +69,8 @@ CGameTaskManager::CGameTaskManager() CGameTaskManager::~CGameTaskManager() { delete_data(m_gametasks_wrapper); - g_active_task_id = NULL; + for (auto& taskId : g_active_task_id) + taskId = nullptr; } vGameTasks& CGameTaskManager::GetGameTasks() @@ -108,14 +118,20 @@ CGameTask* CGameTaskManager::GiveGameTaskToActor(CGameTask* t, u32 timeToComplet t->OnArrived(); - // CGameTask* active_task = ActiveTask(); - - // if ( (active_task == NULL) || (active_task->m_priority < t->m_priority) ) - //{ - // SetActiveTask( t ); - //} - - SetActiveTask(t); + if (!m_flags.test(eMultipleTasks)) + SetActiveTask(t); + else + { + const ETaskType taskType = t->GetTaskType(); + CGameTask* activeTask = ActiveTask(t->GetTaskType()); + if (taskType == eTaskTypeStoryline || taskType == eTaskTypeAdditional) + { + if ((activeTask == nullptr) || (activeTask->m_priority < t->m_priority)) + { + SetActiveTask(t); + } + } + } //установить флажок необходимости прочтения тасков в PDA if (CurrentGameUI()) @@ -126,16 +142,20 @@ CGameTask* CGameTaskManager::GiveGameTaskToActor(CGameTask* t, u32 timeToComplet return t; } -void CGameTaskManager::SetTaskState(CGameTask* t, ETaskState state) +void CGameTaskManager::SetTaskState(CGameTask* task, ETaskState state) { m_flags.set(eChanged, TRUE); - t->SetTaskState(state); + ETaskType type = eTaskTypeStoryline; + if (m_flags.test(eMultipleTasks)) + type = task->GetTaskType(); + + task->SetTaskState(state); - if (ActiveTask() == t) + if (ActiveTask(type) == task) { - // SetActiveTask (""); - g_active_task_id = ""; + //SetActiveTask ("", t->GetTaskType()); + g_active_task_id[type] = ""; } if (CurrentGameUI()) @@ -184,13 +204,14 @@ void CGameTaskManager::UpdateTasks() } } - CGameTask* t = ActiveTask(); - if (t) + for (int i = 0; i < eTaskTypeCount; ++i) { - CMapLocation* ml = t->LinkedMapLocation(); - if (ml && !ml->PointerEnabled()) + CGameTask* activeTask = ActiveTask(static_cast(i)); + if (activeTask) { - ml->EnablePointer(); + CMapLocation* ml = activeTask->LinkedMapLocation(); + if (ml && !ml->PointerEnabled()) + ml->EnablePointer(); } } @@ -202,13 +223,14 @@ void CGameTaskManager::UpdateActiveTask() { std::stable_sort(GetGameTasks().begin(), GetGameTasks().end(), task_prio_pred); - CGameTask* t = ActiveTask(); - if (!t) + for (u32 i = eTaskTypeStoryline; i < eTaskTypeCount; ++i) { - CGameTask* front = IterateGet(NULL, eTaskStateInProgress, true); - if (front) + CGameTask* activeTask = ActiveTask(static_cast(i)); + if (!activeTask) { - SetActiveTask(front); + CGameTask* frontTask = IterateGet(nullptr, eTaskStateInProgress, static_cast(i), true); + if (frontTask) + SetActiveTask(frontTask); } } @@ -216,19 +238,33 @@ void CGameTaskManager::UpdateActiveTask() m_actual_frame = Device.dwFrame; } -CGameTask* CGameTaskManager::ActiveTask() +CGameTask* CGameTaskManager::ActiveTask(ETaskType type) { - const shared_str& t_id = g_active_task_id; + ETaskType t = eTaskTypeStoryline; + if (m_flags.test(eMultipleTasks)) + t = type; + + shared_str& t_id = g_active_task_id[t]; + if (!t_id.size()) - return NULL; + t_id = g_active_task_no_task___internal; + + if (t_id == g_active_task_no_task___internal) + return nullptr; + return HasGameTask(t_id, true); } + /* -void CGameTaskManager::SetActiveTask(const shared_str& id) +void CGameTaskManager::SetActiveTask(const shared_str& id, ETaskType type) { - g_active_task_id = id; - m_flags.set (eChanged, TRUE); - m_read = true; + ETaskType t = eTaskTypeStoryline; + if (m_flags.test(eMultipleTasks)) + t = type; + + g_active_task_id[t] = id; + m_flags.set(eChanged, TRUE); + m_read = true; }*/ void CGameTaskManager::SetActiveTask(CGameTask* task) @@ -236,7 +272,11 @@ void CGameTaskManager::SetActiveTask(CGameTask* task) VERIFY(task); if (task) { - g_active_task_id = task->m_ID; + ETaskType type = eTaskTypeStoryline; + if (m_flags.test(eMultipleTasks)) + type = task->GetTaskType(); + + g_active_task_id[type] = task->m_ID; m_flags.set(eChanged, TRUE); task->m_read = true; } @@ -274,7 +314,7 @@ CGameTask* CGameTaskManager::HasGameTask(const CMapLocation* ml, bool only_inpro return NULL; } -CGameTask* CGameTaskManager::IterateGet(CGameTask* t, ETaskState state, bool bForward) +CGameTask* CGameTaskManager::IterateGet(CGameTask* t, ETaskState state, ETaskType type, bool bForward) { vGameTasks& v = GetGameTasks(); u32 cnt = v.size(); @@ -297,10 +337,10 @@ CGameTask* CGameTaskManager::IterateGet(CGameTask* t, ETaskState state, bool bFo if (allow) { CGameTask* found = v[i].game_task; - if (found->GetTaskState() == state) + if (found->GetTaskState() == state && found->GetTaskType() == type) return found; else - return IterateGet(found, state, bForward); + return IterateGet(found, state, type, bForward); } else return NULL; @@ -309,7 +349,7 @@ CGameTask* CGameTaskManager::IterateGet(CGameTask* t, ETaskState state, bool bFo return NULL; } -u32 CGameTaskManager::GetTaskIndex(CGameTask* t, ETaskState state) +u32 CGameTaskManager::GetTaskIndex(CGameTask* t, ETaskState state, ETaskType type) { if (!t) { @@ -322,7 +362,7 @@ u32 CGameTaskManager::GetTaskIndex(CGameTask* t, ETaskState state) for (u32 i = 0; i < cnt; ++i) { CGameTask* gt = v[i].game_task; - if (gt->GetTaskState() == state) + if (gt->GetTaskType() == type && gt->GetTaskState() == state) { ++res; if (gt == t) @@ -334,7 +374,7 @@ u32 CGameTaskManager::GetTaskIndex(CGameTask* t, ETaskState state) return 0; } -u32 CGameTaskManager::GetTaskCount(ETaskState state) +u32 CGameTaskManager::GetTaskCount(ETaskState state, ETaskType type) { vGameTasks& v = GetGameTasks(); u32 cnt = v.size(); @@ -342,7 +382,7 @@ u32 CGameTaskManager::GetTaskCount(ETaskState state) for (u32 i = 0; i < cnt; ++i) { CGameTask* gt = v[i].game_task; - if (gt->GetTaskState() == state) + if (gt->GetTaskType() == type && gt->GetTaskState() == state) { ++res; } @@ -350,13 +390,17 @@ u32 CGameTaskManager::GetTaskCount(ETaskState state) return res; } -constexpr pcstr sTaskStates[] = { "eTaskStateFail", "TaskStateInProgress", "TaskStateCompleted", "TaskStateDummy" }; - +constexpr pcstr sTaskStates[] = { "TaskStateFail", "TaskStateInProgress", "TaskStateCompleted", "TaskStateDummy" }; +constexpr pcstr sTaskTypes[] = { "TaskTypeStoryline", "TaskTypeAdditional", "TaskTypeInsignificant", }; void CGameTaskManager::DumpTasks() { for (auto& it : GetGameTasks()) { const CGameTask* gt = it.game_task; - Msg(" ID=[%s] state=[%s] prio=[%d] ", gt->m_ID.c_str(), sTaskStates[gt->GetTaskState()], gt->m_priority); + Msg("ID=[%s] type=[%s] state=[%s] prio=[%d] ", + gt->m_ID.c_str(), + sTaskTypes[gt->GetTaskType()], + sTaskStates[gt->GetTaskState()], + gt->m_priority); } } diff --git a/src/xrGame/GametaskManager.h b/src/xrGame/GametaskManager.h index b0890a8907c..55ba758fb30 100644 --- a/src/xrGame/GametaskManager.h +++ b/src/xrGame/GametaskManager.h @@ -14,6 +14,7 @@ class CGameTaskManager enum { eChanged = (1 << 0), + eMultipleTasks = (1 << 1), }; Flags8 m_flags; u32 m_actual_frame; @@ -25,6 +26,8 @@ class CGameTaskManager CGameTaskManager(); ~CGameTaskManager(); + void AllowMultipleTask(bool allow) { m_flags.set(eMultipleTasks, allow); } + vGameTasks& GetGameTasks(); CGameTask* HasGameTask(const CMapLocation* ml, bool only_inprocess); CGameTask* HasGameTask(const shared_str& id, bool only_inprocess); @@ -34,13 +37,13 @@ class CGameTaskManager void __stdcall UpdateTasks(); - CGameTask* ActiveTask(); - // void SetActiveTask (const shared_str& id); + CGameTask* ActiveTask(ETaskType type = eTaskTypeStoryline); + //void SetActiveTask(const shared_str& id, ETaskType type = eTaskTypeStoryline); void SetActiveTask(CGameTask* task); u32 ActualFrame() const { return m_actual_frame; } - CGameTask* IterateGet(CGameTask* t, ETaskState state, bool bForward); - u32 GetTaskIndex(CGameTask* t, ETaskState state); - u32 GetTaskCount(ETaskState state); + CGameTask* IterateGet(CGameTask* t, ETaskState state, ETaskType type, bool bForward); + u32 GetTaskIndex(CGameTask* t, ETaskState state, ETaskType type = eTaskTypeStoryline); + u32 GetTaskCount(ETaskState state, ETaskType type = eTaskTypeStoryline); void MapLocationRelcase(CMapLocation* ml); void ResetStorage() { m_gametasks = NULL; }; diff --git a/src/xrGame/UIGameSP.cpp b/src/xrGame/UIGameSP.cpp index a94bb6fe819..c94da7a13cd 100644 --- a/src/xrGame/UIGameSP.cpp +++ b/src/xrGame/UIGameSP.cpp @@ -145,13 +145,28 @@ bool CUIGameSP::IR_UIOnKeyboardPress(int dik) if (!pActor->inventory_disabled()) { m_game_objective = AddCustomStatic("main_task", true); - CGameTask* t1 = Level().GameTaskManager().ActiveTask(); - m_game_objective->m_static->TextItemControl()->SetTextST((t1) ? t1->m_Title.c_str() : "st_no_active_task"); + CGameTask* t1 = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + CGameTask* t2 = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); - if (t1 && t1->m_Description.c_str()) + if (t1 && t2) { + m_game_objective->m_static->SetTextST(t1->m_Title.c_str()); StaticDrawableWrapper* sm2 = AddCustomStatic("secondary_task", true); - sm2->m_static->TextItemControl()->SetTextST(t1->m_Description.c_str()); + sm2->m_static->SetTextST(t2->m_Title.c_str()); + } + else + { + if (t1 || t2) + { + CGameTask* t = (t1) ? t1 : t2; + m_game_objective->m_static->SetTextST(t->m_Title.c_str()); + StaticDrawableWrapper* sm2 = AddCustomStatic("secondary_task", true); + sm2->m_static->TextItemControl()->SetTextST(t->m_Description.c_str()); + } + else + { + m_game_objective->m_static->TextItemControl()->SetTextST("st_no_active_task"); + } } } break; diff --git a/src/xrGame/map_location.cpp b/src/xrGame/map_location.cpp index 3bbce3e4ddd..dc896952335 100644 --- a/src/xrGame/map_location.cpp +++ b/src/xrGame/map_location.cpp @@ -367,8 +367,9 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp) CGameTask* ml_task = Level().GameTaskManager().HasGameTask(this, true); if (ml_task) { - CGameTask* active_task = Level().GameTaskManager().ActiveTask(); - bool border_show = (ml_task == active_task); + CGameTask* storyTask = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + CGameTask* additionalTask = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); + const bool border_show = ml_task == storyTask || ml_task == additionalTask; if (m_minimap_spot) { m_minimap_spot->show_static_border(border_show); diff --git a/src/xrGame/script_game_object_inventory_owner.cpp b/src/xrGame/script_game_object_inventory_owner.cpp index ff81c0bddf0..bb9dd02e4e0 100644 --- a/src/xrGame/script_game_object_inventory_owner.cpp +++ b/src/xrGame/script_game_object_inventory_owner.cpp @@ -1242,7 +1242,12 @@ void CScriptGameObject::SetActiveTask(CGameTask* t) bool CScriptGameObject::IsActiveTask(CGameTask* t) { VERIFY(t); - return Level().GameTaskManager().ActiveTask() == t; + + const auto t1 = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + const auto t2 = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); + const auto t3 = Level().GameTaskManager().ActiveTask(eTaskTypeInsignificant); + + return t == t1 || t == t2 || t == t3; } u32 CScriptGameObject::active_slot() diff --git a/src/xrGame/ui/UISecondTaskWnd.cpp b/src/xrGame/ui/UISecondTaskWnd.cpp index 63bbdc6af97..519f62547c5 100644 --- a/src/xrGame/ui/UISecondTaskWnd.cpp +++ b/src/xrGame/ui/UISecondTaskWnd.cpp @@ -28,7 +28,10 @@ #include "GametaskManager.h" #include "Actor.h" -UITaskListWnd::UITaskListWnd() { hint_wnd = NULL; } +UITaskListWnd::UITaskListWnd() + : hint_wnd(nullptr), m_background(nullptr), m_list(nullptr), + m_caption(nullptr), m_bt_close(nullptr), m_orig_h(0) {} + UITaskListWnd::~UITaskListWnd() {} void UITaskListWnd::init_from_xml(CUIXml& xml, LPCSTR path) { @@ -166,15 +169,16 @@ void UITaskListWnd::UpdateCounter() // - ----------------------------------------------------------------------------------------------- UITaskListWndItem::UITaskListWndItem() + : show_hint_can(false), show_hint(false), + m_task(nullptr), m_name(nullptr), + m_bt_view(nullptr), m_st_story(nullptr), + m_bt_focus(nullptr) { - m_task = NULL; - - m_color_states[0] = (u32)(-1); - m_color_states[1] = (u32)(-1); - m_color_states[2] = (u32)(-1); + m_color_states[0] = u32(-1); + m_color_states[1] = u32(-1); + m_color_states[2] = u32(-1); } -UITaskListWndItem::~UITaskListWndItem() {} IC u32 UITaskListWndItem::get_priority_task() const { VERIFY(m_task); @@ -197,8 +201,8 @@ bool UITaskListWndItem::init_task(CGameTask* task, UITaskListWnd* parent) CUIXmlInit::InitWindow(xml, "second_task_wnd:task_item", 0, this); m_name = UIHelper::Create3tButton(xml, "second_task_wnd:task_item:name", this); - // m_bt_view = UIHelper::CreateCheck( xml, "second_task_wnd:task_item:btn_view", this ); - m_st_story = UIHelper::CreateStatic(xml, "second_task_wnd:task_item:st_story", this); + m_bt_view = UIHelper::CreateCheck(xml, "second_task_wnd:task_item:btn_view", this, false); + m_st_story = UIHelper::CreateStatic(xml, "second_task_wnd:task_item:st_story", this, false); m_bt_focus = UIHelper::Create3tButton(xml, "second_task_wnd:task_item:btn_focus", this); m_color_states[stt_activ] = CUIXmlInit::GetColor(xml, "second_task_wnd:task_item:activ", 0, (u32)(-1)); @@ -235,15 +239,29 @@ void UITaskListWndItem::update_view() { VERIFY(m_task); CMapLocation* ml = m_task->LinkedMapLocation(); + if (ml && ml->SpotEnabled()) - m_bt_focus->Show(true); + { + if (m_bt_view) + m_bt_view->SetCheck(false); + else + m_bt_focus->Show(true); + } else - m_bt_focus->Show(false); + { + if (m_bt_view) + m_bt_view->SetCheck(true); + else + m_bt_focus->Show(false); + } - if (m_task->GetTaskType() == eTaskTypeStoryline) - m_st_story->InitTexture("ui_inGame2_PDA_icon_Primary_mission"); - else - m_st_story->InitTexture("ui_inGame2_PDA_icon_Secondary_mission"); + if (m_st_story) + { + if (m_task->GetTaskType() == eTaskTypeStoryline) + m_st_story->InitTexture("ui_inGame2_PDA_icon_Primary_mission"); + else + m_st_story->InitTexture("ui_inGame2_PDA_icon_Secondary_mission"); + } m_name->TextItemControl()->SetTextST(m_task->m_Title.c_str()); m_name->AdjustHeightToText(); @@ -251,9 +269,10 @@ void UITaskListWndItem::update_view() h1 = _max(h1, GetHeight()); SetHeight(h1); - CGameTask* activ_task = Level().GameTaskManager().ActiveTask(); - - if (m_task == activ_task) + const CGameTask* storyTask = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + const CGameTask* additionalTask = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); + + if (m_task == storyTask || m_task == additionalTask) { m_name->SetStateTextColor(m_color_states[stt_activ], S_Enabled); } @@ -276,23 +295,20 @@ void UITaskListWndItem::SendMessage(CUIWindow* pWnd, s16 msg, void* pData) GetMessageTarget()->SendMessage(this, PDA_TASK_SET_TARGET_MAP, (void*)m_task); } } - /* - if ( pWnd == m_bt_view ) + if (pWnd == m_bt_view) + { + if (m_bt_view->GetCheck() && msg == BUTTON_CLICKED) { - if ( m_bt_view->GetCheck() && msg == BUTTON_CLICKED ) - { - GetMessageTarget()->SendMessage( this, PDA_TASK_HIDE_MAP_SPOT, (void*)m_task ); - // Msg( " HIDE task id = %d", m_task->m_ID ); - return; - } - if ( !m_bt_view->GetCheck() && msg == BUTTON_CLICKED ) - { - GetMessageTarget()->SendMessage( this, PDA_TASK_SHOW_MAP_SPOT, (void*)m_task ); - // Msg( " show task id = %d", m_task->m_ID ); - return; - } + GetMessageTarget()->SendMessage(this, PDA_TASK_HIDE_MAP_SPOT, (void*)m_task); + return; } - */ + if (!m_bt_view->GetCheck() && msg == BUTTON_CLICKED) + { + GetMessageTarget()->SendMessage(this, PDA_TASK_SHOW_MAP_SPOT, (void*)m_task); + return; + } + } + if (pWnd == m_name) { if (msg == BUTTON_DOWN) diff --git a/src/xrGame/ui/UISecondTaskWnd.h b/src/xrGame/ui/UISecondTaskWnd.h index cf400c0e5dc..8fd1b21981c 100644 --- a/src/xrGame/ui/UISecondTaskWnd.h +++ b/src/xrGame/ui/UISecondTaskWnd.h @@ -74,7 +74,7 @@ class UITaskListWndItem : public CUIWindow public: UITaskListWndItem(); - virtual ~UITaskListWndItem(); + virtual ~UITaskListWndItem() = default; bool init_task(CGameTask* task, UITaskListWnd* parent); IC u32 get_priority_task() const; @@ -97,7 +97,7 @@ class UITaskListWndItem : public CUIWindow private: // m_ CGameTask* m_task; CUI3tButton* m_name; - // CUICheckButton* m_bt_view; + CUICheckButton* m_bt_view; CUIStatic* m_st_story; CUI3tButton* m_bt_focus; diff --git a/src/xrGame/ui/UITaskWnd.cpp b/src/xrGame/ui/UITaskWnd.cpp index e15b8d7a4f0..08879e00e12 100644 --- a/src/xrGame/ui/UITaskWnd.cpp +++ b/src/xrGame/ui/UITaskWnd.cpp @@ -21,7 +21,23 @@ #include "Actor.h" #include "xrUICore/Buttons/UICheckButton.h" -CUITaskWnd::CUITaskWnd() { hint_wnd = NULL; } +CUITaskWnd::CUITaskWnd() + : m_background(nullptr), m_background2(nullptr), + m_center_background(nullptr), m_right_bottom_background(nullptr), + m_task_split(nullptr), m_pMapWnd(nullptr), + m_pStoryLineTaskItem(nullptr), m_pSecondaryTaskItem(nullptr), + m_BtnTaskListWnd(nullptr), m_second_task_index(nullptr), + m_devider(nullptr), m_actual_frame(0), + m_btn_focus(nullptr), m_btn_focus2(nullptr), + m_cbTreasures(nullptr), m_cbQuestNpcs(nullptr), + m_cbSecondaryTasks(nullptr), m_cbPrimaryObjects(nullptr), + m_bTreasuresEnabled(false), m_bQuestNpcsEnabled(false), + m_bSecondaryTasksEnabled(false), m_bPrimaryObjectsEnabled(false), + m_task_wnd(nullptr), m_task_wnd_show(false), + m_map_legend_wnd(nullptr), hint_wnd(nullptr) +{ +} + CUITaskWnd::~CUITaskWnd() { delete_data(m_pMapWnd); } void CUITaskWnd::Init() { @@ -31,28 +47,43 @@ void CUITaskWnd::Init() CUIXmlInit::InitWindow(xml, "main_wnd", 0, this); - m_background = UIHelper::CreateFrameWindow(xml, "background", this); + m_background = UIHelper::CreateFrameWindow(xml, "background", this, false); + m_background2 = UIHelper::CreateFrameLine(xml, "background", this, false); + + m_task_split = UIHelper::CreateFrameLine(xml, "task_split", this, false); - m_cbTreasures = UIHelper::CreateCheck(xml, "filter_treasures", this); - m_cbTreasures->SetCheck(true); - AddCallback(m_cbTreasures, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowTreasures)); + m_cbTreasures = UIHelper::CreateCheck(xml, "filter_treasures", this, false); + if (m_cbTreasures) + { + m_cbTreasures->SetCheck(true); + AddCallback(m_cbTreasures, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowTreasures)); + } m_bTreasuresEnabled = true; - m_cbPrimaryObjects = UIHelper::CreateCheck(xml, "filter_primary_objects", this); - m_cbPrimaryObjects->SetCheck(true); - AddCallback( - m_cbPrimaryObjects, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowPrimaryObjects)); + m_cbPrimaryObjects = UIHelper::CreateCheck(xml, "filter_primary_objects", this, false); + if (m_cbPrimaryObjects) + { + m_cbPrimaryObjects->SetCheck(true); + AddCallback( + m_cbPrimaryObjects, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowPrimaryObjects)); + } m_bPrimaryObjectsEnabled = true; - m_cbSecondaryTasks = UIHelper::CreateCheck(xml, "filter_secondary_tasks", this); - m_cbSecondaryTasks->SetCheck(true); - AddCallback( - m_cbSecondaryTasks, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowSecondaryTasks)); + m_cbSecondaryTasks = UIHelper::CreateCheck(xml, "filter_secondary_tasks", this, false); + if (m_cbSecondaryTasks) + { + m_cbSecondaryTasks->SetCheck(true); + AddCallback( + m_cbSecondaryTasks, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowSecondaryTasks)); + } m_bSecondaryTasksEnabled = true; - m_cbQuestNpcs = UIHelper::CreateCheck(xml, "filter_quest_npcs", this); - m_cbQuestNpcs->SetCheck(true); - AddCallback(m_cbQuestNpcs, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowQuestNpcs)); + m_cbQuestNpcs = UIHelper::CreateCheck(xml, "filter_quest_npcs", this, false); + if (m_cbQuestNpcs) + { + m_cbQuestNpcs->SetCheck(true); + AddCallback(m_cbQuestNpcs, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowQuestNpcs)); + } m_bQuestNpcsEnabled = true; m_pMapWnd = new CUIMapWnd(); @@ -62,7 +93,7 @@ void CUITaskWnd::Init() AttachChild(m_pMapWnd); m_center_background = UIHelper::CreateStatic(xml, "center_background", this); - m_devider = UIHelper::CreateStatic(xml, "line_devider", this); + m_devider = UIHelper::CreateStatic(xml, "line_devider", this, false); m_pStoryLineTaskItem = new CUITaskItem(); m_pStoryLineTaskItem->Init(xml, "storyline_task_item"); @@ -71,17 +102,40 @@ void CUITaskWnd::Init() AddCallback(m_pStoryLineTaskItem, WINDOW_LBUTTON_DB_CLICK, CUIWndCallback::void_function(this, &CUITaskWnd::OnTask1DbClicked)); + if (xml.NavigateToNode("secondary_task_item")) // XXX: replace with UIHelper + { + Level().GameTaskManager().AllowMultipleTask(true); + m_pSecondaryTaskItem = new CUITaskItem(); + m_pSecondaryTaskItem->Init(xml, "secondary_task_item"); + AttachChild(m_pSecondaryTaskItem); + m_pSecondaryTaskItem->SetAutoDelete(true); + AddCallback(m_pSecondaryTaskItem, WINDOW_LBUTTON_DB_CLICK, CUIWndCallback::void_function(this, &CUITaskWnd::OnTask2DbClicked)); + } + m_btn_focus = UIHelper::Create3tButton(xml, "btn_task_focus", this); Register(m_btn_focus); AddCallback(m_btn_focus, BUTTON_DOWN, CUIWndCallback::void_function(this, &CUITaskWnd::OnTask1DbClicked)); + // XXX: 3tButtonEx + //m_btn_focus->set_hint_wnd(hint_wnd); + + m_btn_focus2 = UIHelper::Create3tButton(xml, "btn_task_focus2", this, false); + if (m_btn_focus2) + { + Register(m_btn_focus2); + AddCallback(m_btn_focus2, BUTTON_DOWN, CUIWndCallback::void_function(this, &CUITaskWnd::OnTask2DbClicked)); + //m_btn_focus2->set_hint_wnd(hint_wnd); + } m_BtnTaskListWnd = UIHelper::Create3tButton(xml, "btn_second_task", this); AddCallback(m_BtnTaskListWnd, BUTTON_CLICKED, CUIWndCallback::void_function(this, &CUITaskWnd::OnShowTaskListWnd)); + m_second_task_index = UIHelper::CreateStatic(xml, "second_task_index", this, false); + m_task_wnd = new UITaskListWnd(); m_task_wnd->SetAutoDelete(true); m_task_wnd->hint_wnd = hint_wnd; m_task_wnd->init_from_xml(xml, "second_task_wnd"); + m_pMapWnd->AttachChild(m_task_wnd); m_task_wnd->SetMessageTarget(this); m_task_wnd->Show(false); @@ -106,6 +160,11 @@ void CUITaskWnd::Update() { m_pMapWnd->ShowHintTask(m_pStoryLineTaskItem->OwnerTask(), m_pStoryLineTaskItem); } + else if (m_pSecondaryTaskItem && m_pSecondaryTaskItem->show_hint && m_pSecondaryTaskItem->OwnerTask()) + { + m_pStoryLineTaskItem->show_hint = false; + m_pMapWnd->ShowHintTask(m_pSecondaryTaskItem->OwnerTask(), m_pSecondaryTaskItem); + } else { m_pMapWnd->HideCurHint(); @@ -154,14 +213,29 @@ void CUITaskWnd::SendMessage(CUIWindow* pWnd, s16 msg, void* pData) void CUITaskWnd::ReloadTaskInfo() { - CGameTask* t = Level().GameTaskManager().ActiveTask(); - m_pStoryLineTaskItem->InitTask(t); + CGameTask* storyTask = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + m_pStoryLineTaskItem->InitTask(storyTask); + + CGameTask* additionalTask = nullptr; + if (m_pSecondaryTaskItem) + { + additionalTask = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); + m_pSecondaryTaskItem->InitTask(additionalTask); + } - if (t && (t->m_map_object_id == u16(-1) || t->m_map_location.size() == 0)) + if (!storyTask || (storyTask->m_map_object_id == u16(-1) || storyTask->m_map_location.size() == 0)) m_btn_focus->Show(false); else m_btn_focus->Show(true); + if (m_btn_focus2) + { + if (!additionalTask || (additionalTask->m_map_object_id == u16(-1) || additionalTask->m_map_location.size() == 0)) + m_btn_focus2->Show(false); + else + m_btn_focus2->Show(true); + } + Locations map_locs = Level().MapManager().Locations(); auto b = map_locs.begin(), e = map_locs.end(); for (; b != e; b++) @@ -181,20 +255,54 @@ void CUITaskWnd::ReloadTaskInfo() m_bQuestNpcsEnabled ? b->location->EnableSpot() : b->location->DisableSpot(); } - if (!t) + if (storyTask || additionalTask) + { + m_actual_frame = Level().GameTaskManager().ActualFrame(); + if (m_task_wnd->IsShown()) + m_task_wnd->UpdateList(); + } + + if (!m_second_task_index) return; - m_actual_frame = Level().GameTaskManager().ActualFrame(); + if (storyTask && !additionalTask) + { + const auto task_count = Level().GameTaskManager().GetTaskCount(eTaskStateInProgress, eTaskTypeStoryline); + if (task_count) + { + const auto task_index = Level().GameTaskManager().GetTaskIndex(storyTask, eTaskStateInProgress, eTaskTypeStoryline); + string32 buf; + xr_sprintf(buf, sizeof(buf), "%d / %d", task_index, task_count); - u32 task_count = Level().GameTaskManager().GetTaskCount(eTaskStateInProgress); - if (task_count) + m_second_task_index->SetVisible(true); + m_second_task_index->SetText(buf); + } + else + { + m_second_task_index->SetVisible(false); + m_second_task_index->SetText(""); + } + } + + if (additionalTask) { - u32 task_index = Level().GameTaskManager().GetTaskIndex(t, eTaskStateInProgress); - string32 buf; - xr_sprintf(buf, sizeof(buf), "%d / %d", task_index, task_count); + const auto task2_count = Level().GameTaskManager().GetTaskCount(eTaskStateInProgress, eTaskTypeAdditional); + + if (task2_count) + { + const auto task2_index = Level().GameTaskManager().GetTaskIndex(additionalTask, eTaskStateInProgress, eTaskTypeAdditional); + string32 buf; + xr_sprintf(buf, sizeof(buf), "%d / %d", task2_index, task2_count); + + m_second_task_index->SetVisible(true); + m_second_task_index->SetText(buf); + } + else + { + m_second_task_index->SetVisible(false); + m_second_task_index->SetText(""); + } } - if (m_task_wnd->IsShown()) - m_task_wnd->UpdateList(); } void CUITaskWnd::Show(bool status) @@ -210,7 +318,7 @@ void CUITaskWnd::Show(bool status) } else { - // m_task_wnd_show = false; + //m_task_wnd_show = false; m_task_wnd->Show(false); } } @@ -269,9 +377,15 @@ void CUITaskWnd::TaskShowMapSpot(CGameTask* task, bool show) const } } -void CUITaskWnd::OnTask1DbClicked(CUIWindow* ui, void* d) +void CUITaskWnd::OnTask1DbClicked(CUIWindow*, void*) +{ + CGameTask* task = Level().GameTaskManager().ActiveTask(eTaskTypeStoryline); + TaskSetTargetMap(task); +} + +void CUITaskWnd::OnTask2DbClicked(CUIWindow*, void*) { - CGameTask* task = Level().GameTaskManager().ActiveTask(); + CGameTask* task = Level().GameTaskManager().ActiveTask(eTaskTypeAdditional); TaskSetTargetMap(task); } @@ -298,8 +412,7 @@ void CUITaskWnd::OnShowQuestNpcs(CUIWindow* ui, void* d) ReloadTaskInfo(); } // -------------------------------------------------------------------------------------------------- -CUITaskItem::CUITaskItem() : m_owner(nullptr), m_hint_wt(500), show_hint(false), show_hint_can(false) {} -CUITaskItem::~CUITaskItem() {} +CUITaskItem::CUITaskItem() : m_owner(nullptr), show_hint_can(false), show_hint(false), m_hint_wt(500) {} void CUITaskItem::Init(CUIXml& uiXml, LPCSTR path) { diff --git a/src/xrGame/ui/UITaskWnd.h b/src/xrGame/ui/UITaskWnd.h index 7195f77ac08..f1a5b396445 100644 --- a/src/xrGame/ui/UITaskWnd.h +++ b/src/xrGame/ui/UITaskWnd.h @@ -24,17 +24,23 @@ class CUITaskWnd : public CUIWindow, public CUIWndCallback typedef CUIWindow inherited; CUIFrameWindow* m_background; + CUIFrameLineWnd* m_background2; + CUIStatic* m_center_background; CUIStatic* m_right_bottom_background; + CUIFrameLineWnd* m_task_split; CUIMapWnd* m_pMapWnd; CUITaskItem* m_pStoryLineTaskItem; + CUITaskItem* m_pSecondaryTaskItem; CUI3tButton* m_BtnTaskListWnd; + CUIStatic* m_second_task_index; CUIStatic* m_devider; u32 m_actual_frame; CUI3tButton* m_btn_focus; + CUI3tButton* m_btn_focus2; CUICheckButton* m_cbTreasures; CUICheckButton* m_cbQuestNpcs; @@ -67,29 +73,33 @@ class CUITaskWnd : public CUIWindow, public CUIWndCallback void ShowMapLegend(bool status) const; void Switch_ShowMapLegend() const; - bool IsTreasuresEnabled() { return m_bTreasuresEnabled; }; - bool IsQuestNpcsEnabled() { return m_bQuestNpcsEnabled; }; - bool IsSecondaryTasksEnabled() { return m_bSecondaryTasksEnabled; }; - bool IsPrimaryObjectsEnabled() { return m_bPrimaryObjectsEnabled; }; + bool IsTreasuresEnabled() const { return m_bTreasuresEnabled; }; + bool IsQuestNpcsEnabled() const { return m_bQuestNpcsEnabled; }; + bool IsSecondaryTasksEnabled() const { return m_bSecondaryTasksEnabled; }; + bool IsPrimaryObjectsEnabled() const { return m_bPrimaryObjectsEnabled; }; void TreasuresEnabled(bool enable) { m_bTreasuresEnabled = enable; - m_cbTreasures->SetCheck(enable); + if (m_cbTreasures) + m_cbTreasures->SetCheck(enable); }; void QuestNpcsEnabled(bool enable) { m_bQuestNpcsEnabled = enable; - m_cbQuestNpcs->SetCheck(enable); + if (m_cbQuestNpcs) + m_cbQuestNpcs->SetCheck(enable); }; void SecondaryTasksEnabled(bool enable) { m_bSecondaryTasksEnabled = enable; - m_cbSecondaryTasks->SetCheck(enable); + if (m_cbSecondaryTasks) + m_cbSecondaryTasks->SetCheck(enable); }; void PrimaryObjectsEnabled(bool enable) { m_bPrimaryObjectsEnabled = enable; - m_cbPrimaryObjects->SetCheck(enable); + if (m_cbPrimaryObjects) + m_cbPrimaryObjects->SetCheck(enable); }; void Show_TaskListWnd(bool status); @@ -102,6 +112,7 @@ class CUITaskWnd : public CUIWindow, public CUIWndCallback void OnPrevTaskClicked(); void xr_stdcall OnShowTaskListWnd(CUIWindow* w, void* d); void xr_stdcall OnTask1DbClicked(CUIWindow*, void*); + void xr_stdcall OnTask2DbClicked(CUIWindow*, void*); void xr_stdcall OnShowTreasures(CUIWindow*, void*); void xr_stdcall OnShowPrimaryObjects(CUIWindow*, void*); @@ -119,7 +130,7 @@ class CUITaskItem : public CUIWindow public: CUITaskItem(); - virtual ~CUITaskItem(); + virtual ~CUITaskItem() = default; virtual void OnFocusReceive(); virtual void OnFocusLost();