MiscWidgets.h 7.3 KB

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