CCastleInterface.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. 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 townChange();
  116. void keyPressed(const SDL_KeyboardEvent & key);
  117. void show(SDL_Surface * to);
  118. void showAll(SDL_Surface * to);
  119. void buildingClicked(int building);
  120. void defaultBuildingClicked(int building);//for buildings with simple description + pic left-click messages
  121. void enterFountain(int building);
  122. void enterBlacksmith(int ArtifactID);//support for blacksmith + ballista yard
  123. void enterTavern();
  124. void enterMageGuild();
  125. void splitClicked(); //for hero meeting (splitting stacks is handled by garrison int)
  126. CRecruitmentWindow * showRecruitmentWindow(int building);
  127. void enterHall();
  128. void close();
  129. void splitF();
  130. void activate();
  131. void deactivate();
  132. void addBuilding(int bid);
  133. void removeBuilding(int bid);
  134. void recreateBuildings();
  135. void recreateIcons();
  136. };
  137. class CHallInterface : public IShowActivable
  138. {
  139. public:
  140. CMinorResDataBar * resdatabar;
  141. SDL_Rect pos;
  142. class CBuildingBox : public CIntObject
  143. {
  144. public:
  145. int BID;
  146. 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
  147. //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists
  148. void hover(bool on);
  149. void clickLeft(tribool down, bool previousState);
  150. void clickRight(tribool down, bool previousState);
  151. void show(SDL_Surface * to);
  152. CBuildingBox(int id); //c-tor
  153. CBuildingBox(int id, int x, int y); //c-tor
  154. ~CBuildingBox(); //d-tor
  155. };
  156. class CBuildWindow: public CIntObject
  157. {
  158. public:
  159. int tid, bid, state; //town id, building id, state
  160. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  161. SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar"
  162. AdventureMapButton *buy, *cancel;
  163. void activate();
  164. void deactivate();
  165. std::string getTextForState(int state);
  166. void clickRight(tribool down, bool previousState);
  167. void show(SDL_Surface * to);
  168. void Buy();
  169. void close();
  170. CBuildWindow(int Tid, int Bid, int State, bool Mode); //c-tor
  171. ~CBuildWindow(); //d-tor
  172. };
  173. std::vector< std::vector<CBuildingBox*> >boxes;
  174. AdventureMapButton *exit;
  175. SDL_Surface * bg; //background
  176. int bid;//building ID
  177. CHallInterface(CCastleInterface * owner); //c-tor
  178. ~CHallInterface(); //d-tor
  179. void close();
  180. void show(SDL_Surface * to);
  181. void activate();
  182. void deactivate();
  183. };
  184. class CFortScreen : public CIntObject
  185. {
  186. class RecArea : public CIntObject
  187. {
  188. public:
  189. int bid;
  190. RecArea(int BID):bid(BID){used = LCLICK | RCLICK;}; //c-tor
  191. void clickLeft(tribool down, bool previousState);
  192. void clickRight(tribool down, bool previousState);
  193. };
  194. public:
  195. CMinorResDataBar * resdatabar;
  196. AdventureMapButton *exit;
  197. SDL_Surface * bg;
  198. std::vector<Rect> positions;
  199. std::vector<RecArea*> recAreas;
  200. std::vector<CCreaturePic*> crePics;
  201. CFortScreen(CCastleInterface * owner); //c-tor
  202. void draw( CCastleInterface * owner, bool first);
  203. ~CFortScreen(); //d-tor
  204. void close();
  205. void show(SDL_Surface * to);
  206. void activate();
  207. void deactivate();
  208. };
  209. class CMageGuildScreen : public CIntObject
  210. {
  211. public:
  212. class Scroll : public CIntObject
  213. {
  214. public:
  215. CSpell *spell;
  216. Scroll(CSpell *Spell):spell(Spell){used = LCLICK | RCLICK | HOVER;};
  217. void clickLeft(tribool down, bool previousState);
  218. void clickRight(tribool down, bool previousState);
  219. void hover(bool on);
  220. };
  221. std::vector<std::vector<SDL_Rect> > positions;
  222. SDL_Surface *bg;
  223. CDefEssential *scrolls, *scrolls2;
  224. AdventureMapButton *exit;
  225. std::vector<Scroll> spells;
  226. CMinorResDataBar * resdatabar;
  227. CMageGuildScreen(CCastleInterface * owner); //c-tor
  228. ~CMageGuildScreen(); //d-tor
  229. void close();
  230. void show(SDL_Surface * to);
  231. void activate();
  232. void deactivate();
  233. };
  234. class CBlacksmithDialog : public CIntObject
  235. {
  236. public:
  237. AdventureMapButton *buy, *cancel;
  238. SDL_Surface *bmp; //background
  239. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); //c-tor
  240. ~CBlacksmithDialog(); //d-tor
  241. void close();
  242. void show(SDL_Surface * to);
  243. void activate();
  244. void deactivate();
  245. };
  246. #endif // __CCASTLEINTERFACE_H__