MiscWidgets.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGGarrison;
  14. class CGCreature;
  15. struct InfoAboutArmy;
  16. struct InfoAboutHero;
  17. struct InfoAboutTown;
  18. class CArmedInstance;
  19. class CGTownInstance;
  20. class CGHeroInstance;
  21. class AFactionMember;
  22. VCMI_LIB_NAMESPACE_END
  23. class CLabel;
  24. class CTextBox;
  25. class CGarrisonInt;
  26. class CCreatureAnim;
  27. class CComponent;
  28. class CAnimImage;
  29. /// Shows a text by moving the mouse cursor over the object
  30. class CHoverableArea: public virtual CIntObject
  31. {
  32. public:
  33. std::string hoverText;
  34. virtual void hover (bool on) override;
  35. CHoverableArea();
  36. virtual ~CHoverableArea();
  37. };
  38. /// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it
  39. class LRClickableAreaWText: public CHoverableArea
  40. {
  41. public:
  42. std::string text;
  43. LRClickableAreaWText();
  44. LRClickableAreaWText(const Rect & Pos, const std::string & HoverText = "", const std::string & ClickText = "");
  45. virtual ~LRClickableAreaWText();
  46. void init();
  47. void clickPressed(const Point & cursorPosition) override;
  48. void showPopupWindow(const Point & cursorPosition) override;
  49. };
  50. /// base class for hero/town/garrison tooltips
  51. class CArmyTooltip : public CIntObject
  52. {
  53. std::shared_ptr<CLabel> title;
  54. std::vector<std::shared_ptr<CAnimImage>> icons;
  55. std::vector<std::shared_ptr<CLabel>> subtitles;
  56. void init(const InfoAboutArmy & army);
  57. public:
  58. CArmyTooltip(Point pos, const InfoAboutArmy & army);
  59. CArmyTooltip(Point pos, const CArmedInstance * army);
  60. };
  61. /// Class for hero tooltip. Does not have any background!
  62. /// background for infoBox: ADSTATHR
  63. /// background for tooltip: HEROQVBK
  64. class CHeroTooltip : public CArmyTooltip
  65. {
  66. std::shared_ptr<CAnimImage> portrait;
  67. std::vector<std::shared_ptr<CLabel>> labels;
  68. std::shared_ptr<CAnimImage> morale;
  69. std::shared_ptr<CAnimImage> luck;
  70. void init(const InfoAboutHero & hero);
  71. public:
  72. CHeroTooltip(Point pos, const InfoAboutHero & hero);
  73. CHeroTooltip(Point pos, const CGHeroInstance * hero);
  74. };
  75. /// Class for HD mod-like interactable infobox tooltip. Does not have any background!
  76. class CInteractableHeroTooltip : public CIntObject
  77. {
  78. std::shared_ptr<CLabel> title;
  79. std::shared_ptr<CAnimImage> portrait;
  80. std::vector<std::shared_ptr<CLabel>> labels;
  81. std::shared_ptr<CAnimImage> morale;
  82. std::shared_ptr<CAnimImage> luck;
  83. std::shared_ptr<CGarrisonInt> garrison;
  84. void init(const InfoAboutHero & hero);
  85. public:
  86. CInteractableHeroTooltip(Point pos, const CGHeroInstance * hero);
  87. };
  88. /// Class for town tooltip. Does not have any background!
  89. /// background for infoBox: ADSTATCS
  90. /// background for tooltip: TOWNQVBK
  91. class CTownTooltip : public CArmyTooltip
  92. {
  93. std::shared_ptr<CAnimImage> fort;
  94. std::shared_ptr<CAnimImage> hall;
  95. std::shared_ptr<CAnimImage> build;
  96. std::shared_ptr<CLabel> income;
  97. std::shared_ptr<CPicture> garrisonedHero;
  98. std::shared_ptr<CAnimImage> res1;
  99. std::shared_ptr<CAnimImage> res2;
  100. void init(const InfoAboutTown & town);
  101. public:
  102. CTownTooltip(Point pos, const InfoAboutTown & town);
  103. CTownTooltip(Point pos, const CGTownInstance * town);
  104. };
  105. /// Class for HD mod-like interactable infobox tooltip. Does not have any background!
  106. class CInteractableTownTooltip : public CIntObject
  107. {
  108. std::shared_ptr<CLabel> title;
  109. std::shared_ptr<CAnimImage> fort;
  110. std::shared_ptr<CAnimImage> hall;
  111. std::shared_ptr<CAnimImage> build;
  112. std::shared_ptr<CLabel> income;
  113. std::shared_ptr<CPicture> garrisonedHero;
  114. std::shared_ptr<CAnimImage> res1;
  115. std::shared_ptr<CAnimImage> res2;
  116. std::shared_ptr<CGarrisonInt> garrison;
  117. void init(const InfoAboutTown & town);
  118. public:
  119. CInteractableTownTooltip(Point pos, const CGTownInstance * town);
  120. };
  121. /// draws picture with creature on background, use Animated=true to get animation
  122. class CCreaturePic : public CIntObject
  123. {
  124. private:
  125. std::shared_ptr<CPicture> bg;
  126. std::shared_ptr<CCreatureAnim> anim; //displayed animation
  127. std::shared_ptr<CLabel> amount;
  128. void show(Canvas & to) override;
  129. public:
  130. CCreaturePic(int x, int y, const CCreature * cre, bool Big=true, bool Animated=true);
  131. void setAmount(int newAmount);
  132. };
  133. class CreatureTooltip : public CIntObject
  134. {
  135. std::shared_ptr<CAnimImage> creatureImage;
  136. std::shared_ptr<CTextBox> tooltipTextbox;
  137. public:
  138. CreatureTooltip(Point pos, const CGCreature * creature);
  139. };
  140. /// Resource bar like that at the bottom of the adventure map screen
  141. class CMinorResDataBar : public CIntObject
  142. {
  143. std::shared_ptr<CPicture> background;
  144. std::string buildDateString();
  145. public:
  146. void show(Canvas & to) override;
  147. void showAll(Canvas & to) override;
  148. CMinorResDataBar();
  149. ~CMinorResDataBar();
  150. };
  151. /// Performs an action by left-clicking on it. Opens hero window by default
  152. class CHeroArea: public CIntObject
  153. {
  154. public:
  155. using ClickFunctor = std::function<void()>;
  156. CHeroArea(int x, int y, const CGHeroInstance * hero);
  157. void addClickCallback(ClickFunctor callback);
  158. void clickPressed(const Point & cursorPosition) override;
  159. void hover(bool on) override;
  160. private:
  161. const CGHeroInstance * hero;
  162. std::shared_ptr<CAnimImage> portrait;
  163. ClickFunctor clickFunctor;
  164. ClickFunctor showPopupHandler;
  165. };
  166. /// Can interact on left and right mouse clicks
  167. class LRClickableAreaWTextComp: public LRClickableAreaWText
  168. {
  169. public:
  170. int type;
  171. int baseType;
  172. int bonusValue;
  173. void clickPressed(const Point & cursorPosition) override;
  174. void showPopupWindow(const Point & cursorPosition) override;
  175. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  176. std::shared_ptr<CComponent> createComponent() const;
  177. };
  178. /// Opens town screen by left-clicking on it
  179. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  180. {
  181. public:
  182. const CGTownInstance * town;
  183. void clickPressed(const Point & cursorPosition) override;
  184. LRClickableAreaOpenTown(const Rect & Pos, const CGTownInstance * Town);
  185. };
  186. class MoraleLuckBox : public LRClickableAreaWTextComp
  187. {
  188. std::shared_ptr<CAnimImage> image;
  189. public:
  190. bool morale; //true if morale, false if luck
  191. bool small;
  192. void set(const AFactionMember *node);
  193. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  194. };