CInfoBar.h 5.4 KB

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