MiscWidgets.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #pragma once
  2. #include "CComponent.h"
  3. /*
  4. * MiscWidgets.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. class CCreatureAnim;
  13. class CComponent;
  14. class CGGarrison;
  15. class CSelectableComponent;
  16. class InfoAboutArmy;
  17. class CArmedInstance;
  18. class IBonusBearer;
  19. /// text + comp. + ok button
  20. class CInfoWindow : public CSimpleWindow
  21. { //window able to delete its components when closed
  22. bool delComps; //whether comps will be deleted
  23. public:
  24. typedef std::vector<std::pair<std::string,CFunctionList<void()> > > TButtonsInfo;
  25. typedef std::vector<CComponent*> TCompsInfo;
  26. QueryID ID; //for identification
  27. CTextBox *text;
  28. std::vector<CAdventureMapButton *> buttons;
  29. std::vector<CComponent*> components;
  30. CSlider *slider;
  31. void setDelComps(bool DelComps);
  32. virtual void close();
  33. void show(SDL_Surface * to);
  34. void showAll(SDL_Surface * to);
  35. void sliderMoved(int to);
  36. CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo &comps = TCompsInfo(), const TButtonsInfo &Buttons = TButtonsInfo(), bool delComps = true); //c-tor
  37. CInfoWindow(); //c-tor
  38. ~CInfoWindow(); //d-tor
  39. //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  40. static void showInfoDialog( const std::string & text, const std::vector<CComponent*> *components, bool DelComps = true, PlayerColor player = PlayerColor(1));
  41. static void showOkDialog(const std::string & text, const std::vector<CComponent*> *components, const boost::function<void()> & onOk, bool delComps = true, PlayerColor player = PlayerColor(1));
  42. 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));
  43. static CInfoWindow *create(const std::string &text, PlayerColor playerID = PlayerColor(1), const std::vector<CComponent*> *components = nullptr, bool DelComps = false);
  44. /// create text from title and description: {title}\n\n description
  45. static std::string genText(std::string title, std::string description);
  46. };
  47. /// popup displayed on R-click
  48. class CRClickPopup : public CIntObject
  49. {
  50. public:
  51. virtual void close();
  52. void clickRight(tribool down, bool previousState);
  53. CRClickPopup();
  54. virtual ~CRClickPopup(); //d-tor
  55. static CIntObject* createInfoWin(Point position, const CGObjectInstance * specific);
  56. static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  57. static void createAndPush(const std::string &txt, CComponent * component);
  58. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  59. };
  60. /// popup displayed on R-click
  61. class CRClickPopupInt : public CRClickPopup
  62. {
  63. public:
  64. IShowActivatable *inner;
  65. bool delInner;
  66. void show(SDL_Surface * to);
  67. void showAll(SDL_Surface * to);
  68. CRClickPopupInt(IShowActivatable *our, bool deleteInt); //c-tor
  69. virtual ~CRClickPopupInt(); //d-tor
  70. };
  71. class CInfoPopup : public CRClickPopup
  72. {
  73. public:
  74. bool free; //TODO: comment me
  75. SDL_Surface * bitmap; //popup background
  76. void close();
  77. void show(SDL_Surface * to);
  78. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  79. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  80. CInfoPopup(SDL_Surface * Bitmap = nullptr, bool Free = false); //default c-tor
  81. void init(int x, int y);
  82. ~CInfoPopup(); //d-tor
  83. };
  84. /// popup on adventure map for town\hero objects
  85. class CInfoBoxPopup : public CWindowObject
  86. {
  87. Point toScreen(Point pos);
  88. public:
  89. CInfoBoxPopup(Point position, const CGTownInstance * town);
  90. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  91. CInfoBoxPopup(Point position, const CGGarrison * garr);
  92. };
  93. /// component selection window
  94. class CSelWindow : public CInfoWindow
  95. { //warning - this window deletes its components by closing!
  96. public:
  97. void selectionChange(unsigned to);
  98. void madeChoice(); //looks for selected component and calls callback
  99. 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
  100. CSelWindow(){}; //c-tor
  101. //notification - this class inherits important destructor from CInfoWindow
  102. };
  103. /// base class for hero/town/garrison tooltips
  104. class CArmyTooltip : public CIntObject
  105. {
  106. void init(const InfoAboutArmy &army);
  107. public:
  108. CArmyTooltip(Point pos, const InfoAboutArmy &army);
  109. CArmyTooltip(Point pos, const CArmedInstance * army);
  110. };
  111. /// Class for hero tooltip. Does not have any background!
  112. /// background for infoBox: ADSTATHR
  113. /// background for tooltip: HEROQVBK
  114. class CHeroTooltip : public CArmyTooltip
  115. {
  116. void init(const InfoAboutHero &hero);
  117. public:
  118. CHeroTooltip(Point pos, const InfoAboutHero &hero);
  119. CHeroTooltip(Point pos, const CGHeroInstance * hero);
  120. };
  121. /// Class for town tooltip. Does not have any background!
  122. /// background for infoBox: ADSTATCS
  123. /// background for tooltip: TOWNQVBK
  124. class CTownTooltip : public CArmyTooltip
  125. {
  126. void init(const InfoAboutTown &town);
  127. public:
  128. CTownTooltip(Point pos, const InfoAboutTown &town);
  129. CTownTooltip(Point pos, const CGTownInstance * town);
  130. };
  131. /// draws picture with creature on background, use Animated=true to get animation
  132. class CCreaturePic : public CIntObject
  133. {
  134. private:
  135. CPicture *bg;
  136. CCreatureAnim *anim; //displayed animation
  137. public:
  138. CCreaturePic(int x, int y, const CCreature *cre, bool Big=true, bool Animated=true); //c-tor
  139. };
  140. /// Resource bar like that at the bottom of the adventure map screen
  141. class CMinorResDataBar : public CIntObject
  142. {
  143. public:
  144. SDL_Surface *bg; //background bitmap
  145. void show(SDL_Surface * to);
  146. void showAll(SDL_Surface * to);
  147. CMinorResDataBar(); //c-tor
  148. ~CMinorResDataBar(); //d-tor
  149. };
  150. class MoraleLuckBox : public LRClickableAreaWTextComp
  151. {
  152. CAnimImage *image;
  153. public:
  154. bool morale; //true if morale, false if luck
  155. bool small;
  156. void set(const IBonusBearer *node);
  157. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  158. };
  159. /// Opens hero window by left-clicking on it
  160. class CHeroArea: public CIntObject
  161. {
  162. const CGHeroInstance * hero;
  163. public:
  164. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  165. void clickLeft(tribool down, bool previousState);
  166. void clickRight(tribool down, bool previousState);
  167. void hover(bool on);
  168. };
  169. /// Opens town screen by left-clicking on it
  170. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  171. {
  172. public:
  173. const CGTownInstance * town;
  174. void clickLeft(tribool down, bool previousState);
  175. void clickRight(tribool down, bool previousState);
  176. LRClickableAreaOpenTown();
  177. };