Study Dungeon  1.0.0
A group project for COSC345
edit_flashcard.h
Go to the documentation of this file.
1 
11 #pragma once
12 #ifndef EDIT_DECK_SCENE_H
13 #define EDIT_DECK_SCENE_H
14 
15 #include "artwork.h"
16 #include "deck.h"
17 #include "menu.h"
18 #include "settings_scene.h"
19 #include "util.h"
20 #include <algorithm>
21 #include <conio.h>
22 #include <functional>
23 #include <iostream>
24 #include <limits>
25 #include <memory>
26 #include <sstream>
27 #include <vector>
28 
29 namespace FlashcardEdit
30 {
31 
32 
42 {
43 public:
52  std::function<void()> goBack,
53  std::function<void(FlashCardDeck &)> openEditFlashcardScene,
54  StudySettings &studySettings);
55 
56 
61  void init() override;
62 
69  void update() override;
70 
78  void render(std::shared_ptr<ConsoleUI::ConsoleWindow> window) override;
79 
86  void handleInput() override;
87 
92  void setStaticDrawn(bool staticDrawn) override;
93 
99  void drawBookshelf(std::shared_ptr<ConsoleUI::ConsoleWindow> window);
100 
107  void loadDecks();
108 
113  const std::vector<FlashCardDeck> &getDecks() const
114  {
115  return m_decks;
116  }
117 
122  size_t getSelectedDeckIndex() const
123  {
124  return m_selectedDeckIndex;
125  }
126 
131  void setSelectedDeckIndex(size_t index)
132  {
133  m_selectedDeckIndex = index;
134  }
135 
140  int getCurrentPage() const
141  {
142  return m_currentPage;
143  }
144 
149  void setCurrentPage(int page)
150  {
151  m_currentPage = page;
152  }
153 
158  size_t getMaxCardsPerPage() const
159  {
160  return m_maxCardsPerPage;
161  }
162 
167  void setMaxCardsPerPage(size_t maxCards)
168  {
169  m_maxCardsPerPage = maxCards;
170  }
171 
176  bool getNeedsRedraw() const
177  {
178  return m_needsRedraw;
179  }
180 
185  void setNeedsRedraw(bool needsRedraw)
186  {
187  m_needsRedraw = needsRedraw;
188  }
189 
195  {
196  return m_settings;
197  }
198 
203  void setStudySettings(const StudySettings &settings)
204  {
205  m_settings = settings;
206  }
207 
208 private:
209  ConsoleUI::UIManager &m_uiManager;
210  std::function<void()> m_goBack;
211  std::function<void(FlashCardDeck &)> m_openEditFlashcardScene;
212  std::vector<FlashCardDeck> m_decks;
213  size_t m_selectedDeckIndex;
214  int m_currentPage;
215  size_t m_maxCardsPerPage;
216  bool m_needsRedraw;
217 
218  bool m_staticDrawn = false;
219  int m_prevBookshelfIndex = -1;
220  bool m_paging = false;
221  std::chrono::steady_clock::time_point m_lastPageChangeTime;
222  const std::chrono::milliseconds m_pageChangeDelay{200};
223  int bookshelfIndex = 0;
224  StudySettings m_settings;
225 
226 
233  void addNewDeck();
234 
241  void deleteDeck();
242 
249  void renameDeck();
250 
254  void drawLibrarianComment();
255 };
256 
265 {
266 public:
275  FlashCardDeck &deck,
276  std::function<void()> goBack,
277  StudySettings &studySettings);
278 
283  void init() override;
284 
291  void update() override;
292 
301  void render(std::shared_ptr<ConsoleUI::ConsoleWindow> window) override;
302 
309  void handleInput() override;
310 
315  void setStaticDrawn(bool staticDrawn) override;
316 
321  const FlashCardDeck &getDeck() const
322  {
323  return m_deck;
324  }
325 
330  size_t getSelectedCardIndex() const
331  {
332  return m_selectedCardIndex;
333  }
334 
339  void setSelectedCardIndex(size_t index)
340  {
341  m_selectedCardIndex = index;
342  }
343 
348  int getCurrentPage() const
349  {
350  return m_currentPage;
351  }
352 
357  void setCurrentPage(int page)
358  {
359  m_currentPage = page;
360  }
361 
366  size_t getMaxCardsPerPage() const
367  {
368  return m_maxCardsPerPage;
369  }
370 
375  void setMaxCardsPerPage(size_t maxCards)
376  {
377  m_maxCardsPerPage = maxCards;
378  }
379 
384  bool getNeedsRedraw() const
385  {
386  return m_needsRedraw;
387  }
388 
393  void setNeedsRedraw(bool needsRedraw)
394  {
395  m_needsRedraw = needsRedraw;
396  }
397 
403  {
404  return m_settings;
405  }
406 
411  void setStudySettings(const StudySettings &settings)
412  {
413  m_settings = settings;
414  }
415 
416 private:
417  ConsoleUI::UIManager &m_uiManager;
418  FlashCardDeck &m_deck;
419  std::function<void()> m_goBack;
420  size_t m_selectedCardIndex;
421  int m_currentPage;
422  size_t m_maxCardsPerPage;
423  bool m_needsRedraw;
424 
425  bool m_staticDrawn = false;
426  StudySettings m_settings;
427 
435  void editSelectedCard();
436 
444  void addNewCard();
445 
452  void deleteSelectedCard();
453 
457  void drawLibrarianComment();
458 };
459 
460 } // namespace FlashcardEdit
461 
462 #endif // EDIT_DECK_SCENE_H
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
Represents the scene for editing flashcard decks.
Definition: edit_flashcard.h:42
void setNeedsRedraw(bool needsRedraw)
Sets the flag indicating if the scene needs redrawing.
Definition: edit_flashcard.h:185
void setCurrentPage(int page)
Sets the current page number for deck content display.
Definition: edit_flashcard.h:149
size_t getMaxCardsPerPage() const
Gets the maximum number of cards displayed per page.
Definition: edit_flashcard.h:158
void loadDecks()
Loads all flashcard decks from the file system.
Definition: edit_flashcard.cpp:378
EditDeckScene(ConsoleUI::UIManager &uiManager, std::function< void()> goBack, std::function< void(FlashCardDeck &)> openEditFlashcardScene, StudySettings &studySettings)
Constructs an EditDeckScene object.
Definition: edit_flashcard.cpp:368
size_t getSelectedDeckIndex() const
Gets the index of the currently selected deck.
Definition: edit_flashcard.h:122
void update() override
Updates the scene state.
Definition: edit_flashcard.cpp:392
void drawBookshelf(std::shared_ptr< ConsoleUI::ConsoleWindow > window)
Draws the books shelf art.
Definition: edit_flashcard.cpp:402
bool getNeedsRedraw() const
Gets the flag indicating if the scene needs redrawing.
Definition: edit_flashcard.h:176
void render(std::shared_ptr< ConsoleUI::ConsoleWindow > window) override
Renders the scene on the console window.
Definition: edit_flashcard.cpp:442
int getCurrentPage() const
Gets the current page number for deck content display.
Definition: edit_flashcard.h:140
void setStaticDrawn(bool staticDrawn) override
Sets the static drawn state of the scene.
Definition: edit_flashcard.cpp:397
const std::vector< FlashCardDeck > & getDecks() const
Gets the vector of loaded flashcard decks.
Definition: edit_flashcard.h:113
void setStudySettings(const StudySettings &settings)
Sets the study settings object.
Definition: edit_flashcard.h:203
void setSelectedDeckIndex(size_t index)
Sets the index of the currently selected deck.
Definition: edit_flashcard.h:131
void handleInput() override
Handles user input for the scene.
Definition: edit_flashcard.cpp:515
void init() override
Initialises the scene.
Definition: edit_flashcard.cpp:386
void setMaxCardsPerPage(size_t maxCards)
Sets the maximum number of cards displayed per page.
Definition: edit_flashcard.h:167
StudySettings & getStudySettings()
Gets the study settings object.
Definition: edit_flashcard.h:194
Represents the scene for editing individual flashcards within a deck.
Definition: edit_flashcard.h:265
bool getNeedsRedraw() const
Gets the flag indicating if the scene needs redrawing.
Definition: edit_flashcard.h:384
void handleInput() override
Handles user input for the scene.
Definition: edit_flashcard.cpp:109
void render(std::shared_ptr< ConsoleUI::ConsoleWindow > window) override
Renders the scene on the console window.
Definition: edit_flashcard.cpp:55
StudySettings & getStudySettings()
Gets the study settings object.
Definition: edit_flashcard.h:402
size_t getMaxCardsPerPage() const
Gets the maximum number of flashcards displayed per page.
Definition: edit_flashcard.h:366
EditFlashcardScene(ConsoleUI::UIManager &uiManager, FlashCardDeck &deck, std::function< void()> goBack, StudySettings &studySettings)
Constructs an EditFlashcardScene object.
Definition: edit_flashcard.cpp:20
size_t getSelectedCardIndex() const
Gets the index of the currently selected flashcard.
Definition: edit_flashcard.h:330
void setSelectedCardIndex(size_t index)
Sets the index of the currently selected flashcard.
Definition: edit_flashcard.h:339
void setStudySettings(const StudySettings &settings)
Sets the study settings object.
Definition: edit_flashcard.h:411
void update() override
Updates the scene state.
Definition: edit_flashcard.cpp:34
void init() override
Initialises the scene.
Definition: edit_flashcard.cpp:29
void setMaxCardsPerPage(size_t maxCards)
Sets the maximum number of flashcards displayed per page.
Definition: edit_flashcard.h:375
const FlashCardDeck & getDeck() const
Gets the flashcard deck being edited.
Definition: edit_flashcard.h:321
void setStaticDrawn(bool staticDrawn) override
Sets the static drawn state of the scene.
Definition: edit_flashcard.cpp:39
void setNeedsRedraw(bool needsRedraw)
Sets the flag indicating if the scene needs redrawing.
Definition: edit_flashcard.h:393
void setCurrentPage(int page)
Sets the current page number for flashcard list display.
Definition: edit_flashcard.h:357
int getCurrentPage() const
Gets the current page number for flashcard list display.
Definition: edit_flashcard.h:348
Object for the settings relating to the study sessions component.
Definition: settings_scene.h:27
Functions and classes relating to flashcards.
Classes and functions for the UI system.
The menu and settings for the over all game.
Contains useful helper functions.