CCastleInterface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * CCastleInterface.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../widgets/CGarrisonInt.h"
  12. #include "../widgets/Images.h"
  13. class CButton;
  14. class CBuilding;
  15. class CCastleBuildings;
  16. class CCreaturePic;
  17. class CGStatusBar;
  18. class CGTownInstance;
  19. class CLabel;
  20. class CMinorResDataBar;
  21. class CPicture;
  22. class CResDataBar;
  23. class CSpell;
  24. class CTextBox;
  25. class CTownList;
  26. struct CStructure;
  27. class CGHeroInstance;
  28. class CGarrisonInt;
  29. class CCreature;
  30. /// Building "button"
  31. class CBuildingRect : public CShowableAnim
  32. {
  33. std::string getSubtitle();
  34. public:
  35. /// returns building associated with this structure
  36. const CBuilding * getBuilding();
  37. CCastleBuildings * parent;
  38. const CGTownInstance * town;
  39. const CStructure* str;
  40. SDL_Surface* border;
  41. SDL_Surface* area;
  42. ui32 stateCounter;//For building construction - current stage in animation
  43. CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str);
  44. ~CBuildingRect();
  45. bool operator<(const CBuildingRect & p2) const;
  46. void hover(bool on) override;
  47. void clickLeft(tribool down, bool previousState) override;
  48. void clickRight(tribool down, bool previousState) override;
  49. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  50. void show(SDL_Surface * to) override;
  51. void showAll(SDL_Surface * to) override;
  52. };
  53. /// Dwelling info box - right-click screen for dwellings
  54. class CDwellingInfoBox : public CWindowObject
  55. {
  56. CLabel *title;
  57. CCreaturePic *animation;
  58. CLabel *available;
  59. CLabel *costPerTroop;
  60. std::vector<CAnimImage *> resPicture;
  61. std::vector<CLabel *> resAmount;
  62. public:
  63. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level);
  64. };
  65. class HeroSlots;
  66. /// Hero icon slot
  67. class CHeroGSlot : public CIntObject
  68. {
  69. public:
  70. HeroSlots *owner;
  71. const CGHeroInstance *hero;
  72. int upg; //0 - up garrison, 1 - down garrison
  73. CAnimImage *image;
  74. CAnimImage *selection; //selection border. nullptr if not selected
  75. void setHighlight(bool on);
  76. void set(const CGHeroInstance *newHero);
  77. void hover (bool on) override;
  78. void clickLeft(tribool down, bool previousState) override;
  79. void clickRight(tribool down, bool previousState) override;
  80. void deactivate() override;
  81. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner);
  82. ~CHeroGSlot();
  83. };
  84. /// Two hero slots that can interact with each other
  85. class HeroSlots : public CIntObject
  86. {
  87. public:
  88. bool showEmpty;
  89. const CGTownInstance * town;
  90. CGarrisonInt *garr;
  91. CHeroGSlot * garrisonedHero;
  92. CHeroGSlot * visitingHero;
  93. HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty);
  94. void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int)
  95. void update();
  96. void swapArmies(); //exchange garrisoned and visiting heroes or move hero to\from garrison
  97. };
  98. /// Class for town screen management (town background and structures)
  99. class CCastleBuildings : public CIntObject
  100. {
  101. CPicture *background;
  102. //List of buildings and structures that can represent them
  103. std::map< BuildingID, std::vector<const CStructure*> > groups;
  104. // actual IntObject's visible on screen
  105. std::vector< CBuildingRect * > buildings;
  106. const CGTownInstance * town;
  107. const CGHeroInstance* getHero();//Select hero for buildings usage
  108. void enterBlacksmith(ArtifactID artifactID);//support for blacksmith + ballista yard
  109. void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages
  110. void enterCastleGate();
  111. void enterFountain(BuildingID building);//Rampart's fountains
  112. void enterMagesGuild();
  113. void enterTownHall();
  114. void openMagesGuild();
  115. void openTownHall();
  116. void recreate();
  117. public:
  118. CBuildingRect * selectedBuilding;
  119. CCastleBuildings(const CGTownInstance* town);
  120. ~CCastleBuildings();
  121. void enterDwelling(int level);
  122. void enterToTheQuickRecruitmentWindow();
  123. void buildingClicked(BuildingID building);
  124. void addBuilding(BuildingID building);
  125. void removeBuilding(BuildingID building);//FIXME: not tested!!!
  126. void show(SDL_Surface * to) override;
  127. void showAll(SDL_Surface * to) override;
  128. };
  129. /// Creature info window
  130. class CCreaInfo : public CIntObject
  131. {
  132. const CGTownInstance * town;
  133. const CCreature *creature;
  134. int level;
  135. bool showAvailable;
  136. CAnimImage *picture;
  137. CLabel * label;
  138. int AddToString(std::string from, std::string & to, int numb);
  139. std::string genGrowthText();
  140. public:
  141. CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false);
  142. void update();
  143. void hover(bool on) override;
  144. void clickLeft(tribool down, bool previousState) override;
  145. void clickRight(tribool down, bool previousState) override;
  146. };
  147. /// Town hall and fort icons for town screen
  148. class CTownInfo : public CIntObject
  149. {
  150. const CGTownInstance *town;
  151. const CBuilding *building;
  152. public:
  153. CAnimImage * picture;
  154. //if (townHall) hall-capital else fort - castle
  155. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  156. void hover(bool on) override;
  157. void clickRight(tribool down, bool previousState) override;
  158. };
  159. /// Class which manages the castle window
  160. class CCastleInterface : public CWindowObject, public CWindowWithGarrison
  161. {
  162. CLabel *title;
  163. CLabel *income;
  164. CAnimImage *icon;
  165. CPicture * panel;
  166. CResDataBar *resdatabar;
  167. CGStatusBar * statusbar;
  168. CTownInfo *hall, *fort;
  169. CButton *exit;
  170. CButton *split;
  171. CButton * fastArmyPurhase;
  172. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  173. public:
  174. CTownList * townlist;
  175. //TODO: move to private
  176. const CGTownInstance * town;
  177. HeroSlots *heroes;
  178. CCastleBuildings *builds;
  179. //from - previously selected castle (if any)
  180. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr);
  181. ~CCastleInterface();
  182. void castleTeleport(int where);
  183. void townChange();
  184. void keyPressed(const SDL_KeyboardEvent & key) override;
  185. void close();
  186. void addBuilding(BuildingID bid);
  187. void removeBuilding(BuildingID bid);
  188. void recreateIcons();
  189. };
  190. /// Hall window where you can build things
  191. class CHallInterface : public CWindowObject
  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. ui32 state;//Buildings::EBuildStructure enum
  199. public:
  200. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  201. void hover(bool on) override;
  202. void clickLeft(tribool down, bool previousState) override;
  203. void clickRight(tribool down, bool previousState) override;
  204. };
  205. const CGTownInstance * town;
  206. std::vector< std::vector<CBuildingBox*> >boxes;
  207. CLabel *title;
  208. CGStatusBar *statusBar;
  209. CMinorResDataBar * resdatabar;
  210. CButton *exit;
  211. public:
  212. CHallInterface(const CGTownInstance * Town);
  213. };
  214. /// Window where you can decide to buy a building or not
  215. class CBuildWindow: public CWindowObject
  216. {
  217. const CGTownInstance *town;
  218. const CBuilding *building;
  219. std::string getTextForState(int state);
  220. void buyFunc();
  221. public:
  222. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick);
  223. };
  224. //Small class to display
  225. class LabeledValue : public CIntObject
  226. {
  227. std::string hoverText;
  228. CLabel *name;
  229. CLabel *value;
  230. void init(std::string name, std::string descr, int min, int max);
  231. public:
  232. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  233. LabeledValue(Rect size, std::string name, std::string descr, int val);
  234. void hover(bool on) override;
  235. };
  236. /// The fort screen where you can afford units
  237. class CFortScreen : public CWindowObject
  238. {
  239. class RecruitArea : public CIntObject
  240. {
  241. const CGTownInstance *town;
  242. int level;
  243. std::string hoverText;
  244. CLabel * availableCount;
  245. std::vector<LabeledValue*> values;
  246. CPicture *icons;
  247. const CCreature * getMyCreature();
  248. const CBuilding * getMyBuilding();
  249. public:
  250. RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
  251. void creaturesChanged();
  252. void hover(bool on) override;
  253. void clickLeft(tribool down, bool previousState) override;
  254. void clickRight(tribool down, bool previousState) override;
  255. };
  256. CLabel *title;
  257. std::vector<RecruitArea*> recAreas;
  258. CMinorResDataBar * resdatabar;
  259. CGStatusBar *statusBar;
  260. CButton *exit;
  261. std::string getBgName(const CGTownInstance *town);
  262. public:
  263. CFortScreen(const CGTownInstance * town);
  264. void creaturesChanged();
  265. };
  266. /// The mage guild screen where you can see which spells you have
  267. class CMageGuildScreen : public CWindowObject
  268. {
  269. class Scroll : public CIntObject
  270. {
  271. const CSpell *spell;
  272. CAnimImage *image;
  273. public:
  274. Scroll(Point position, const CSpell *Spell);
  275. void clickLeft(tribool down, bool previousState) override;
  276. void clickRight(tribool down, bool previousState) override;
  277. void hover(bool on) override;
  278. };
  279. CPicture *window;
  280. CButton *exit;
  281. std::vector<Scroll *> spells;
  282. CMinorResDataBar * resdatabar;
  283. CGStatusBar *statusBar;
  284. public:
  285. CMageGuildScreen(CCastleInterface * owner,std::string image);
  286. };
  287. /// The blacksmith window where you can buy available in town war machine
  288. class CBlacksmithDialog : public CWindowObject
  289. {
  290. CButton *buy, *cancel;
  291. CPicture *animBG;
  292. CCreatureAnim * anim;
  293. CLabel * title;
  294. CLabel * costText;
  295. CLabel * costValue;
  296. CGStatusBar *statusBar;
  297. public:
  298. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  299. };