CCastleInterface.h 7.6 KB

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