MiscWidgets.h 7.4 KB

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