CInfoBar.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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;
  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. struct Cache
  98. {
  99. std::vector<Component> compsToDisplay;
  100. std::string message;
  101. int textH;
  102. bool tiny;
  103. Cache(std::vector<Component> comps, std::string msg, int textH, bool tiny):
  104. compsToDisplay(std::move(comps)),
  105. message(std::move(msg)),
  106. textH(textH),
  107. tiny(tiny)
  108. {}
  109. };
  110. VisibleComponentInfo(const Cache & c): VisibleComponentInfo(c.compsToDisplay, c.message, c.textH, c.tiny) {}
  111. VisibleComponentInfo(const std::vector<Component> & compsToDisplay, std::string message, int textH, bool tiny);
  112. };
  113. enum EState
  114. {
  115. EMPTY, HERO, TOWN, DATE, GAME, AITURN, COMPONENT
  116. };
  117. std::shared_ptr<CVisibleInfo> visibleInfo;
  118. EState state;
  119. uint32_t timerCounter;
  120. bool shouldPopAll = false;
  121. std::queue<std::pair<VisibleComponentInfo::Cache, int>> componentsQueue;
  122. //private helper for showing components
  123. void showComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
  124. void pushComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
  125. void prepareComponents(const std::vector<Component> & comps, std::string message, int timer);
  126. void popComponents(bool remove = false);
  127. //removes all information about current state, deactivates timer (if any)
  128. void reset();
  129. void tick(uint32_t msPassed) override;
  130. void clickLeft(tribool down, bool previousState) override;
  131. void clickRight(tribool down, bool previousState) override;
  132. void hover(bool on) override;
  133. void playNewDaySound();
  134. void setTimer(uint32_t msToTrigger);
  135. public:
  136. CInfoBar(const Rect & pos);
  137. CInfoBar(const Point & pos);
  138. /// show new day/week animation
  139. void showDate();
  140. /// show components for 3 seconds. Used to display picked up resources. Can display up to 8 components
  141. void pushComponents(const std::vector<Component> & comps, std::string message, int timer = 3000);
  142. /// Remove all queued components
  143. void popAll();
  144. /// Request infobar to pop all after next InfoWindow arrives.
  145. void requestPopAll();
  146. /// print enemy turn progress
  147. void startEnemyTurn(PlayerColor color);
  148. /// reset to default view - selected object
  149. void showSelection();
  150. /// show hero\town information
  151. void showHeroSelection(const CGHeroInstance * hero);
  152. void showTownSelection(const CGTownInstance * town);
  153. /// for 3 seconds shows amount of town halls and players status
  154. void showGameStatus();
  155. /// check if infobar is showed something about pickups
  156. bool showingComponents();
  157. };