CInfoBar.h 5.5 KB

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