CCastleInterface.h 11 KB

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