InfoWindows.h 5.5 KB

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