CCastleInterface.h 10 KB

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