InfoWindows.h 4.5 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. 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 CIntObject
  27. {
  28. public:
  29. SDL_Surface * bitmap; //background
  30. virtual 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 showOkDialog(const std::string & text, const TCompsInfo & components, const std::function<void()> & onOk, PlayerColor player = PlayerColor(1));
  54. static void showYesNoDialog( const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  55. static CInfoWindow * create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  56. /// create text from title and description: {title}\n\n description
  57. static std::string genText(std::string title, std::string description);
  58. };
  59. /// popup displayed on R-click
  60. class CRClickPopup : public CIntObject
  61. {
  62. public:
  63. virtual void close();
  64. void clickRight(tribool down, bool previousState) override;
  65. CRClickPopup();
  66. virtual ~CRClickPopup();
  67. static CIntObject* 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, EAlignment alignment = BOTTOMRIGHT);
  71. };
  72. /// popup displayed on R-click
  73. class CRClickPopupInt : public CRClickPopup
  74. {
  75. public:
  76. IShowActivatable *inner;
  77. bool delInner;
  78. void show(SDL_Surface * to) override;
  79. void showAll(SDL_Surface * to) override;
  80. CRClickPopupInt(IShowActivatable *our, bool deleteInt);
  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(SDL_Surface * to) override;
  90. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  91. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment 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. { //warning - this window deletes its components by closing!
  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. CSelWindow(){};
  114. //notification - this class inherits important destructor from CInfoWindow
  115. };