InfoWindows.h 4.2 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 "../../lib/FunctionList.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGGarrison;
  15. VCMI_LIB_NAMESPACE_END
  16. struct SDL_Surface;
  17. struct Rect;
  18. class CAnimImage;
  19. class CLabel;
  20. class CAnimation;
  21. class CComponent;
  22. class CSelectableComponent;
  23. class CTextBox;
  24. class CButton;
  25. class CSlider;
  26. class CArmyTooltip;
  27. // Window GUI class
  28. class CSimpleWindow : public WindowBase
  29. {
  30. public:
  31. SDL_Surface * bitmap; //background
  32. void show(SDL_Surface * to) override;
  33. CSimpleWindow():bitmap(nullptr){};
  34. virtual ~CSimpleWindow();
  35. };
  36. /// text + comp. + ok button
  37. class CInfoWindow : public CSimpleWindow
  38. {
  39. public:
  40. typedef std::vector<std::pair<std::string, CFunctionList<void()> > > TButtonsInfo;
  41. typedef std::vector<std::shared_ptr<CComponent>> TCompsInfo;
  42. QueryID ID; //for identification
  43. std::shared_ptr<CTextBox> text;
  44. std::vector<std::shared_ptr<CButton>> buttons;
  45. TCompsInfo components;
  46. virtual void close();
  47. void show(SDL_Surface * to) override;
  48. void showAll(SDL_Surface * to) override;
  49. void sliderMoved(int to);
  50. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());
  51. CInfoWindow();
  52. ~CInfoWindow();
  53. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  54. static void showInfoDialog( const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
  55. static void showYesNoDialog( const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  56. static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  57. /// create text from title and description: {title}\n\n description
  58. static std::string genText(std::string title, std::string description);
  59. };
  60. /// popup displayed on R-click
  61. class CRClickPopup : public WindowBase
  62. {
  63. public:
  64. virtual void close();
  65. void clickRight(tribool down, bool previousState) override;
  66. CRClickPopup();
  67. virtual ~CRClickPopup();
  68. static std::shared_ptr<WindowBase> createInfoWin(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, EAlignment alignment = 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(SDL_Surface * to) override;
  88. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  89. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment 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 objects
  95. class CInfoBoxPopup : public CWindowObject
  96. {
  97. std::shared_ptr<CArmyTooltip> 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. };
  104. /// component selection window
  105. class CSelWindow : public CInfoWindow
  106. {
  107. public:
  108. void selectionChange(unsigned to);
  109. void madeChoice(); //looks for selected component and calls callback
  110. 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);
  111. //notification - this class inherits important destructor from CInfoWindow
  112. };