CInfoBar.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 CInteractableHeroTooltip;
  24. class CTownTooltip;
  25. class CInteractableTownTooltip;
  26. class CLabel;
  27. class CMultiLineLabel;
  28. /// Info box which shows next week/day information, hold the current date
  29. class CInfoBar : public CIntObject
  30. {
  31. private:
  32. /// Infobar actually have a fixed size
  33. /// Declare before to compute correct size of widgets
  34. static constexpr int width = 192;
  35. static constexpr int height = 192;
  36. static constexpr int offset = 4;
  37. //all visible information located in one object - for ease of replacing
  38. class CVisibleInfo : public CIntObject
  39. {
  40. public:
  41. static constexpr int offset_x = 8;
  42. static constexpr int offset_y = 12;
  43. void show(Canvas & to) override;
  44. protected:
  45. std::shared_ptr<CPicture> background;
  46. std::list<std::shared_ptr<CIntObject>> forceRefresh;
  47. CVisibleInfo();
  48. };
  49. static constexpr int data_width = width - 2 * CVisibleInfo::offset_x;
  50. static constexpr int data_height = height - 2 * CVisibleInfo::offset_y;
  51. class EmptyVisibleInfo : public CVisibleInfo
  52. {
  53. public:
  54. EmptyVisibleInfo();
  55. };
  56. class VisibleHeroInfo : public CVisibleInfo
  57. {
  58. std::variant<std::shared_ptr<CHeroTooltip>, std::shared_ptr<CInteractableHeroTooltip>> heroTooltip;
  59. public:
  60. VisibleHeroInfo(const CGHeroInstance * hero);
  61. };
  62. class VisibleTownInfo : public CVisibleInfo
  63. {
  64. std::variant<std::shared_ptr<CTownTooltip>, std::shared_ptr<CInteractableTownTooltip>> townTooltip;
  65. public:
  66. VisibleTownInfo(const CGTownInstance * town);
  67. };
  68. class VisibleDateInfo : public CVisibleInfo
  69. {
  70. std::shared_ptr<CShowableAnim> animation;
  71. std::shared_ptr<CLabel> label;
  72. std::string getNewDayName();
  73. public:
  74. VisibleDateInfo();
  75. };
  76. class VisibleEnemyTurnInfo : public CVisibleInfo
  77. {
  78. std::shared_ptr<CAnimImage> banner;
  79. std::shared_ptr<CShowableAnim> glass;
  80. std::shared_ptr<CShowableAnim> sand;
  81. public:
  82. VisibleEnemyTurnInfo(PlayerColor player);
  83. };
  84. class VisibleGameStatusInfo : public CVisibleInfo
  85. {
  86. std::shared_ptr<CLabel> allyLabel;
  87. std::shared_ptr<CLabel> enemyLabel;
  88. std::vector<std::shared_ptr<CAnimImage>> flags;
  89. std::vector<std::shared_ptr<CAnimImage>> hallIcons;
  90. std::vector<std::shared_ptr<CLabel>> hallLabels;
  91. public:
  92. VisibleGameStatusInfo();
  93. };
  94. class VisibleComponentInfo : public CVisibleInfo
  95. {
  96. std::shared_ptr<CComponentBox> comps;
  97. std::shared_ptr<CMultiLineLabel> text;
  98. public:
  99. struct Cache
  100. {
  101. std::vector<Component> compsToDisplay;
  102. std::string message;
  103. int textH;
  104. bool tiny;
  105. Cache(std::vector<Component> comps, std::string msg, int textH, bool tiny):
  106. compsToDisplay(std::move(comps)),
  107. message(std::move(msg)),
  108. textH(textH),
  109. tiny(tiny)
  110. {}
  111. };
  112. VisibleComponentInfo(const Cache & c): VisibleComponentInfo(c.compsToDisplay, c.message, c.textH, c.tiny) {}
  113. VisibleComponentInfo(const std::vector<Component> & compsToDisplay, std::string message, int textH, bool tiny);
  114. };
  115. enum EState
  116. {
  117. EMPTY, HERO, TOWN, DATE, GAME, AITURN, COMPONENT
  118. };
  119. std::shared_ptr<CVisibleInfo> visibleInfo;
  120. EState state;
  121. uint32_t timerCounter;
  122. bool shouldPopAll = false;
  123. std::queue<std::pair<VisibleComponentInfo::Cache, int>> componentsQueue;
  124. //private helper for showing components
  125. void showComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
  126. void pushComponents(const std::vector<Component> & comps, std::string message, int textH, bool tiny, int timer);
  127. void prepareComponents(const std::vector<Component> & comps, std::string message, int timer);
  128. void popComponents(bool remove = false);
  129. //removes all information about current state, deactivates timer (if any)
  130. void reset();
  131. void tick(uint32_t msPassed) override;
  132. void clickReleased(const Point & cursorPosition) override;
  133. void showPopupWindow(const Point & cursorPosition) override;
  134. void hover(bool on) override;
  135. void playNewDaySound();
  136. void setTimer(uint32_t msToTrigger);
  137. public:
  138. CInfoBar(const Rect & pos);
  139. CInfoBar(const Point & pos);
  140. /// show new day/week animation
  141. void showDate();
  142. /// show components for 3 seconds. Used to display picked up resources. Can display up to 8 components
  143. void pushComponents(const std::vector<Component> & comps, std::string message, int timer = 3000);
  144. /// Remove all queued components
  145. void popAll();
  146. /// Request infobar to pop all after next InfoWindow arrives.
  147. void requestPopAll();
  148. /// print enemy turn progress
  149. void startEnemyTurn(PlayerColor color);
  150. /// reset to default view - selected object
  151. void showSelection();
  152. /// show hero\town information
  153. void showHeroSelection(const CGHeroInstance * hero);
  154. void showTownSelection(const CGTownInstance * town);
  155. /// for 3 seconds shows amount of town halls and players status
  156. void showGameStatus();
  157. /// check if infobar is showed something about pickups
  158. bool showingComponents();
  159. };