CInfoBar.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * CInfoBar.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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. struct Component;
  16. class PlayerColor;
  17. VCMI_LIB_NAMESPACE_END
  18. class CAnimImage;
  19. class CShowableAnim;
  20. class CComponent;
  21. class CComponentBox;
  22. class CHeroTooltip;
  23. class CTownTooltip;
  24. class CLabel;
  25. class CTextBox;
  26. /// Info box which shows next week/day information, hold the current date
  27. class CInfoBar : public CIntObject
  28. {
  29. private:
  30. /// Infobar actually have a fixed size
  31. /// Declare before to compute correct size of widgets
  32. static constexpr int width = 192;
  33. static constexpr int height = 192;
  34. static constexpr int offset = 4;
  35. //all visible information located in one object - for ease of replacing
  36. class CVisibleInfo : public CIntObject
  37. {
  38. public:
  39. static constexpr int offset_x = 8;
  40. static constexpr int offset_y = 12;
  41. void show(SDL_Surface * to) override;
  42. protected:
  43. std::shared_ptr<CPicture> background;
  44. std::list<std::shared_ptr<CIntObject>> forceRefresh;
  45. CVisibleInfo();
  46. };
  47. static constexpr int data_width = width - 2 * CVisibleInfo::offset_x;
  48. static constexpr int data_height = height - 2 * CVisibleInfo::offset_y + 4; //yes, +4 is required
  49. class EmptyVisibleInfo : public CVisibleInfo
  50. {
  51. public:
  52. EmptyVisibleInfo();
  53. };
  54. class VisibleHeroInfo : public CVisibleInfo
  55. {
  56. std::shared_ptr<CHeroTooltip> heroTooltip;
  57. public:
  58. VisibleHeroInfo(const CGHeroInstance * hero);
  59. };
  60. class VisibleTownInfo : public CVisibleInfo
  61. {
  62. std::shared_ptr<CTownTooltip> townTooltip;
  63. public:
  64. VisibleTownInfo(const CGTownInstance * town);
  65. };
  66. class VisibleDateInfo : public CVisibleInfo
  67. {
  68. std::shared_ptr<CShowableAnim> animation;
  69. std::shared_ptr<CLabel> label;
  70. std::string getNewDayName();
  71. public:
  72. VisibleDateInfo();
  73. };
  74. class VisibleEnemyTurnInfo : public CVisibleInfo
  75. {
  76. std::shared_ptr<CAnimImage> banner;
  77. std::shared_ptr<CShowableAnim> glass;
  78. std::shared_ptr<CShowableAnim> sand;
  79. public:
  80. VisibleEnemyTurnInfo(PlayerColor player);
  81. };
  82. class VisibleGameStatusInfo : public CVisibleInfo
  83. {
  84. std::shared_ptr<CLabel> allyLabel;
  85. std::shared_ptr<CLabel> enemyLabel;
  86. std::vector<std::shared_ptr<CAnimImage>> flags;
  87. std::vector<std::shared_ptr<CAnimImage>> hallIcons;
  88. std::vector<std::shared_ptr<CLabel>> hallLabels;
  89. public:
  90. VisibleGameStatusInfo();
  91. };
  92. class VisibleComponentInfo : public CVisibleInfo
  93. {
  94. std::shared_ptr<CComponentBox> comps;
  95. std::shared_ptr<CTextBox> text;
  96. public:
  97. VisibleComponentInfo(const std::vector<Component> & compsToDisplay, std::string message, int textH, bool tiny);
  98. };
  99. enum EState
  100. {
  101. EMPTY, HERO, TOWN, DATE, GAME, AITURN, COMPONENT
  102. };
  103. std::shared_ptr<CVisibleInfo> visibleInfo;
  104. EState state;
  105. //private helper for showing components
  106. void showComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny = false, int timer = 3000);
  107. //removes all information about current state, deactivates timer (if any)
  108. void reset();
  109. void tick() override;
  110. void clickLeft(tribool down, bool previousState) override;
  111. void clickRight(tribool down, bool previousState) override;
  112. void hover(bool on) override;
  113. void playNewDaySound();
  114. public:
  115. CInfoBar(const Rect & pos);
  116. CInfoBar(const Point & pos);
  117. /// show new day/week animation
  118. void showDate();
  119. /// show components for 3 seconds. Used to display picked up resources. Can display up to 8 components
  120. bool tryShowComponents(const std::vector<Component> & comps, std::string message, int timer = 3000);
  121. /// print enemy turn progress
  122. void startEnemyTurn(PlayerColor color);
  123. /// reset to default view - selected object
  124. void showSelection();
  125. /// show hero\town information
  126. void showHeroSelection(const CGHeroInstance * hero);
  127. void showTownSelection(const CGTownInstance * town);
  128. /// for 3 seconds shows amount of town halls and players status
  129. void showGameStatus();
  130. /// check if infobar is showed something about pickups
  131. bool showingComponents();
  132. /// get estimated component height for InfoBar
  133. int getEstimatedComponentHeight(int numComps) const;
  134. };