MiscWidgets.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * MiscWidgets.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. class CLabel;
  13. class CCreatureAnim;
  14. class CComponent;
  15. class CGGarrison;
  16. struct InfoAboutArmy;
  17. class CArmedInstance;
  18. class IBonusBearer;
  19. class CAnimImage;
  20. /// Shows a text by moving the mouse cursor over the object
  21. class CHoverableArea: public virtual CIntObject
  22. {
  23. public:
  24. std::string hoverText;
  25. virtual void hover (bool on) override;
  26. CHoverableArea();
  27. virtual ~CHoverableArea();
  28. };
  29. /// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it
  30. class LRClickableAreaWText: public CHoverableArea
  31. {
  32. public:
  33. std::string text;
  34. LRClickableAreaWText();
  35. LRClickableAreaWText(const Rect & Pos, const std::string & HoverText = "", const std::string & ClickText = "");
  36. virtual ~LRClickableAreaWText();
  37. void init();
  38. virtual void clickLeft(tribool down, bool previousState) override;
  39. virtual void clickRight(tribool down, bool previousState) override;
  40. };
  41. /// base class for hero/town/garrison tooltips
  42. class CArmyTooltip : public CIntObject
  43. {
  44. std::shared_ptr<CLabel> title;
  45. std::vector<std::shared_ptr<CAnimImage>> icons;
  46. std::vector<std::shared_ptr<CLabel>> subtitles;
  47. void init(const InfoAboutArmy & army);
  48. public:
  49. CArmyTooltip(Point pos, const InfoAboutArmy & army);
  50. CArmyTooltip(Point pos, const CArmedInstance * army);
  51. };
  52. /// Class for hero tooltip. Does not have any background!
  53. /// background for infoBox: ADSTATHR
  54. /// background for tooltip: HEROQVBK
  55. class CHeroTooltip : public CArmyTooltip
  56. {
  57. std::shared_ptr<CAnimImage> portrait;
  58. std::vector<std::shared_ptr<CLabel>> labels;
  59. std::shared_ptr<CAnimImage> morale;
  60. std::shared_ptr<CAnimImage> luck;
  61. void init(const InfoAboutHero & hero);
  62. public:
  63. CHeroTooltip(Point pos, const InfoAboutHero & hero);
  64. CHeroTooltip(Point pos, const CGHeroInstance * hero);
  65. };
  66. /// Class for town tooltip. Does not have any background!
  67. /// background for infoBox: ADSTATCS
  68. /// background for tooltip: TOWNQVBK
  69. class CTownTooltip : public CArmyTooltip
  70. {
  71. std::shared_ptr<CAnimImage> fort;
  72. std::shared_ptr<CAnimImage> hall;
  73. std::shared_ptr<CAnimImage> build;
  74. std::shared_ptr<CLabel> income;
  75. std::shared_ptr<CPicture> garrisonedHero;
  76. std::shared_ptr<CAnimImage> res1;
  77. std::shared_ptr<CAnimImage> res2;
  78. void init(const InfoAboutTown & town);
  79. public:
  80. CTownTooltip(Point pos, const InfoAboutTown & town);
  81. CTownTooltip(Point pos, const CGTownInstance * town);
  82. };
  83. /// draws picture with creature on background, use Animated=true to get animation
  84. class CCreaturePic : public CIntObject
  85. {
  86. private:
  87. std::shared_ptr<CPicture> bg;
  88. std::shared_ptr<CCreatureAnim> anim; //displayed animation
  89. std::shared_ptr<CLabel> amount;
  90. void show(SDL_Surface * to) override;
  91. public:
  92. CCreaturePic(int x, int y, const CCreature * cre, bool Big=true, bool Animated=true);
  93. void setAmount(int newAmount);
  94. };
  95. /// Resource bar like that at the bottom of the adventure map screen
  96. class CMinorResDataBar : public CIntObject
  97. {
  98. std::shared_ptr<CPicture> background;
  99. public:
  100. void show(SDL_Surface * to) override;
  101. void showAll(SDL_Surface * to) override;
  102. CMinorResDataBar();
  103. ~CMinorResDataBar();
  104. };
  105. /// Opens hero window by left-clicking on it
  106. class CHeroArea: public CIntObject
  107. {
  108. const CGHeroInstance * hero;
  109. std::shared_ptr<CAnimImage> portrait;
  110. public:
  111. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  112. void clickLeft(tribool down, bool previousState) override;
  113. void clickRight(tribool down, bool previousState) override;
  114. void hover(bool on) override;
  115. };
  116. /// Can interact on left and right mouse clicks
  117. class LRClickableAreaWTextComp: public LRClickableAreaWText
  118. {
  119. public:
  120. int baseType;
  121. int bonusValue;
  122. virtual void clickLeft(tribool down, bool previousState) override;
  123. virtual void clickRight(tribool down, bool previousState) override;
  124. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  125. std::shared_ptr<CComponent> createComponent() const;
  126. };
  127. /// Opens town screen by left-clicking on it
  128. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  129. {
  130. public:
  131. const CGTownInstance * town;
  132. void clickLeft(tribool down, bool previousState) override;
  133. void clickRight(tribool down, bool previousState) override;
  134. LRClickableAreaOpenTown(const Rect & Pos, const CGTownInstance * Town);
  135. };
  136. class MoraleLuckBox : public LRClickableAreaWTextComp
  137. {
  138. std::shared_ptr<CAnimImage> image;
  139. public:
  140. bool morale; //true if morale, false if luck
  141. bool small;
  142. void set(const IBonusBearer *node);
  143. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  144. };