CCastleInterface.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 buildingClicked(BuildingID building);
  123. void addBuilding(BuildingID building);
  124. void removeBuilding(BuildingID building);//FIXME: not tested!!!
  125. void show(SDL_Surface * to) override;
  126. void showAll(SDL_Surface * to) override;
  127. };
  128. /// Creature info window
  129. class CCreaInfo : public CIntObject
  130. {
  131. const CGTownInstance * town;
  132. const CCreature *creature;
  133. int level;
  134. bool showAvailable;
  135. CAnimImage *picture;
  136. CLabel * label;
  137. int AddToString(std::string from, std::string & to, int numb);
  138. std::string genGrowthText();
  139. public:
  140. CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false);
  141. void update();
  142. void hover(bool on) override;
  143. void clickLeft(tribool down, bool previousState) override;
  144. void clickRight(tribool down, bool previousState) override;
  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) override;
  156. void clickRight(tribool down, bool previousState) override;
  157. };
  158. /// Class which manages the castle window
  159. class CCastleInterface : public CWindowObject, 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. CButton *exit;
  169. CButton *split;
  170. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  171. public:
  172. CTownList * townlist;
  173. //TODO: move to private
  174. const CGTownInstance * town;
  175. HeroSlots *heroes;
  176. CCastleBuildings *builds;
  177. //from - previously selected castle (if any)
  178. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr);
  179. ~CCastleInterface();
  180. void castleTeleport(int where);
  181. void townChange();
  182. void keyPressed(const SDL_KeyboardEvent & key) override;
  183. void close();
  184. void addBuilding(BuildingID bid);
  185. void removeBuilding(BuildingID bid);
  186. void recreateIcons();
  187. };
  188. /// Hall window where you can build things
  189. class CHallInterface : public CWindowObject
  190. {
  191. /// Building box from town hall (building icon + subtitle)
  192. class CBuildingBox : public CIntObject
  193. {
  194. const CGTownInstance * town;
  195. const CBuilding * building;
  196. ui32 state;//Buildings::EBuildStructure enum
  197. public:
  198. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  199. void hover(bool on) override;
  200. void clickLeft(tribool down, bool previousState) override;
  201. void clickRight(tribool down, bool previousState) override;
  202. };
  203. const CGTownInstance * town;
  204. std::vector< std::vector<CBuildingBox*> >boxes;
  205. CLabel *title;
  206. CGStatusBar *statusBar;
  207. CMinorResDataBar * resdatabar;
  208. CButton *exit;
  209. public:
  210. CHallInterface(const CGTownInstance * Town);
  211. };
  212. /// Window where you can decide to buy a building or not
  213. class CBuildWindow: public CWindowObject
  214. {
  215. const CGTownInstance *town;
  216. const CBuilding *building;
  217. std::string getTextForState(int state);
  218. void buyFunc();
  219. public:
  220. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick);
  221. };
  222. //Small class to display
  223. class LabeledValue : public CIntObject
  224. {
  225. std::string hoverText;
  226. CLabel *name;
  227. CLabel *value;
  228. void init(std::string name, std::string descr, int min, int max);
  229. public:
  230. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  231. LabeledValue(Rect size, std::string name, std::string descr, int val);
  232. void hover(bool on) override;
  233. };
  234. /// The fort screen where you can afford units
  235. class CFortScreen : public CWindowObject
  236. {
  237. class RecruitArea : public CIntObject
  238. {
  239. const CGTownInstance *town;
  240. int level;
  241. std::string hoverText;
  242. CLabel * availableCount;
  243. std::vector<LabeledValue*> values;
  244. CPicture *icons;
  245. const CCreature * getMyCreature();
  246. const CBuilding * getMyBuilding();
  247. public:
  248. RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
  249. void creaturesChanged();
  250. void hover(bool on) override;
  251. void clickLeft(tribool down, bool previousState) override;
  252. void clickRight(tribool down, bool previousState) override;
  253. };
  254. CLabel *title;
  255. std::vector<RecruitArea*> recAreas;
  256. CMinorResDataBar * resdatabar;
  257. CGStatusBar *statusBar;
  258. CButton *exit;
  259. std::string getBgName(const CGTownInstance *town);
  260. public:
  261. CFortScreen(const CGTownInstance * town);
  262. void creaturesChanged();
  263. };
  264. /// The mage guild screen where you can see which spells you have
  265. class CMageGuildScreen : public CWindowObject
  266. {
  267. class Scroll : public CIntObject
  268. {
  269. const CSpell *spell;
  270. CAnimImage *image;
  271. public:
  272. Scroll(Point position, const CSpell *Spell);
  273. void clickLeft(tribool down, bool previousState) override;
  274. void clickRight(tribool down, bool previousState) override;
  275. void hover(bool on) override;
  276. };
  277. CPicture *window;
  278. CButton *exit;
  279. std::vector<Scroll *> spells;
  280. CMinorResDataBar * resdatabar;
  281. CGStatusBar *statusBar;
  282. public:
  283. CMageGuildScreen(CCastleInterface * owner,std::string image);
  284. };
  285. /// The blacksmith window where you can buy available in town war machine
  286. class CBlacksmithDialog : public CWindowObject
  287. {
  288. CButton *buy, *cancel;
  289. CPicture *animBG;
  290. CCreatureAnim * anim;
  291. CLabel * title;
  292. CLabel * costText;
  293. CLabel * costValue;
  294. CGStatusBar *statusBar;
  295. public:
  296. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  297. };