From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- .../Common/Tutorial/ProcedureCompoundTask.cpp | 263 +++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 Minecraft.Client/Common/Tutorial/ProcedureCompoundTask.cpp (limited to 'Minecraft.Client/Common/Tutorial/ProcedureCompoundTask.cpp') diff --git a/Minecraft.Client/Common/Tutorial/ProcedureCompoundTask.cpp b/Minecraft.Client/Common/Tutorial/ProcedureCompoundTask.cpp new file mode 100644 index 00000000..8603f765 --- /dev/null +++ b/Minecraft.Client/Common/Tutorial/ProcedureCompoundTask.cpp @@ -0,0 +1,263 @@ +#include "stdafx.h" +#include "ProcedureCompoundTask.h" + +ProcedureCompoundTask::~ProcedureCompoundTask() +{ + for(AUTO_VAR(it, m_taskSequence.begin()); it < m_taskSequence.end(); ++it) + { + delete (*it); + } +} + +void ProcedureCompoundTask::AddTask(TutorialTask *task) +{ + if(task != NULL) + { + m_taskSequence.push_back(task); + } +} + +int ProcedureCompoundTask::getDescriptionId() +{ + if(bIsCompleted) + return -1; + + // Return the id of the first task not completed + int descriptionId = -1; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + task->setAsCurrentTask(true); + descriptionId = task->getDescriptionId(); + break; + } + else if(task->getCompletionAction() == e_Tutorial_Completion_Complete_State) + { + bIsCompleted = true; + break; + } + } + return descriptionId; +} + +int ProcedureCompoundTask::getPromptId() +{ + if(bIsCompleted) + return -1; + + // Return the id of the first task not completed + int promptId = -1; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + promptId = task->getPromptId(); + break; + } + } + return promptId; +} + +bool ProcedureCompoundTask::isCompleted() +{ + // Return whether all tasks are completed + + bool allCompleted = true; + bool isCurrentTask = true; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + + if(allCompleted && isCurrentTask) + { + if(task->isCompleted()) + { + if(task->getCompletionAction() == e_Tutorial_Completion_Complete_State) + { + allCompleted = true; + break; + } + } + else + { + task->setAsCurrentTask(true); + allCompleted = false; + isCurrentTask = false; + } + } + else if (!allCompleted) + { + task->setAsCurrentTask(false); + } + } + + if(allCompleted) + { + //Disable all constraints + itEnd = m_taskSequence.end(); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->enableConstraints(false); + } + } + bIsCompleted = allCompleted; + return allCompleted; +} + +void ProcedureCompoundTask::onCrafted(shared_ptr item) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->onCrafted(item); + } +} + +void ProcedureCompoundTask::handleUIInput(int iAction) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->handleUIInput(iAction); + } +} + + +void ProcedureCompoundTask::setAsCurrentTask(bool active /*= true*/) +{ + bool allCompleted = true; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(allCompleted && !task->isCompleted()) + { + task->setAsCurrentTask(true); + allCompleted = false; + } + else if (!allCompleted) + { + task->setAsCurrentTask(false); + } + } +} + +bool ProcedureCompoundTask::ShowMinimumTime() +{ + if(bIsCompleted) + return false; + + bool showMinimumTime = false; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + showMinimumTime = task->ShowMinimumTime(); + break; + } + } + return showMinimumTime; +} + +bool ProcedureCompoundTask::hasBeenActivated() +{ + if(bIsCompleted) + return true; + + bool hasBeenActivated = false; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + hasBeenActivated = task->hasBeenActivated(); + break; + } + } + return hasBeenActivated; +} + +void ProcedureCompoundTask::setShownForMinimumTime() +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + task->setShownForMinimumTime(); + break; + } + } +} + +bool ProcedureCompoundTask::AllowFade() +{ + if(bIsCompleted) + return true; + + bool allowFade = true; + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + if(!task->isCompleted()) + { + allowFade = task->AllowFade(); + break; + } + } + return allowFade; +} + +void ProcedureCompoundTask::useItemOn(Level *level, shared_ptr item, int x, int y, int z,bool bTestUseOnly) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->useItemOn(level, item, x, y, z, bTestUseOnly); + } +} + +void ProcedureCompoundTask::useItem(shared_ptr item, bool bTestUseOnly) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->useItem(item, bTestUseOnly); + } +} + +void ProcedureCompoundTask::onTake(shared_ptr item, unsigned int invItemCountAnyAux, unsigned int invItemCountThisAux) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->onTake(item, invItemCountAnyAux, invItemCountThisAux); + } +} + +void ProcedureCompoundTask::onStateChange(eTutorial_State newState) +{ + AUTO_VAR(itEnd, m_taskSequence.end()); + for(AUTO_VAR(it, m_taskSequence.begin()); it < itEnd; ++it) + { + TutorialTask *task = *it; + task->onStateChange(newState); + } +} \ No newline at end of file -- cgit v1.2.3