CCastleInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #pragma once
  2. #include "../widgets/CGarrisonInt.h"
  3. #include "../widgets/Images.h"
  4. class CButton;
  5. class CBuilding;
  6. class CCastleBuildings;
  7. class CCreaturePic;
  8. class CGStatusBar;
  9. class CGTownInstance;
  10. class CLabel;
  11. class CMinorResDataBar;
  12. class CPicture;
  13. class CResDataBar;
  14. class CSpell;
  15. class CTextBox;
  16. class CTownList;
  17. struct CStructure;
  18. class CGHeroInstance;
  19. class CGarrisonInt;
  20. class CCreature;
  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. 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); //c-tor
  44. ~CBuildingRect(); //d-tor
  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); //c-tor
  82. ~CHeroGSlot(); //d-tor
  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: 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. //from - previously selected castle (if any)
  180. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr); //c-tor
  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. 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) override;
  206. void clickLeft(tribool down, bool previousState) override;
  207. void clickRight(tribool down, bool previousState) override;
  208. };
  209. const CGTownInstance * town;
  210. std::vector< std::vector<CBuildingBox*> >boxes;
  211. CLabel *title;
  212. CGStatusBar *statusBar;
  213. CMinorResDataBar * resdatabar;
  214. CButton *exit;
  215. public:
  216. CHallInterface(const CGTownInstance * Town); //c-tor
  217. };
  218. /// Window where you can decide to buy a building or not
  219. class CBuildWindow: public CWindowObject
  220. {
  221. const CGTownInstance *town;
  222. const CBuilding *building;
  223. CButton *buy;
  224. CButton *cancel;
  225. std::string getTextForState(int state);
  226. void buyFunc();
  227. public:
  228. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); //c-tor
  229. };
  230. //Small class to display
  231. class LabeledValue : public CIntObject
  232. {
  233. std::string hoverText;
  234. CLabel *name;
  235. CLabel *value;
  236. void init(std::string name, std::string descr, int min, int max);
  237. public:
  238. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  239. LabeledValue(Rect size, std::string name, std::string descr, int val);
  240. void hover(bool on) override;
  241. };
  242. /// The fort screen where you can afford units
  243. class CFortScreen : public CWindowObject
  244. {
  245. class RecruitArea : public CIntObject
  246. {
  247. const CGTownInstance *town;
  248. int level;
  249. std::string hoverText;
  250. CLabel * creatureName;
  251. CLabel * dwellingName;
  252. CLabel * availableCount;
  253. std::vector<LabeledValue*> values;
  254. CPicture *icons;
  255. CAnimImage * buildingPic;
  256. CCreaturePic *creatureAnim;
  257. const CCreature * getMyCreature();
  258. const CBuilding * getMyBuilding();
  259. public:
  260. RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
  261. void creaturesChanged();
  262. void hover(bool on) override;
  263. void clickLeft(tribool down, bool previousState) override;
  264. void clickRight(tribool down, bool previousState) override;
  265. };
  266. CLabel *title;
  267. std::vector<RecruitArea*> recAreas;
  268. CMinorResDataBar * resdatabar;
  269. CGStatusBar *statusBar;
  270. CButton *exit;
  271. std::string getBgName(const CGTownInstance *town);
  272. public:
  273. CFortScreen(const CGTownInstance * town); //c-tor
  274. void creaturesChanged();
  275. };
  276. /// The mage guild screen where you can see which spells you have
  277. class CMageGuildScreen : public CWindowObject
  278. {
  279. class Scroll : public CIntObject
  280. {
  281. const CSpell *spell;
  282. CAnimImage *image;
  283. public:
  284. Scroll(Point position, const CSpell *Spell);
  285. void clickLeft(tribool down, bool previousState) override;
  286. void clickRight(tribool down, bool previousState) override;
  287. void hover(bool on) override;
  288. };
  289. CPicture *window;
  290. CButton *exit;
  291. std::vector<Scroll *> spells;
  292. CMinorResDataBar * resdatabar;
  293. CGStatusBar *statusBar;
  294. public:
  295. CMageGuildScreen(CCastleInterface * owner,std::string image);
  296. };
  297. /// The blacksmith window where you can buy available in town war machine
  298. class CBlacksmithDialog : public CWindowObject
  299. {
  300. CButton *buy, *cancel;
  301. CPicture *animBG;
  302. CCreatureAnim * anim;
  303. CLabel * title;
  304. CLabel * costText;
  305. CLabel * costValue;
  306. CGStatusBar *statusBar;
  307. public:
  308. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  309. };