InfoWindows.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. VCMI_LIB_NAMESPACE_END
  22. class CComponent;
  23. class CComponentBox;
  24. class CSelectableComponent;
  25. class CTextBox;
  26. class CButton;
  27. class CFilledTexture;
  28. class FilledTexturePlayerColored;
  29. class TransparentFilledRectangle;
  30. class CMinimapInstance;
  31. class CLabel;
  32. /// text + comp. + ok button
  33. class CInfoWindow : public WindowBase
  34. {
  35. public:
  36. using TButtonsInfo = std::vector<std::pair<AnimationPath, CFunctionList<void()>>>;
  37. using TCompsInfo = std::vector<std::shared_ptr<CComponent>>;
  38. QueryID ID; //for identification
  39. std::shared_ptr<CFilledTexture> backgroundTexture;
  40. std::shared_ptr<CTextBox> text;
  41. std::shared_ptr<CComponentBox> components;
  42. std::vector<std::shared_ptr<CButton>> buttons;
  43. void close() override;
  44. void showAll(Canvas & to) override;
  45. void sliderMoved(int to);
  46. CInfoWindow(const std::string & Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());
  47. CInfoWindow();
  48. ~CInfoWindow();
  49. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  50. static void showInfoDialog(const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
  51. static void showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  52. static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  53. /// create text from title and description: {title}\n\n description
  54. static std::string genText(const std::string & title, const std::string & description);
  55. };
  56. /// popup displayed on R-click
  57. class CRClickPopup : public WindowBase
  58. {
  59. public:
  60. bool isPopupWindow() const override;
  61. static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
  62. static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps = CInfoWindow::TCompsInfo());
  63. static void createAndPush(const std::string & txt, const std::shared_ptr<CComponent> & component);
  64. static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
  65. };
  66. /// popup displayed on R-click
  67. class CRClickPopupInt : public CRClickPopup
  68. {
  69. std::shared_ptr<CIntObject> inner;
  70. Point dragDistance;
  71. public:
  72. CRClickPopupInt(const std::shared_ptr<CIntObject> & our);
  73. ~CRClickPopupInt();
  74. void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  75. };
  76. /// popup on adventure map for town\hero and other objects with customized popup content
  77. class CInfoBoxPopup : public CWindowObject
  78. {
  79. std::shared_ptr<CIntObject> tooltip;
  80. Point dragDistance;
  81. public:
  82. CInfoBoxPopup(Point position, const CGTownInstance * town);
  83. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  84. CInfoBoxPopup(Point position, const CGGarrison * garr);
  85. CInfoBoxPopup(Point position, const CGCreature * creature);
  86. void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  87. };
  88. /// component selection window
  89. class CSelWindow : public CInfoWindow
  90. {
  91. public:
  92. void madeChoice(); //looks for selected component and calls callback
  93. void madeChoiceAndClose();
  94. 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);
  95. };
  96. class TeleporterPopup : public CWindowObject
  97. {
  98. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  99. std::shared_ptr<TransparentFilledRectangle> backgroundSurface;
  100. std::shared_ptr<TransparentFilledRectangle> backgroundUnderground;
  101. std::shared_ptr<CMinimapInstance> surface;
  102. std::shared_ptr<CMinimapInstance> undergroud;
  103. std::shared_ptr<CLabel> labelTitle;
  104. std::vector<std::shared_ptr<CPicture>> iconsOverlay;
  105. public:
  106. TeleporterPopup(const Point & position, const CGTeleport * teleporter);
  107. };