2
0

CInfoBar.h 5.4 KB

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