MiscWidgets.h 7.7 KB

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