InfoWindows.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * InfoWindows.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 "CWindowObject.h"
  12. #include "../gui/TextAlignment.h"
  13. #include "../../lib/FunctionList.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class CGTownInstance;
  17. class CGHeroInstance;
  18. class CGGarrison;
  19. class CGCreature;
  20. class CGTeleport;
  21. class CGKeys;
  22. class CGObelisk;
  23. VCMI_LIB_NAMESPACE_END
  24. class CComponent;
  25. class CComponentBox;
  26. class CSelectableComponent;
  27. class CTextBox;
  28. class CButton;
  29. class CFilledTexture;
  30. class FilledTexturePlayerColored;
  31. class TransparentFilledRectangle;
  32. class CMinimapInstance;
  33. class CLabel;
  34. class CSlider;
  35. /// text + comp. + ok button
  36. class CInfoWindow : public WindowBase
  37. {
  38. public:
  39. using TButtonsInfo = std::vector<std::pair<AnimationPath, CFunctionList<void()>>>;
  40. using TCompsInfo = std::vector<std::shared_ptr<CComponent>>;
  41. QueryID ID; //for identification
  42. std::shared_ptr<CFilledTexture> backgroundTexture;
  43. std::shared_ptr<CTextBox> text;
  44. std::shared_ptr<CComponentBox> components;
  45. std::vector<std::shared_ptr<CButton>> buttons;
  46. void close() override;
  47. void showAll(Canvas & to) override;
  48. void sliderMoved(int to);
  49. CInfoWindow(const std::string & Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());
  50. CInfoWindow();
  51. ~CInfoWindow();
  52. //use only before the game starts! (showYesNoDialog in GAME->interface() must be used then)
  53. static void showInfoDialog(const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
  54. static void showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  55. static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  56. /// create text from title and description: {title}\n\n description
  57. static std::string genText(const std::string & title, const std::string & description);
  58. };
  59. /// popup displayed on R-click
  60. class CRClickPopup : public WindowBase
  61. {
  62. public:
  63. bool isPopupWindow() const override;
  64. static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
  65. static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps = CInfoWindow::TCompsInfo());
  66. static void createAndPush(const std::string & txt, const std::shared_ptr<CComponent> & component);
  67. static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
  68. };
  69. /// popup displayed on R-click
  70. class CRClickPopupInt : public CRClickPopup
  71. {
  72. std::shared_ptr<CIntObject> inner;
  73. Point dragDistance;
  74. public:
  75. CRClickPopupInt(const std::shared_ptr<CIntObject> & our);
  76. ~CRClickPopupInt();
  77. void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  78. };
  79. /// adventure map popup
  80. class AdventureMapPopup : public CWindowObject
  81. {
  82. Point dragDistance;
  83. public:
  84. template<typename... Args>
  85. AdventureMapPopup(Args&&... args);
  86. void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  87. };
  88. /// popup on adventure map for town\hero and other objects with customized popup content
  89. class CInfoBoxPopup : public AdventureMapPopup
  90. {
  91. std::shared_ptr<CIntObject> tooltip;
  92. public:
  93. CInfoBoxPopup(Point position, const CGTownInstance * town);
  94. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  95. CInfoBoxPopup(Point position, const CGGarrison * garr);
  96. CInfoBoxPopup(Point position, const CGCreature * creature);
  97. };
  98. /// component selection window
  99. class CSelWindow : public CInfoWindow
  100. {
  101. public:
  102. void madeChoice(); //looks for selected component and calls callback
  103. void madeChoiceAndClose();
  104. CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath,CFunctionList<void()> > > &Buttons, QueryID askID);
  105. };
  106. class MinimapWithIcons : public CIntObject
  107. {
  108. std::shared_ptr<TransparentFilledRectangle> background1;
  109. std::shared_ptr<TransparentFilledRectangle> background2;
  110. std::shared_ptr<CMinimapInstance> map1;
  111. std::shared_ptr<CMinimapInstance> map2;
  112. std::vector<std::shared_ptr<CPicture>> iconsOverlay;
  113. std::shared_ptr<CSlider> slider;
  114. std::vector<std::pair<const int3, const ImagePath>> icons;
  115. public:
  116. MinimapWithIcons(const Point & position);
  117. void recreate();
  118. void addIcon(const int3 & coordinates, const ImagePath & image);
  119. };
  120. class TeleporterPopup : public AdventureMapPopup
  121. {
  122. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  123. std::shared_ptr<MinimapWithIcons> minimap;
  124. std::shared_ptr<CLabel> labelTitle;
  125. public:
  126. TeleporterPopup(const Point & position, const CGTeleport * teleporter);
  127. };
  128. class KeymasterPopup : public AdventureMapPopup
  129. {
  130. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  131. std::shared_ptr<MinimapWithIcons> minimap;
  132. std::shared_ptr<CLabel> labelTitle;
  133. std::shared_ptr<CLabel> labelDescription;
  134. public:
  135. KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard);
  136. };
  137. class ObeliskPopup : public AdventureMapPopup
  138. {
  139. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  140. std::shared_ptr<MinimapWithIcons> minimap;
  141. std::shared_ptr<CLabel> labelTitle;
  142. std::shared_ptr<CLabel> labelDescription;
  143. public:
  144. ObeliskPopup(const Point & position, const CGObelisk * obelisk);
  145. };
  146. class SearchPopup : public AdventureMapPopup
  147. {
  148. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  149. std::shared_ptr<MinimapWithIcons> minimap;
  150. std::shared_ptr<CLabel> labelTitle;
  151. public:
  152. SearchPopup(std::vector<const CGObjectInstance *> objs);
  153. };