Quiz System Documentation
The Virtual Anatomy project includes a comprehensive Quiz system designed to test user knowledge of human anatomy. This documentation outlines its architecture, data flow, and key components.
1. Architecture Overview
The Quiz system is built with a clear separation of concerns, utilizing several C++ classes to manage quiz data, UI flow, and interaction with a backend API.
Key architectural components include:
UQuizManager: Handles all network communication with the backend API to fetch quizzes and submit results. It acts as the data layer for quizzes.UQuizUIManager: Manages the entire user interface flow for the quiz system, from year selection to displaying questions and the end screen. It orchestrates the display of various quiz widgets.- Quiz Data Structures: C++
USTRUCTs define the format of quiz content and user submissions. - Quiz Widgets: A hierarchy of
UUserWidgetclasses handles the visual presentation and user interaction for different stages and types of quiz questions. UMeshKnowledgeBaseDataAsset: A data asset that provides a local lookup for anatomical mesh and group IDs, used by "select organ" question types.
2. Quiz System Data Flow
The typical flow of a user interacting with the Quiz system is as follows:
- Initialization: When the quiz level loads,
UQuizUIManager::Initializeis called from theACPP_GameMode. This loads theUMeshKnowledgeBaseDataAssetand presents theUStudyYearSelectorWidgetto the user. - Study Year Selection: The user selects a study year via the
UStudyYearSelectorWidget. This selection triggersUQuizUIManager::HandleStudyYearSelected. - Fetching Quizzes:
UQuizUIManagerinstructs theUQuizManagertoFetchQuizzesfor the selected study year. TheUQuizManagersends an HTTP GET request to the backend. - Quiz Overview Display: Upon receiving a successful response,
UQuizManagerbroadcasts the fetched quiz data.UQuizUIManager'sCurrentOverviewwidget (anUCPP_QuizOverview) listens to this event and populates a list of available quizzes. - Quiz Details: The user selects a quiz from the overview.
UQuizUIManager::ShowQuizDetailsis called, displaying anUCPP_QuizDetailsWidgetwith more information about the chosen quiz. - Starting Quiz: The user clicks "Start Quiz" on the details screen.
UQuizUIManager::StartQuizis called, initializing the quiz state (current question index, empty accumulated answers). - Displaying Questions:
UQuizUIManager::ShowNextQuestiondetermines the type of the current question (FQuizQuestion::Type) and dynamically creates the appropriate widget (UCPP_MultipleChoiceWidget,UCPP_TrueFalseWidget,UCPP_OpenEndedWidget, orUCPP_SelectOrganWidget). The question text and options are then initialized. - Answering Questions: The user interacts with the active question widget (e.g., clicking an answer button, typing text, selecting an organ).
- For "Select Organ" questions,
UCPP_SelectOrganWidgetsubscribes toUMeshSelector::OnMeshClickedto capture user clicks on 3D anatomical models. It then uses theUMeshKnowledgeBaseDataAssetto validate or retrieve information about the clicked mesh.
- For "Select Organ" questions,
- Processing Answers: When an answer is submitted on a question widget, its
OnQuestionAnswereddelegate is broadcast.UQuizUIManager::HandleQuestionAnsweredInternalBindercaptures this, extracts the answer data in the correct format (FQuizSubmittedAnswerPayload), and then callsUQuizUIManager::HandleQuestionAnswered. - Accumulating Answers:
UQuizUIManager::HandleQuestionAnsweredadds theFQuizSubmittedAnswerPayloadto an internal array ofAccumulatedAnswersand increments theCurrentQuestionIndex. It then callsShowNextQuestionagain. - Quiz Completion & Submission: When all questions have been answered (
CurrentQuestionIndexexceeds total questions),UQuizUIManager::FinalizeAndSubmitQuizis called. This constructs theFQuizSubmissionPayloadwith all accumulated answers and a timestamp. - Sending Submission:
UQuizUIManager::SendQuizSubmissionToAPIserializes the payload to JSON and sends an HTTP POST request to the backend/api/submissionsendpoint. - Submission Response:
UQuizUIManager::OnQuizSubmissionResponseReceivedhandles the backend's response, logging success or failure. Regardless of the outcome, it displays theUCPP_QuizEndScreenWidget.
3. Key Components
This section details the individual C++ classes that form the Quiz System.
UQuizManager
UQuizUIManager
UMeshKnowledgeBaseDataAsset
4. Quiz Data Structures
This section details the C++ USTRUCTs that define the data models used throughout the quiz system.
FQuizData
FQuizQuestion
FQuizAnswer
FQuizSubmissionPayload
FMeshCatalogEntryUE and FOrganGroupUE
5. Quiz Widgets
This section details the UI components used in the Quiz System.