CCastleInterface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #ifndef __CCASTLEINTERFACE_H__
  2. #define __CCASTLEINTERFACE_H__
  3. #include "../global.h"
  4. #include "CAnimation.h"
  5. #include "GUIBase.h"
  6. class AdventureMapButton;
  7. class CBuilding;
  8. class CCastleBuildings;
  9. class CCreaturePic;
  10. class CGStatusBar;
  11. class CGTownInstance;
  12. class CLabel;
  13. class CMinorResDataBar;
  14. class CPicture;
  15. class CResDataBar;
  16. class CSpell;
  17. class CStatusBar;
  18. class CTextBox;
  19. class CTownList;
  20. struct Structure;
  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. /// Building "button"
  31. class CBuildingRect : public CShowableAnim
  32. {
  33. public:
  34. CCastleBuildings * parent;
  35. const CGTownInstance * town;
  36. const Structure* str;
  37. SDL_Surface* border;
  38. SDL_Surface* area;
  39. unsigned int stateCounter;//For building construction - current stage in animation
  40. CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const Structure *Str); //c-tor
  41. ~CBuildingRect(); //d-tor
  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. void show(SDL_Surface *to);
  48. void showAll(SDL_Surface *to);
  49. };
  50. /// Dwelling info box - right-click screen for dwellings
  51. class CDwellingInfoBox : public CIntObject
  52. {
  53. CPicture *background;
  54. CLabel *title;
  55. CCreaturePic *animation;
  56. CLabel *available;
  57. CLabel *costPerTroop;
  58. std::vector<CPicture *> resPicture;
  59. std::vector<CLabel *> resAmount;
  60. public:
  61. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level);
  62. void clickRight(tribool down, bool previousState);
  63. };
  64. /// Hero army slot
  65. class CHeroGSlot : public CIntObject
  66. {
  67. public:
  68. CCastleInterface *owner;
  69. const CGHeroInstance *hero;
  70. int upg; //0 - up garrison, 1 - down garrison
  71. bool highlight; //indicates id the slot is highlighted
  72. void setHighlight(bool on);
  73. void hover (bool on);
  74. void clickLeft(tribool down, bool previousState);
  75. void deactivate();
  76. void showAll(SDL_Surface * to);
  77. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner); //c-tor
  78. ~CHeroGSlot(); //d-tor
  79. };
  80. /// Class for town screen management (town background and structures)
  81. class CCastleBuildings : public CIntObject
  82. {
  83. struct AnimRule
  84. {
  85. int townID, buildID;
  86. int toCheck;
  87. size_t firstA, lastA;
  88. size_t firstB, lastB;
  89. };
  90. CPicture *background;
  91. //List of buildings for each group
  92. std::map< int, std::vector<const Structure*> > groups;
  93. //Vector with all blittable buildings
  94. std::vector<CBuildingRect*> buildings;
  95. const CGTownInstance * town;
  96. const CGHeroInstance* getHero();//Select hero for buildings usage
  97. void checkRules();//Check animation rules (special anims for Shipyard and Mana Vortex)
  98. void enterBlacksmith(int ArtifactID);//support for blacksmith + ballista yard
  99. void enterBuilding(int building);//for buildings with simple description + pic left-click messages
  100. void enterCastleGate();
  101. void enterFountain(int building);//Rampart's fountains
  102. void enterMagesGuild();
  103. void enterTownHall();
  104. void openMagesGuild();
  105. void openTownHall();
  106. public:
  107. CBuildingRect * selectedBuilding;
  108. CCastleBuildings(const CGTownInstance* town);
  109. ~CCastleBuildings();
  110. void enterDwelling(int level);
  111. void buildingClicked(int building);
  112. void addBuilding(int building);
  113. void removeBuilding(int building);//FIXME: not tested!!!
  114. void show(SDL_Surface *to);
  115. void showAll(SDL_Surface *to);
  116. };
  117. /// Creature info window
  118. class CCreaInfo : public CIntObject
  119. {
  120. const CGTownInstance * town;
  121. const CCreature *creature;
  122. int level;
  123. CAnimImage *picture;
  124. CLabel * label;
  125. int AddToString(std::string from, std::string & to, int numb);
  126. public:
  127. CCreaInfo(int posX, int posY, const CGTownInstance *Town, int Level);
  128. void hover(bool on);
  129. void clickLeft(tribool down, bool previousState);
  130. void clickRight(tribool down, bool previousState);
  131. };
  132. /// Town hall and fort icons for town screen
  133. class CTownInfo : public CIntObject
  134. {
  135. const CGTownInstance *town;
  136. const CBuilding *building;
  137. CAnimImage *picture;
  138. public:
  139. //if (townHall) hall-capital else fort - castle
  140. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  141. void hover(bool on);
  142. void clickRight(tribool down, bool previousState);
  143. };
  144. /// Class which manages the castle window
  145. class CCastleInterface : public CWindowWithGarrison
  146. {
  147. CLabel *title;
  148. CLabel *income;
  149. CAnimImage *icon;
  150. CPicture * panel;
  151. CResDataBar *resdatabar;
  152. CGStatusBar * statusbar;
  153. CTownInfo *hall, *fort;
  154. CTownList * townlist;
  155. AdventureMapButton *exit;
  156. AdventureMapButton *split;
  157. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  158. public:
  159. //TODO: remove - currently used only in dialog messages
  160. CDefEssential* bicons; //150x70 buildings imgs
  161. //TODO: move to private
  162. const CGTownInstance * town;
  163. CHeroGSlot *heroSlotUp, *heroSlotDown;
  164. CCastleBuildings *builds;
  165. CCastleInterface(const CGTownInstance * Town, int listPos = 1); //c-tor
  166. ~CCastleInterface();
  167. void castleTeleport(int where);
  168. void townChange();
  169. void keyPressed(const SDL_KeyboardEvent & key);
  170. void splitClicked(); //for hero meeting (splitting stacks is handled by garrison int)
  171. void showAll(SDL_Surface *to);
  172. void close();
  173. void addBuilding(int bid);
  174. void removeBuilding(int bid);
  175. void recreateIcons();
  176. };
  177. /// Hall window where you can build things
  178. class CHallInterface : public CIntObject
  179. {
  180. /// Building box from town hall (building icon + subtitle)
  181. class CBuildingBox : public CIntObject
  182. {
  183. const CGTownInstance * town;
  184. const CBuilding * building;
  185. unsigned int state;//Buildings::EBuildStructure enum
  186. CAnimImage * picture;
  187. CAnimImage * panel;
  188. CAnimImage * icon;
  189. CLabel * label;
  190. public:
  191. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  192. void hover(bool on);
  193. void clickLeft(tribool down, bool previousState);
  194. void clickRight(tribool down, bool previousState);
  195. };
  196. const CGTownInstance * town;
  197. std::vector< std::vector<CBuildingBox*> >boxes;
  198. CPicture *background;
  199. CLabel *title;
  200. CGStatusBar *statusBar;
  201. CMinorResDataBar * resdatabar;
  202. AdventureMapButton *exit;
  203. public:
  204. CHallInterface(const CGTownInstance * Town); //c-tor
  205. void close();
  206. };
  207. /// Window where you can decide to buy a building or not
  208. class CBuildWindow: public CIntObject
  209. {
  210. const CGTownInstance *town;
  211. const CBuilding *building;
  212. int state; //state - same as CHallInterface::CBuildingBox::state
  213. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  214. CPicture *background;
  215. CAnimImage *buildingPic;
  216. AdventureMapButton *buy;
  217. AdventureMapButton *cancel;
  218. CLabel * title;
  219. CTextBox * buildingDescr;
  220. CTextBox * buildingState;
  221. CGStatusBar *statusBar;
  222. std::vector<CPicture *> resPicture;
  223. std::vector<CLabel *> resAmount;
  224. std::string getTextForState(int state);
  225. void buyFunc();
  226. void close();
  227. public:
  228. void clickRight(tribool down, bool previousState);
  229. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool Mode); //c-tor
  230. ~CBuildWindow(); //d-tor
  231. };
  232. //Small class to display
  233. class LabeledValue : public CIntObject
  234. {
  235. std::string hoverText;
  236. CLabel *name;
  237. CLabel *value;
  238. void init(std::string name, std::string descr, int min, int max);
  239. public:
  240. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  241. LabeledValue(Rect size, std::string name, std::string descr, int val);
  242. void hover(bool on);
  243. };
  244. /// The fort screen where you can afford units
  245. class CFortScreen : public CIntObject
  246. {
  247. class RecruitArea : public CIntObject
  248. {
  249. const CGTownInstance *town;
  250. int level;
  251. std::string hoverText;
  252. CLabel * creatureName;
  253. CLabel * dwellingName;
  254. CLabel * availableCount;
  255. std::vector<LabeledValue*> values;
  256. CPicture *icons;
  257. CAnimImage * buildingPic;
  258. CCreaturePic *creatureAnim;
  259. public:
  260. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  261. void creaturesChanged();
  262. void hover(bool on);
  263. void clickLeft(tribool down, bool previousState);
  264. void clickRight(tribool down, bool previousState);
  265. };
  266. CPicture *background;
  267. CLabel *title;
  268. std::vector<RecruitArea*> recAreas;
  269. CMinorResDataBar * resdatabar;
  270. CGStatusBar *statusBar;
  271. AdventureMapButton *exit;
  272. public:
  273. CFortScreen(const CGTownInstance * town); //c-tor
  274. void creaturesChanged();
  275. void close();
  276. };
  277. /// The mage guild screen where you can see which spells you have
  278. class CMageGuildScreen : public CIntObject
  279. {
  280. class Scroll : public CIntObject
  281. {
  282. const CSpell *spell;
  283. CAnimImage *image;
  284. public:
  285. Scroll(Point position, const CSpell *Spell);
  286. void clickLeft(tribool down, bool previousState);
  287. void clickRight(tribool down, bool previousState);
  288. void hover(bool on);
  289. };
  290. CPicture *background;
  291. CPicture *window;
  292. AdventureMapButton *exit;
  293. std::vector<Scroll *> spells;
  294. CMinorResDataBar * resdatabar;
  295. CGStatusBar *statusBar;
  296. void close();
  297. public:
  298. CMageGuildScreen(CCastleInterface * owner);
  299. };
  300. /// The blacksmith window where you can buy available in town war machine
  301. class CBlacksmithDialog : public CIntObject
  302. {
  303. AdventureMapButton *buy, *cancel;
  304. CPicture *background;
  305. CPicture *animBG;
  306. CCreatureAnim * anim;
  307. CPicture * gold;
  308. CLabel * title;
  309. CLabel * costText;
  310. CLabel * costValue;
  311. CGStatusBar *statusBar;
  312. void close();
  313. public:
  314. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  315. };
  316. #endif // __CCASTLEINTERFACE_H__