CCastleInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. CAnimImage *picture;
  138. CLabel * label;
  139. int AddToString(std::string from, std::string & to, int numb);
  140. public:
  141. CCreaInfo(int posX, int posY, const CGTownInstance *Town, int Level);
  142. void hover(bool on);
  143. void clickLeft(tribool down, bool previousState);
  144. void clickRight(tribool down, bool previousState);
  145. };
  146. /// Town hall and fort icons for town screen
  147. class CTownInfo : public CIntObject
  148. {
  149. const CGTownInstance *town;
  150. const CBuilding *building;
  151. CAnimImage *picture;
  152. public:
  153. //if (townHall) hall-capital else fort - castle
  154. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  155. void hover(bool on);
  156. void clickRight(tribool down, bool previousState);
  157. };
  158. /// Class which manages the castle window
  159. class CCastleInterface : public CWindowWithGarrison
  160. {
  161. CLabel *title;
  162. CLabel *income;
  163. CAnimImage *icon;
  164. CPicture * panel;
  165. CResDataBar *resdatabar;
  166. CGStatusBar * statusbar;
  167. CTownInfo *hall, *fort;
  168. CTownList * townlist;
  169. AdventureMapButton *exit;
  170. AdventureMapButton *split;
  171. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  172. public:
  173. //TODO: remove - currently used only in dialog messages
  174. CDefEssential* bicons; //150x70 buildings imgs
  175. //TODO: move to private
  176. const CGTownInstance * town;
  177. HeroSlots *heroes;
  178. CCastleBuildings *builds;
  179. CCastleInterface(const CGTownInstance * Town, int listPos = 1); //c-tor
  180. ~CCastleInterface();
  181. void castleTeleport(int where);
  182. void townChange();
  183. void keyPressed(const SDL_KeyboardEvent & key);
  184. void showAll(SDL_Surface *to);
  185. void close();
  186. void addBuilding(int bid);
  187. void removeBuilding(int bid);
  188. void recreateIcons();
  189. };
  190. /// Hall window where you can build things
  191. class CHallInterface : public CIntObject
  192. {
  193. /// Building box from town hall (building icon + subtitle)
  194. class CBuildingBox : public CIntObject
  195. {
  196. const CGTownInstance * town;
  197. const CBuilding * building;
  198. unsigned int state;//Buildings::EBuildStructure enum
  199. CAnimImage * picture;
  200. CAnimImage * panel;
  201. CAnimImage * icon;
  202. CLabel * label;
  203. public:
  204. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  205. void hover(bool on);
  206. void clickLeft(tribool down, bool previousState);
  207. void clickRight(tribool down, bool previousState);
  208. };
  209. const CGTownInstance * town;
  210. std::vector< std::vector<CBuildingBox*> >boxes;
  211. CPicture *background;
  212. CLabel *title;
  213. CGStatusBar *statusBar;
  214. CMinorResDataBar * resdatabar;
  215. AdventureMapButton *exit;
  216. public:
  217. CHallInterface(const CGTownInstance * Town); //c-tor
  218. void close();
  219. };
  220. /// Window where you can decide to buy a building or not
  221. class CBuildWindow: public CIntObject
  222. {
  223. const CGTownInstance *town;
  224. const CBuilding *building;
  225. int state; //state - same as CHallInterface::CBuildingBox::state
  226. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  227. CPicture *background;
  228. CAnimImage *buildingPic;
  229. AdventureMapButton *buy;
  230. AdventureMapButton *cancel;
  231. CLabel * title;
  232. CTextBox * buildingDescr;
  233. CTextBox * buildingState;
  234. CGStatusBar *statusBar;
  235. std::vector<CPicture *> resPicture;
  236. std::vector<CLabel *> resAmount;
  237. std::string getTextForState(int state);
  238. void buyFunc();
  239. void close();
  240. public:
  241. void clickRight(tribool down, bool previousState);
  242. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool Mode); //c-tor
  243. ~CBuildWindow(); //d-tor
  244. };
  245. //Small class to display
  246. class LabeledValue : public CIntObject
  247. {
  248. std::string hoverText;
  249. CLabel *name;
  250. CLabel *value;
  251. void init(std::string name, std::string descr, int min, int max);
  252. public:
  253. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  254. LabeledValue(Rect size, std::string name, std::string descr, int val);
  255. void hover(bool on);
  256. };
  257. /// The fort screen where you can afford units
  258. class CFortScreen : public CIntObject
  259. {
  260. class RecruitArea : public CIntObject
  261. {
  262. const CGTownInstance *town;
  263. int level;
  264. std::string hoverText;
  265. CLabel * creatureName;
  266. CLabel * dwellingName;
  267. CLabel * availableCount;
  268. std::vector<LabeledValue*> values;
  269. CPicture *icons;
  270. CAnimImage * buildingPic;
  271. CCreaturePic *creatureAnim;
  272. public:
  273. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  274. void creaturesChanged();
  275. void hover(bool on);
  276. void clickLeft(tribool down, bool previousState);
  277. void clickRight(tribool down, bool previousState);
  278. };
  279. CPicture *background;
  280. CLabel *title;
  281. std::vector<RecruitArea*> recAreas;
  282. CMinorResDataBar * resdatabar;
  283. CGStatusBar *statusBar;
  284. AdventureMapButton *exit;
  285. public:
  286. CFortScreen(const CGTownInstance * town); //c-tor
  287. void creaturesChanged();
  288. void close();
  289. };
  290. /// The mage guild screen where you can see which spells you have
  291. class CMageGuildScreen : public CIntObject
  292. {
  293. class Scroll : public CIntObject
  294. {
  295. const CSpell *spell;
  296. CAnimImage *image;
  297. public:
  298. Scroll(Point position, const CSpell *Spell);
  299. void clickLeft(tribool down, bool previousState);
  300. void clickRight(tribool down, bool previousState);
  301. void hover(bool on);
  302. };
  303. CPicture *background;
  304. CPicture *window;
  305. AdventureMapButton *exit;
  306. std::vector<Scroll *> spells;
  307. CMinorResDataBar * resdatabar;
  308. CGStatusBar *statusBar;
  309. void close();
  310. public:
  311. CMageGuildScreen(CCastleInterface * owner);
  312. };
  313. /// The blacksmith window where you can buy available in town war machine
  314. class CBlacksmithDialog : public CIntObject
  315. {
  316. AdventureMapButton *buy, *cancel;
  317. CPicture *background;
  318. CPicture *animBG;
  319. CCreatureAnim * anim;
  320. CPicture * gold;
  321. CLabel * title;
  322. CLabel * costText;
  323. CLabel * costValue;
  324. CGStatusBar *statusBar;
  325. void close();
  326. public:
  327. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  328. };
  329. #endif // __CCASTLEINTERFACE_H__