2
0

MiscWidgets.h 6.7 KB

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