InfoWindows.h 3.6 KB

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