MiscWidgets.h 7.4 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. #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. void show(Canvas & to) override;
  145. public:
  146. CreatureTooltip(Point pos, const CGCreature * creature);
  147. };
  148. /// Resource bar like that at the bottom of the adventure map screen
  149. class CMinorResDataBar : public CIntObject
  150. {
  151. std::shared_ptr<CPicture> background;
  152. std::string buildDateString();
  153. public:
  154. void show(Canvas & to) override;
  155. void showAll(Canvas & to) override;
  156. CMinorResDataBar();
  157. ~CMinorResDataBar();
  158. };
  159. /// Performs an action by left-clicking on it. Opens hero window by default
  160. class CHeroArea: public CIntObject
  161. {
  162. public:
  163. using ClickFunctor = std::function<void()>;
  164. CHeroArea(int x, int y, const CGHeroInstance * hero);
  165. void addClickCallback(ClickFunctor callback);
  166. void addRClickCallback(ClickFunctor callback);
  167. void clickPressed(const Point & cursorPosition) override;
  168. void showPopupWindow(const Point & cursorPosition) override;
  169. void hover(bool on) override;
  170. private:
  171. const CGHeroInstance * hero;
  172. std::shared_ptr<CAnimImage> portrait;
  173. ClickFunctor clickFunctor;
  174. ClickFunctor clickRFunctor;
  175. ClickFunctor showPopupHandler;
  176. };
  177. /// Can interact on left and right mouse clicks
  178. class LRClickableAreaWTextComp: public LRClickableAreaWText
  179. {
  180. public:
  181. Component component;
  182. void clickPressed(const Point & cursorPosition) override;
  183. void showPopupWindow(const Point & cursorPosition) override;
  184. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), ComponentType baseType = ComponentType::NONE);
  185. std::shared_ptr<CComponent> createComponent() const;
  186. };
  187. /// Opens town screen by left-clicking on it
  188. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  189. {
  190. public:
  191. const CGTownInstance * town;
  192. void clickPressed(const Point & cursorPosition) override;
  193. LRClickableAreaOpenTown(const Rect & Pos, const CGTownInstance * Town);
  194. };
  195. /// Can do action on click
  196. class LRClickableArea: public CIntObject
  197. {
  198. std::function<void()> onClick;
  199. std::function<void()> onPopup;
  200. public:
  201. void clickPressed(const Point & cursorPosition) override;
  202. void showPopupWindow(const Point & cursorPosition) override;
  203. LRClickableArea(const Rect & Pos, std::function<void()> onClick = nullptr, std::function<void()> onPopup = nullptr);
  204. };
  205. class MoraleLuckBox : public LRClickableAreaWTextComp
  206. {
  207. std::shared_ptr<CAnimImage> image;
  208. std::shared_ptr<CLabel> label;
  209. public:
  210. bool morale; //true if morale, false if luck
  211. bool small;
  212. void set(const AFactionMember *node);
  213. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  214. };
  215. class SelectableSlot : public LRClickableAreaWTextComp
  216. {
  217. std::shared_ptr<TransparentFilledRectangle> selection;
  218. bool selected;
  219. public:
  220. SelectableSlot(Rect area, Point oversize, const int width);
  221. SelectableSlot(Rect area, Point oversize);
  222. SelectableSlot(Rect area, const int width = 1);
  223. void selectSlot(bool on);
  224. bool isSelected() const;
  225. void setSelectionWidth(int width);
  226. void moveSelectionForeground();
  227. };