InfoWindows.h 4.2 KB

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