CCastleInterface.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. public:
  68. SDL_Rect pos; //why not inherit this member from CIntObject ?
  69. bool showing; //indicates if interface is active
  70. CBuildingRect * hBuild; //highlighted building
  71. SDL_Surface * townInt;
  72. SDL_Surface * cityBg;
  73. const CGTownInstance * town;
  74. CStatusBar * statusbar;
  75. CResDataBar *resdatabar;
  76. unsigned char animval, count;
  77. CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
  78. *status; //0 - already, 1 - can't, 2 - lack of resources
  79. CDefHandler *hall,*fort;
  80. CDefEssential* bicons; //150x70 buildings imgs
  81. CTownList * townlist;
  82. CHeroGSlot hslotup, hslotdown;
  83. AdventureMapButton *exit;
  84. AdventureMapButton *split;
  85. musicBase::musicID musicID;
  86. std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
  87. CCastleInterface(const CGTownInstance * Town, int listPos = 1); //c-tor
  88. ~CCastleInterface(); //d-tor
  89. void townChange();
  90. void keyPressed(const SDL_KeyboardEvent & key);
  91. void show(SDL_Surface * to);
  92. void showAll(SDL_Surface * to);
  93. void buildingClicked(int building);
  94. void enterTavern();
  95. void enterMageGuild();
  96. void splitClicked(); //for hero meeting (splitting stacks is handled by garrison int)
  97. CRecruitmentWindow * showRecruitmentWindow(int building);
  98. void enterHall();
  99. void close();
  100. void splitF();
  101. void activate();
  102. void deactivate();
  103. void addBuilding(int bid);
  104. void removeBuilding(int bid);
  105. void recreateBuildings();
  106. };
  107. class CHallInterface : public IShowActivable
  108. {
  109. public:
  110. CMinorResDataBar * resdatabar;
  111. SDL_Rect pos;
  112. class CBuildingBox : public CIntObject
  113. {
  114. public:
  115. int BID;
  116. 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
  117. //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists
  118. void hover(bool on);
  119. void clickLeft(tribool down, bool previousState);
  120. void clickRight(tribool down, bool previousState);
  121. void show(SDL_Surface * to);
  122. void activate();
  123. void deactivate();
  124. CBuildingBox(int id); //c-tor
  125. CBuildingBox(int id, int x, int y); //c-tor
  126. ~CBuildingBox(); //d-tor
  127. };
  128. class CBuildWindow: public CIntObject
  129. {
  130. public:
  131. int tid, bid, state; //town id, building id, state
  132. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  133. SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar"
  134. AdventureMapButton *buy, *cancel;
  135. void activate();
  136. void deactivate();
  137. std::string getTextForState(int state);
  138. void clickRight(tribool down, bool previousState);
  139. void show(SDL_Surface * to);
  140. void Buy();
  141. void close();
  142. CBuildWindow(int Tid, int Bid, int State, bool Mode); //c-tor
  143. ~CBuildWindow(); //d-tor
  144. };
  145. std::vector< std::vector<CBuildingBox*> >boxes;
  146. AdventureMapButton *exit;
  147. SDL_Surface * bg; //background
  148. CHallInterface(CCastleInterface * owner); //c-tor
  149. ~CHallInterface(); //d-tor
  150. void close();
  151. void show(SDL_Surface * to);
  152. void activate();
  153. void deactivate();
  154. };
  155. class CFortScreen : public CIntObject
  156. {
  157. class RecArea : public CIntObject
  158. {
  159. public:
  160. int bid;
  161. RecArea(int BID):bid(BID){}; //c-tor
  162. void clickLeft(tribool down, bool previousState);
  163. void clickRight(tribool down, bool previousState);
  164. void activate();
  165. void deactivate();
  166. };
  167. public:
  168. CMinorResDataBar * resdatabar;
  169. AdventureMapButton *exit;
  170. SDL_Surface * bg;
  171. std::vector<Rect> positions;
  172. std::vector<RecArea*> recAreas;
  173. std::vector<CCreaturePic*> crePics;
  174. CFortScreen(CCastleInterface * owner); //c-tor
  175. void draw( CCastleInterface * owner, bool first);
  176. ~CFortScreen(); //d-tor
  177. void close();
  178. void show(SDL_Surface * to);
  179. void activate();
  180. void deactivate();
  181. };
  182. class CMageGuildScreen : public CIntObject
  183. {
  184. public:
  185. class Scroll : public CIntObject
  186. {
  187. public:
  188. CSpell *spell;
  189. Scroll(CSpell *Spell):spell(Spell){};
  190. void clickLeft(tribool down, bool previousState);
  191. void clickRight(tribool down, bool previousState);
  192. void hover(bool on);
  193. void activate();
  194. void deactivate();
  195. };
  196. std::vector<std::vector<SDL_Rect> > positions;
  197. SDL_Surface *bg;
  198. CDefEssential *scrolls, *scrolls2;
  199. AdventureMapButton *exit;
  200. std::vector<Scroll> spells;
  201. CMinorResDataBar * resdatabar;
  202. CMageGuildScreen(CCastleInterface * owner); //c-tor
  203. ~CMageGuildScreen(); //d-tor
  204. void close();
  205. void show(SDL_Surface * to);
  206. void activate();
  207. void deactivate();
  208. };
  209. class CBlacksmithDialog : public CIntObject
  210. {
  211. public:
  212. AdventureMapButton *buy, *cancel;
  213. SDL_Surface *bmp; //background
  214. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); //c-tor
  215. ~CBlacksmithDialog(); //d-tor
  216. void close();
  217. void show(SDL_Surface * to);
  218. void activate();
  219. void deactivate();
  220. };
  221. #endif // __CCASTLEINTERFACE_H__