BattleConsole.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * BattleConsole.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 "../windows/CWindowObject.h"
  12. class BattleInterface;
  13. class CFilledTexture;
  14. class CButton;
  15. class TransparentFilledRectangle;
  16. class CTextBox;
  17. class BattleConsoleWindow : public CWindowObject
  18. {
  19. private:
  20. std::shared_ptr<CFilledTexture> backgroundTexture;
  21. std::shared_ptr<CButton> buttonOk;
  22. std::shared_ptr<TransparentFilledRectangle> textBoxBackgroundBorder;
  23. std::shared_ptr<CTextBox> textBox;
  24. public:
  25. BattleConsoleWindow(const std::string & text);
  26. };
  27. /// Class which shows the console at the bottom of the battle screen and manages the text of the console
  28. class BattleConsole : public CIntObject, public IStatusBar
  29. {
  30. private:
  31. const BattleInterface & owner;
  32. std::shared_ptr<CPicture> background;
  33. /// List of all texts added during battle, essentially - log of entire battle
  34. std::vector<std::string> logEntries;
  35. /// Current scrolling position, to allow showing older entries via scroll buttons
  36. int scrollPosition;
  37. /// current hover text set on mouse move, takes priority over log entries
  38. std::string hoverText;
  39. /// current text entered via in-game console, takes priority over both log entries and hover text
  40. std::string consoleText;
  41. /// if true then we are currently entering console text
  42. bool enteringText;
  43. /// splits text into individual strings for battle log
  44. std::vector<std::string> splitText(const std::string & text);
  45. /// select line(s) that will be visible in UI
  46. std::vector<std::string> getVisibleText() const;
  47. public:
  48. BattleConsole(const BattleInterface & owner, const std::shared_ptr<CPicture> & backgroundSource, const Point & objectPos, const Point & imagePos, const Point & size);
  49. void showAll(Canvas & to) override;
  50. void deactivate() override;
  51. void clickPressed(const Point & cursorPosition) override;
  52. bool addText(const std::string & text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  53. void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
  54. void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
  55. // IStatusBar interface
  56. void write(const std::string & Text) override;
  57. void clearIfMatching(const std::string & Text) override;
  58. void clear() override;
  59. void setEnteringMode(bool on) override;
  60. void setEnteredText(const std::string & text) override;
  61. };