CInGameConsole.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * CInGameConsole.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../gui/CIntObject.h"
  12. class CInGameConsole : public CIntObject
  13. {
  14. private:
  15. struct TextState
  16. {
  17. std::string text;
  18. uint32_t timeOnScreen;
  19. };
  20. /// Currently visible texts in the overlay
  21. std::vector<TextState> texts;
  22. /// previously entered texts, for up/down arrows to work
  23. std::vector<std::string> previouslyEntered;
  24. /// displayed entry from previouslyEntered - if none it's -1
  25. int prevEntDisp;
  26. /// timeout for new texts (in ms)
  27. static constexpr int defaultTimeout = 10000;
  28. /// how many texts can be displayed simultaneously
  29. static constexpr int maxDisplayedTexts = 10;
  30. std::weak_ptr<IStatusBar> currentStatusBar;
  31. std::string enteredText;
  32. /// Returns true if console is active and player is currently entering text
  33. bool isEnteringText() const;
  34. void showRecentChatHistory();
  35. void addMessageSilent(const std::string & timeFormatted, const std::string & senderName, const std::string & messageText);
  36. public:
  37. void addMessage(const std::string & timeFormatted, const std::string & senderName, const std::string & messageText);
  38. void tick(uint32_t msPassed) override;
  39. void show(Canvas & to) override;
  40. void showAll(Canvas & to) override;
  41. void keyPressed(EShortcut key) override;
  42. void textInputted(const std::string & enteredText) override;
  43. void textEdited(const std::string & enteredText) override;
  44. bool captureThisKey(EShortcut key) override;
  45. void startEnteringText();
  46. void endEnteringText(bool processEnteredText);
  47. void refreshEnteredText();
  48. CInGameConsole();
  49. };