MiscWidgets.h 5.9 KB

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