InfoWindows.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/TextAlignment.h"
  13. #include "../../lib/FunctionList.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class CGTownInstance;
  17. class CGHeroInstance;
  18. class CGGarrison;
  19. class CGCreature;
  20. class Rect;
  21. VCMI_LIB_NAMESPACE_END
  22. struct SDL_Surface;
  23. class CAnimImage;
  24. class CLabel;
  25. class CAnimation;
  26. class CComponent;
  27. class CSelectableComponent;
  28. class CTextBox;
  29. class CButton;
  30. class CSlider;
  31. class CArmyTooltip;
  32. // Window GUI class
  33. class CSimpleWindow : public WindowBase
  34. {
  35. public:
  36. SDL_Surface * bitmap; //background
  37. void show(Canvas & to) override;
  38. CSimpleWindow():bitmap(nullptr){};
  39. virtual ~CSimpleWindow();
  40. };
  41. /// text + comp. + ok button
  42. class CInfoWindow : public CSimpleWindow
  43. {
  44. public:
  45. using TButtonsInfo = std::vector<std::pair<AnimationPath, CFunctionList<void()>>>;
  46. using TCompsInfo = std::vector<std::shared_ptr<CComponent>>;
  47. QueryID ID; //for identification
  48. std::shared_ptr<CTextBox> text;
  49. std::vector<std::shared_ptr<CButton>> buttons;
  50. TCompsInfo components;
  51. virtual void close();
  52. void show(Canvas & to) override;
  53. void showAll(Canvas & to) override;
  54. void sliderMoved(int to);
  55. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());
  56. CInfoWindow();
  57. ~CInfoWindow();
  58. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  59. static void showInfoDialog( const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
  60. static void showYesNoDialog( const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
  61. static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
  62. /// create text from title and description: {title}\n\n description
  63. static std::string genText(std::string title, std::string description);
  64. };
  65. /// popup displayed on R-click
  66. class CRClickPopup : public WindowBase
  67. {
  68. public:
  69. virtual void close();
  70. bool isPopupWindow() const override;
  71. static std::shared_ptr<WindowBase> createCustomInfoWindow(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, std::shared_ptr<CComponent> component);
  74. static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
  75. };
  76. /// popup displayed on R-click
  77. class CRClickPopupInt : public CRClickPopup
  78. {
  79. std::shared_ptr<CIntObject> inner;
  80. public:
  81. CRClickPopupInt(std::shared_ptr<CIntObject> our);
  82. virtual ~CRClickPopupInt();
  83. };
  84. class CInfoPopup : public CRClickPopup
  85. {
  86. public:
  87. bool free; //TODO: comment me
  88. SDL_Surface * bitmap; //popup background
  89. void close() override;
  90. void show(Canvas & to) override;
  91. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  92. CInfoPopup(SDL_Surface * Bitmap, const Point &p, ETextAlignment alignment, bool Free=false);
  93. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false);
  94. void init(int x, int y);
  95. ~CInfoPopup();
  96. };
  97. /// popup on adventure map for town\hero and other objects with customized popup content
  98. class CInfoBoxPopup : public CWindowObject
  99. {
  100. std::shared_ptr<CIntObject> tooltip;
  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. CInfoBoxPopup(Point position, const CGCreature * creature);
  107. };
  108. /// component selection window
  109. class CSelWindow : public CInfoWindow
  110. {
  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<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath,CFunctionList<void()> > > &Buttons, QueryID askID);
  115. //notification - this class inherits important destructor from CInfoWindow
  116. };