CCastleInterface.h 7.7 KB

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