InfoWindows.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 CGGarrison;
  16. class Rect;
  17. VCMI_LIB_NAMESPACE_END
  18. struct SDL_Surface;
  19. class CAnimImage;
  20. class CLabel;
  21. class CAnimation;
  22. class CComponent;
  23. class CSelectableComponent;
  24. class CTextBox;
  25. class CButton;
  26. class CSlider;
  27. class CArmyTooltip;
  28. // Window GUI class
  29. class CSimpleWindow : public WindowBase
  30. {
  31. public:
  32. SDL_Surface * bitmap; //background
  33. void show(Canvas & to) override;
  34. CSimpleWindow():bitmap(nullptr){};
  35. virtual ~CSimpleWindow();
  36. };
  37. /// text + comp. + ok button
  38. class CInfoWindow : public CSimpleWindow
  39. {
  40. public:
  41. using TButtonsInfo = std::vector<std::pair<std::string, CFunctionList<void()>>>;
  42. using TCompsInfo = std::vector<std::shared_ptr<CComponent>>;
  43. QueryID ID; //for identification
  44. std::shared_ptr<CTextBox> text;
  45. std::vector<std::shared_ptr<CButton>> buttons;
  46. TCompsInfo components;
  47. virtual void close();
  48. void show(Canvas & to) override;
  49. void showAll(Canvas & to) override;
  50. void sliderMoved(int to);
  51. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());
  52. CInfoWindow();
  53. ~CInfoWindow();
  54. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  55. static void showInfoDialog( const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
  56. static void showYesNoDialog( const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  57. static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  58. /// create text from title and description: {title}\n\n description
  59. static std::string genText(std::string title, std::string description);
  60. };
  61. /// popup displayed on R-click
  62. class CRClickPopup : public WindowBase
  63. {
  64. public:
  65. virtual void close();
  66. bool isPopupWindow() const override;
  67. static std::shared_ptr<WindowBase> createInfoWin(Point position, const CGObjectInstance * specific);
  68. static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  69. static void createAndPush(const std::string & txt, std::shared_ptr<CComponent> component);
  70. static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
  71. };
  72. /// popup displayed on R-click
  73. class CRClickPopupInt : public CRClickPopup
  74. {
  75. std::shared_ptr<CIntObject> inner;
  76. public:
  77. CRClickPopupInt(std::shared_ptr<CIntObject> our);
  78. virtual ~CRClickPopupInt();
  79. };
  80. class CInfoPopup : public CRClickPopup
  81. {
  82. public:
  83. bool free; //TODO: comment me
  84. SDL_Surface * bitmap; //popup background
  85. void close() override;
  86. void show(Canvas & to) override;
  87. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  88. CInfoPopup(SDL_Surface * Bitmap, const Point &p, ETextAlignment alignment, bool Free=false);
  89. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false);
  90. void init(int x, int y);
  91. ~CInfoPopup();
  92. };
  93. /// popup on adventure map for town\hero objects
  94. class CInfoBoxPopup : public CWindowObject
  95. {
  96. std::shared_ptr<CArmyTooltip> tooltip;
  97. Point toScreen(Point pos);
  98. public:
  99. CInfoBoxPopup(Point position, const CGTownInstance * town);
  100. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  101. CInfoBoxPopup(Point position, const CGGarrison * garr);
  102. };
  103. /// component selection window
  104. class CSelWindow : public CInfoWindow
  105. {
  106. public:
  107. void selectionChange(unsigned to);
  108. void madeChoice(); //looks for selected component and calls callback
  109. CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, QueryID askID);
  110. //notification - this class inherits important destructor from CInfoWindow
  111. };