CCastleInterface.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #ifndef __CCASTLEINTERFACE_H__
  2. #define __CCASTLEINTERFACE_H__
  3. #include "global.h"
  4. #include <SDL.h>
  5. #include "CPlayerInterface.h"
  6. //#include "boost/tuple/tuple.hpp"
  7. class CGTownInstance;
  8. class CTownHandler;
  9. class CHallInterface;
  10. struct Structure;
  11. class CSpell;
  12. class AdventureMapButton;
  13. class CResDataBar;
  14. /*
  15. * CCastleInterface.h, part of VCMI engine
  16. *
  17. * Authors: listed in file AUTHORS in main folder
  18. *
  19. * License: GNU General Public License v2.0 or later
  20. * Full text of license available in license.txt file, in main folder
  21. *
  22. */
  23. class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested
  24. {
  25. public:
  26. bool moi; //motion interested is active
  27. int offset, max; //first and last animation frame
  28. Structure* str;
  29. CDefHandler* def;
  30. SDL_Surface* border;
  31. SDL_Surface* area;
  32. CBuildingRect(Structure *Str);
  33. ~CBuildingRect();
  34. void activate();
  35. void deactivate();
  36. bool operator<(const CBuildingRect & p2) const;
  37. void hover(bool on);
  38. void clickLeft (tribool down);
  39. void clickRight (tribool down);
  40. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  41. };
  42. class CHeroGSlot : public ClickableL, public ClickableR, public Hoverable
  43. {
  44. public:
  45. CCastleInterface *owner;
  46. const CGHeroInstance *hero;
  47. int upg; //0 - up garrison, 1 - down garrison
  48. bool highlight; //indicates id the slot is highlighted
  49. void hover (bool on);
  50. void clickRight (boost::logic::tribool down);
  51. void clickLeft(boost::logic::tribool down);
  52. void activate();
  53. void deactivate();
  54. void show(SDL_Surface * to);
  55. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner);
  56. ~CHeroGSlot();
  57. };
  58. class CCastleInterface : public CWindowWithGarrison
  59. {
  60. public:
  61. SDL_Rect pos; //why not inherit this member from CIntObject ?
  62. bool showing; //indicates if interface is active
  63. CBuildingRect * hBuild; //highlighted building
  64. SDL_Surface * townInt;
  65. SDL_Surface * cityBg;
  66. const CGTownInstance * town;
  67. CStatusBar * statusbar;
  68. CResDataBar *resdatabar;
  69. unsigned char animval, count;
  70. CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
  71. *status; //0 - already, 1 - can't, 2 - lack of resources
  72. CDefHandler *hall,*fort;
  73. CDefEssential* bicons; //150x70 buildings imgs
  74. CTownList * townlist;
  75. CHeroGSlot hslotup, hslotdown;
  76. AdventureMapButton *exit;
  77. AdventureMapButton *split;
  78. musicBase::musicID musicID;
  79. std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
  80. CCastleInterface(const CGTownInstance * Town);
  81. ~CCastleInterface();
  82. void townChange();
  83. void show(SDL_Surface * to);
  84. void showAll(SDL_Surface * to);
  85. void buildingClicked(int building);
  86. void enterMageGuild();
  87. CRecrutationWindow * showRecruitmentWindow(int building);
  88. void enterHall();
  89. void close();
  90. void splitF();
  91. void activate();
  92. void deactivate();
  93. void addBuilding(int bid);
  94. void removeBuilding(int bid);
  95. void recreateBuildings();
  96. };
  97. class CHallInterface : public IShowActivable
  98. {
  99. public:
  100. CMinorResDataBar resdatabar;
  101. SDL_Rect pos;
  102. class CBuildingBox : public Hoverable, public ClickableL, public ClickableR
  103. {
  104. public:
  105. int BID;
  106. int state;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
  107. //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists
  108. void hover(bool on);
  109. void clickLeft (tribool down);
  110. void clickRight (tribool down);
  111. void show(SDL_Surface * to);
  112. void activate();
  113. void deactivate();
  114. CBuildingBox(int id);
  115. CBuildingBox(int id, int x, int y);
  116. ~CBuildingBox();
  117. };
  118. class CBuildWindow: public IShowActivable, public ClickableR
  119. {
  120. public:
  121. int tid, bid, state; //town id, building id, state
  122. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  123. SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar"
  124. AdventureMapButton *buy, *cancel;
  125. void activate();
  126. void deactivate();
  127. std::string getTextForState(int state);
  128. void clickRight (tribool down);
  129. void show(SDL_Surface * to);
  130. void Buy();
  131. void close();
  132. CBuildWindow(int Tid, int Bid, int State, bool Mode);
  133. ~CBuildWindow();
  134. };
  135. std::vector< std::vector<CBuildingBox*> >boxes;
  136. AdventureMapButton *exit;
  137. SDL_Surface * bg;
  138. CHallInterface(CCastleInterface * owner);
  139. ~CHallInterface();
  140. void close();
  141. void show(SDL_Surface * to);
  142. void activate();
  143. void deactivate();
  144. };
  145. class CFortScreen : public IShowActivable, public CIntObject
  146. {
  147. class RecArea : public ClickableL, public ClickableR
  148. {
  149. public:
  150. int bid;
  151. RecArea(int BID):bid(BID){}; //c-tor
  152. void clickLeft (tribool down);
  153. void clickRight (tribool down);
  154. void activate();
  155. void deactivate();
  156. };
  157. public:
  158. CMinorResDataBar resdatabar;
  159. AdventureMapButton *exit;
  160. SDL_Surface * bg;
  161. std::vector<Rect> positions;
  162. std::vector<RecArea*> recAreas;
  163. std::vector<CCreaturePic*> crePics;
  164. CFortScreen(CCastleInterface * owner); //c-tor
  165. void draw( CCastleInterface * owner, bool first);
  166. ~CFortScreen(); //d-tor
  167. void close();
  168. void show(SDL_Surface * to);
  169. void activate();
  170. void deactivate();
  171. };
  172. class CMageGuildScreen : public IShowActivable, public CIntObject
  173. {
  174. public:
  175. class Scroll : public ClickableL, public Hoverable, public ClickableR
  176. {
  177. public:
  178. CSpell *spell;
  179. Scroll(CSpell *Spell):spell(Spell){};
  180. void clickLeft (tribool down);
  181. void clickRight (tribool down);
  182. void hover(bool on);
  183. void activate();
  184. void deactivate();
  185. };
  186. std::vector<std::vector<SDL_Rect> > positions;
  187. SDL_Surface *bg;
  188. CDefEssential *scrolls, *scrolls2;
  189. AdventureMapButton *exit;
  190. std::vector<Scroll> spells;
  191. CMinorResDataBar resdatabar;
  192. CMageGuildScreen(CCastleInterface * owner);
  193. ~CMageGuildScreen();
  194. void close();
  195. void show(SDL_Surface * to);
  196. void activate();
  197. void deactivate();
  198. };
  199. class CBlacksmithDialog : public IShowActivable, public CIntObject
  200. {
  201. public:
  202. AdventureMapButton *buy, *cancel;
  203. SDL_Surface *bmp;
  204. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  205. ~CBlacksmithDialog();
  206. void close();
  207. void show(SDL_Surface * to);
  208. void activate();
  209. void deactivate();
  210. };
  211. #endif // __CCASTLEINTERFACE_H__