CCastleInterface.h 6.8 KB

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