MiscWidgets.h 7.2 KB

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