InfoWindows.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/SDL_Extensions.h"
  13. #include "../../lib/FunctionList.h"
  14. struct SDL_Surface;
  15. struct Rect;
  16. class CAnimImage;
  17. class CLabel;
  18. class CAnimation;
  19. class CComponent;
  20. class CSelectableComponent;
  21. class CGGarrison;
  22. class CTextBox;
  23. class CButton;
  24. class CSlider;
  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()
  32. : bitmap(nullptr){};
  33. virtual ~CSimpleWindow();
  34. };
  35. /// text + comp. + ok button
  36. class CInfoWindow : public CSimpleWindow
  37. { //window able to delete its components when closed
  38. bool delComps; //whether comps will be deleted
  39. public:
  40. typedef std::vector<std::pair<std::string, CFunctionList<void ()>>> TButtonsInfo;
  41. typedef std::vector<CComponent *> TCompsInfo;
  42. QueryID ID; //for identification
  43. CTextBox * text;
  44. std::vector<CButton *> buttons;
  45. std::vector<CComponent *> components;
  46. void setDelComps(bool DelComps);
  47. virtual void close();
  48. void show(SDL_Surface * to) override;
  49. void showAll(SDL_Surface * to) override;
  50. void sliderMoved(int to);
  51. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo(), bool delComps = true);
  52. CInfoWindow();
  53. ~CInfoWindow();
  54. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  55. static void showInfoDialog(const std::string & text, const std::vector<CComponent *> * components, bool DelComps = true, PlayerColor player = PlayerColor(1));
  56. static void showOkDialog(const std::string & text, const std::vector<CComponent *> * components, const std::function<void()> & onOk, bool delComps = true, PlayerColor player = PlayerColor(1));
  57. static void showYesNoDialog(const std::string & text, const std::vector<CComponent *> * components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, bool DelComps = true, PlayerColor player = PlayerColor(1));
  58. static CInfoWindow * create(const std::string & text, PlayerColor playerID = PlayerColor(1), const std::vector<CComponent *> * components = nullptr, bool DelComps = false);
  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 CIntObject
  64. {
  65. public:
  66. virtual void close();
  67. void clickRight(tribool down, bool previousState) override;
  68. CRClickPopup();
  69. virtual ~CRClickPopup();
  70. static CIntObject * 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, CComponent * component);
  73. static void createAndPush(const CGObjectInstance * obj, const Point & p, EAlignment alignment = BOTTOMRIGHT);
  74. };
  75. /// popup displayed on R-click
  76. class CRClickPopupInt : public CRClickPopup
  77. {
  78. public:
  79. IShowActivatable * inner;
  80. bool delInner;
  81. void show(SDL_Surface * to) override;
  82. void showAll(SDL_Surface * to) override;
  83. CRClickPopupInt(IShowActivatable * our, bool deleteInt);
  84. virtual ~CRClickPopupInt();
  85. };
  86. class CInfoPopup : public CRClickPopup
  87. {
  88. public:
  89. bool free; //TODO: comment me
  90. SDL_Surface * bitmap; //popup background
  91. void close() override;
  92. void show(SDL_Surface * to) override;
  93. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free = false);
  94. CInfoPopup(SDL_Surface * Bitmap, const Point & p, EAlignment alignment, bool Free = false);
  95. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false);
  96. void init(int x, int y);
  97. ~CInfoPopup();
  98. };
  99. /// popup on adventure map for town\hero objects
  100. class CInfoBoxPopup : public CWindowObject
  101. {
  102. Point toScreen(Point pos);
  103. public:
  104. CInfoBoxPopup(Point position, const CGTownInstance * town);
  105. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  106. CInfoBoxPopup(Point position, const CGGarrison * garr);
  107. };
  108. /// component selection window
  109. class CSelWindow : public CInfoWindow
  110. { //warning - this window deletes its components by closing!
  111. public:
  112. void selectionChange(unsigned to);
  113. void madeChoice(); //looks for selected component and calls callback
  114. CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<CSelectableComponent *> & comps, const std::vector<std::pair<std::string, CFunctionList<void()>>> & Buttons, QueryID askID);
  115. CSelWindow(){};
  116. //notification - this class inherits important destructor from CInfoWindow
  117. };