InfoWindows.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include "CWindowObject.h"
  3. //#include "../gui/SDL_Extensions.h"
  4. #include "../../lib/FunctionList.h"
  5. struct SDL_Surface;
  6. struct Rect;
  7. class CAnimImage;
  8. class CLabel;
  9. class CAnimation;
  10. class CDefHandler;
  11. class CComponent;
  12. class CSelectableComponent;
  13. class CGGarrison;
  14. class CTextBox;
  15. class CButton;
  16. class CSlider;
  17. /*
  18. * InfoWindows.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. // Window GUI class
  27. class CSimpleWindow : public CIntObject
  28. {
  29. public:
  30. SDL_Surface * bitmap; //background
  31. virtual void show(SDL_Surface * to) override;
  32. CSimpleWindow():bitmap(nullptr){}; //c-tor
  33. virtual ~CSimpleWindow(); //d-tor
  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. CSlider *slider;
  47. void setDelComps(bool DelComps);
  48. virtual void close();
  49. void show(SDL_Surface * to) override;
  50. void showAll(SDL_Surface * to) override;
  51. void sliderMoved(int to);
  52. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo &comps = TCompsInfo(), const TButtonsInfo &Buttons = TButtonsInfo(), bool delComps = true); //c-tor
  53. CInfoWindow(); //c-tor
  54. ~CInfoWindow(); //d-tor
  55. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  56. static void showInfoDialog( const std::string & text, const std::vector<CComponent*> *components, bool DelComps = true, PlayerColor player = PlayerColor(1));
  57. static void showOkDialog(const std::string & text, const std::vector<CComponent*> *components, const std::function<void()> & onOk, bool delComps = true, PlayerColor player = PlayerColor(1));
  58. 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));
  59. static CInfoWindow *create(const std::string &text, PlayerColor playerID = PlayerColor(1), const std::vector<CComponent*> *components = nullptr, bool DelComps = false);
  60. /// create text from title and description: {title}\n\n description
  61. static std::string genText(std::string title, std::string description);
  62. };
  63. /// popup displayed on R-click
  64. class CRClickPopup : public CIntObject
  65. {
  66. public:
  67. virtual void close();
  68. void clickRight(tribool down, bool previousState) override;
  69. CRClickPopup();
  70. virtual ~CRClickPopup(); //d-tor
  71. static CIntObject* createInfoWin(Point position, const CGObjectInstance * specific);
  72. static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  73. static void createAndPush(const std::string &txt, CComponent * component);
  74. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  75. };
  76. /// popup displayed on R-click
  77. class CRClickPopupInt : public CRClickPopup
  78. {
  79. public:
  80. IShowActivatable *inner;
  81. bool delInner;
  82. void show(SDL_Surface * to) override;
  83. void showAll(SDL_Surface * to) override;
  84. CRClickPopupInt(IShowActivatable *our, bool deleteInt); //c-tor
  85. virtual ~CRClickPopupInt(); //d-tor
  86. };
  87. class CInfoPopup : public CRClickPopup
  88. {
  89. public:
  90. bool free; //TODO: comment me
  91. SDL_Surface * bitmap; //popup background
  92. void close() override;
  93. void show(SDL_Surface * to) override;
  94. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  95. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  96. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false); //default c-tor
  97. void init(int x, int y);
  98. ~CInfoPopup(); //d-tor
  99. };
  100. /// popup on adventure map for town\hero objects
  101. class CInfoBoxPopup : public CWindowObject
  102. {
  103. Point toScreen(Point pos);
  104. public:
  105. CInfoBoxPopup(Point position, const CGTownInstance * town);
  106. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  107. CInfoBoxPopup(Point position, const CGGarrison * garr);
  108. };
  109. /// component selection window
  110. class CSelWindow : public CInfoWindow
  111. { //warning - this window deletes its components by closing!
  112. public:
  113. void selectionChange(unsigned to);
  114. void madeChoice(); //looks for selected component and calls callback
  115. 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); //c-tor
  116. CSelWindow(){}; //c-tor
  117. //notification - this class inherits important destructor from CInfoWindow
  118. };