InfoWindows.h 4.3 KB

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