Study Dungeon  1.0.0
A group project for COSC345
flashcard_scene.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "artwork.h"
15 #include "deck.h"
16 #include "edit_flashcard.h"
17 #include "menu.h"
18 #include "settings_scene.h"
19 #include "util.h"
20 #include <algorithm>
21 #include <chrono>
22 #include <conio.h>
23 #include <functional>
24 #include <memory>
25 #include <numeric>
26 #include <random>
27 #include <sstream>
28 #include <vector>
29 
30 namespace FlashcardApp
31 {
32 
42 {
43 public:
52  std::function<void()> goBack,
53  std::function<void(const FlashCardDeck &)> openDeck,
54  StudySettings &settings);
55 
62  void init() override;
63 
70  void update() override;
71 
77  void render(std::shared_ptr<ConsoleUI::ConsoleWindow> window) override;
78 
85  void handleInput() override;
86 
87 
94  void loadDecks();
95 
100  void setStaticDrawn(bool staticDrawn) override;
101 
102  void setDecksNeedReload(bool needReload)
103  {
104  m_decksNeedReload = needReload;
105  }
106 
107  void drawBookshelf(std::shared_ptr<ConsoleUI::ConsoleWindow> window);
108 
109  std::vector<FlashCardDeck> m_decks;
110  size_t m_selectedDeckIndex = 0;
111  int m_currentPage = 0;
112 
113 
114 private:
115  ConsoleUI::UIManager &m_uiManager;
116  std::function<void()> m_goBack;
117  std::function<void(const FlashCardDeck &)> m_openDeck;
118  bool m_needsRedraw = true;
119  int m_maxCardsPerPage = 0;
120 
121  bool m_staticDrawn = false;
122  bool m_decksNeedReload = false;
123  std::chrono::steady_clock::time_point m_lastPageChangeTime;
124  const std::chrono::milliseconds m_pageChangeDelay{200};
125  StudySettings m_settings;
126 
127  bool m_paging = false;
128  int m_prevBookshelfIndex = -1;
129  int bookshelfIndex = 0;
130 };
131 
141 {
142 public:
152  const FlashCardDeck &deck,
153  std::function<void()> goBack,
154  std::function<void()> goToDeckSelection,
155  std::function<void(const std::vector<int> &, int, bool)> showResults,
156  StudySettings &studySettings);
163  void init() override;
164 
172  void update() override;
173 
179  void render(std::shared_ptr<ConsoleUI::ConsoleWindow> window) override;
180 
187  void handleInput() override;
188 
193  void setStaticDrawn(bool staticDrawn) override;
194 
195  void setDecksNeedReload(bool needReload)
196  {
197  m_decksNeedReload = needReload;
198  }
199  void updateCardDifficulty(size_t cardIndex, CardDifficulty difficulty);
200  void initializeCardOrder();
201 
205  void nextCard();
206 
207 
208  std::vector<size_t> m_cardOrder;
210  size_t m_currentCardIndex = 0;
211  bool m_showAnswer = false;
212  bool m_lastAnswerDisplayed;
213 
214 
215 private:
221  void selectDifficulty(CardDifficulty difficulty);
222 
223 
224  void saveUpdatedDeck();
225  // int flashcard_limit = 10;
226  bool empty = false;
227  StudySettings m_settings;
228 
229  bool m_decksNeedReload = false;
230 
231 
235  void endSession(bool sessionComplete);
236 
237  ConsoleUI::UIManager &m_uiManager;
238  std::vector<int> m_difficultyCount = {0, 0, 0};
239  std::function<void()> m_goBack;
240  std::function<void(const std::vector<int> &, int, bool)> m_showResults;
241  bool m_needsRedraw;
242 
243  bool m_staticDrawn = false;
244  StudySettings m_studySetting;
245 
246  std::string m_lastQuestionDisplayed;
247  bool m_answerDrawn;
248  int m_score;
249 };
250 
261 {
262 public:
273  const std::vector<int> &difficultyCount,
274  int score,
275  std::function<void()> goToMainMenu,
276  std::function<void()> goToDeckSelection,
277  std::function<void()> goToGame,
278  bool sessionComplete);
279  void init() override;
280 
287  void update() override;
288 
294  void render(std::shared_ptr<ConsoleUI::ConsoleWindow> window) override;
295 
302  void handleInput() override;
303 
308  void setStaticDrawn(bool staticDrawn) override;
309 
310 private:
311  ConsoleUI::UIManager &m_uiManager;
312  std::vector<int> m_difficultyCount;
313  std::function<void()> m_goToMainMenu;
314  std::function<void()> m_goToDeckSelection;
315  std::function<void()> m_goToGame;
316  bool m_needsRedraw;
317  std::string phrase;
318 
319  bool m_staticDrawn = false;
320  bool m_sessionComplete;
321  int m_score;
322 };
323 
324 } // namespace FlashcardApp
Defines variables containg ASCII artwork.
Defines a UI scene.
Definition: menu.h:629
Defines the UI manager.
Definition: menu.h:675
Class that defines a "deck" of flashcards.
Definition: deck.h:113
A scene for browsing and selecting flashcard decks.
Definition: flashcard_scene.h:42
void setStaticDrawn(bool staticDrawn) override
Sets the static drawn state of the scene.
Definition: flashcard_scene.cpp:76
void update() override
Update the scene state.
Definition: flashcard_scene.cpp:71
void init() override
Initialize the scene.
Definition: flashcard_scene.cpp:65
void render(std::shared_ptr< ConsoleUI::ConsoleWindow > window) override
Render the scene to the console window.
Definition: flashcard_scene.cpp:81
std::vector< FlashCardDeck > m_decks
Vector of loaded flashcard decks.
Definition: flashcard_scene.h:109
size_t m_selectedDeckIndex
Index of the currently selected deck.
Definition: flashcard_scene.h:110
void handleInput() override
Handle user input for the scene.
Definition: flashcard_scene.cpp:160
void loadDecks()
Load available flashcard decks from storage.
Definition: flashcard_scene.cpp:28
BrowseDecksScene(ConsoleUI::UIManager &uiManager, std::function< void()> goBack, std::function< void(const FlashCardDeck &)> openDeck, StudySettings &settings)
Construct a new BrowseDecksScene object.
Definition: flashcard_scene.cpp:17
int m_currentPage
Current page number when viewing deck contents.
Definition: flashcard_scene.h:111
A scene for studying flashcards from a selected deck.
Definition: flashcard_scene.h:141
bool m_showAnswer
Flag indicating whether the answer is currently visible.
Definition: flashcard_scene.h:211
size_t m_currentCardIndex
Index of the current flashcard being shown.
Definition: flashcard_scene.h:210
void render(std::shared_ptr< ConsoleUI::ConsoleWindow > window) override
Render the scene to the console window.
Definition: flashcard_scene.cpp:373
void handleInput() override
Handle user input for the scene.
Definition: flashcard_scene.cpp:465
void nextCard()
Move to the next flashcard in the deck.
Definition: flashcard_scene.cpp:574
void update() override
Update the scene state.
Definition: flashcard_scene.cpp:347
FlashcardScene(ConsoleUI::UIManager &uiManager, const FlashCardDeck &deck, std::function< void()> goBack, std::function< void()> goToDeckSelection, std::function< void(const std::vector< int > &, int, bool)> showResults, StudySettings &studySettings)
Construct a new FlashcardScene object.
Definition: flashcard_scene.cpp:266
std::vector< size_t > m_cardOrder
Randomized order of flashcards for the session.
Definition: flashcard_scene.h:208
void setStaticDrawn(bool staticDrawn) override
Sets the static drawn state of the scene.
Definition: flashcard_scene.cpp:368
FlashCardDeck m_deck
The flashcard deck being studied.
Definition: flashcard_scene.h:209
void init() override
Initialize the scene.
Definition: flashcard_scene.cpp:363
A scene for displaying the results of a flashcard study session.
Definition: flashcard_scene.h:261
void update() override
Update the scene state.
Definition: flashcard_scene.cpp:640
void setStaticDrawn(bool staticDrawn) override
Sets the static drawn state of the scene.
Definition: flashcard_scene.cpp:645
void handleInput() override
Handle user input for the scene.
Definition: flashcard_scene.cpp:739
void render(std::shared_ptr< ConsoleUI::ConsoleWindow > window) override
Render the scene to the console window.
Definition: flashcard_scene.cpp:651
ResultsScene(ConsoleUI::UIManager &uiManager, const std::vector< int > &difficultyCount, int score, std::function< void()> goToMainMenu, std::function< void()> goToDeckSelection, std::function< void()> goToGame, bool sessionComplete)
Construct a new ResultsScene object.
Definition: flashcard_scene.cpp:599
void init() override
Initialise the scene.
Definition: flashcard_scene.cpp:635
Object for the settings relating to the study sessions component.
Definition: settings_scene.h:27
Functions and classes relating to flashcards.
CardDifficulty
The possible difficulties for a flashcard.
Definition: deck.h:35
Classes and functions that are used in the UI scene for editing flashcards.
Classes and functions for the UI system.
The menu and settings for the over all game.
Contains useful helper functions.