InfoWindows.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 CComponent;
  11. class CSelectableComponent;
  12. class CGGarrison;
  13. class CTextBox;
  14. class CButton;
  15. class CSlider;
  16. /*
  17. * InfoWindows.h, part of VCMI engine
  18. *
  19. * Authors: listed in file AUTHORS in main folder
  20. *
  21. * License: GNU General Public License v2.0 or later
  22. * Full text of license available in license.txt file, in main folder
  23. *
  24. */
  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){}; //c-tor
  32. virtual ~CSimpleWindow(); //d-tor
  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. CSlider *slider;
  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); //c-tor
  52. CInfoWindow(); //c-tor
  53. ~CInfoWindow(); //d-tor
  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(); //d-tor
  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); //c-tor
  84. virtual ~CRClickPopupInt(); //d-tor
  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); //c-tor
  94. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  95. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false); //default c-tor
  96. void init(int x, int y);
  97. ~CInfoPopup(); //d-tor
  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); //c-tor
  115. CSelWindow(){}; //c-tor
  116. //notification - this class inherits important destructor from CInfoWindow
  117. };