InfoWindows.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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():bitmap(nullptr){};
  32. virtual ~CSimpleWindow();
  33. };
  34. /// text + comp. + ok button
  35. class CInfoWindow : public CSimpleWindow
  36. { //window able to delete its components when closed
  37. bool delComps; //whether comps will be deleted
  38. public:
  39. typedef std::vector<std::pair<std::string,CFunctionList<void()> > > TButtonsInfo;
  40. typedef std::vector<CComponent*> TCompsInfo;
  41. QueryID ID; //for identification
  42. CTextBox *text;
  43. std::vector<CButton *> buttons;
  44. std::vector<CComponent*> components;
  45. void setDelComps(bool DelComps);
  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(), bool delComps = true);
  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 std::vector<CComponent*> *components, bool DelComps = true, PlayerColor player = PlayerColor(1));
  55. static void showOkDialog(const std::string & text, const std::vector<CComponent*> *components, const std::function<void()> & onOk, bool delComps = true, PlayerColor player = PlayerColor(1));
  56. 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));
  57. static CInfoWindow *create(const std::string &text, PlayerColor playerID = PlayerColor(1), const std::vector<CComponent*> *components = nullptr, bool DelComps = false);
  58. /// create text from title and description: {title}\n\n description
  59. static std::string genText(std::string title, std::string description);
  60. };
  61. /// popup displayed on R-click
  62. class CRClickPopup : public CIntObject
  63. {
  64. public:
  65. virtual void close();
  66. void clickRight(tribool down, bool previousState) override;
  67. CRClickPopup();
  68. virtual ~CRClickPopup();
  69. static CIntObject* createInfoWin(Point position, const CGObjectInstance * specific);
  70. static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  71. static void createAndPush(const std::string &txt, CComponent * component);
  72. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  73. };
  74. /// popup displayed on R-click
  75. class CRClickPopupInt : public CRClickPopup
  76. {
  77. public:
  78. IShowActivatable *inner;
  79. bool delInner;
  80. void show(SDL_Surface * to) override;
  81. void showAll(SDL_Surface * to) override;
  82. CRClickPopupInt(IShowActivatable *our, bool deleteInt);
  83. virtual ~CRClickPopupInt();
  84. };
  85. class CInfoPopup : public CRClickPopup
  86. {
  87. public:
  88. bool free; //TODO: comment me
  89. SDL_Surface * bitmap; //popup background
  90. void close() override;
  91. void show(SDL_Surface * to) override;
  92. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  93. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false);
  94. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false);
  95. void init(int x, int y);
  96. ~CInfoPopup();
  97. };
  98. /// popup on adventure map for town\hero objects
  99. class CInfoBoxPopup : public CWindowObject
  100. {
  101. Point toScreen(Point pos);
  102. public:
  103. CInfoBoxPopup(Point position, const CGTownInstance * town);
  104. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  105. CInfoBoxPopup(Point position, const CGGarrison * garr);
  106. };
  107. /// component selection window
  108. class CSelWindow : public CInfoWindow
  109. { //warning - this window deletes its components by closing!
  110. public:
  111. void selectionChange(unsigned to);
  112. void madeChoice(); //looks for selected component and calls callback
  113. 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);
  114. CSelWindow(){};
  115. //notification - this class inherits important destructor from CInfoWindow
  116. };