InfoWindows.h 4.2 KB

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