CCastleInterface.h 7.8 KB

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