CCastleInterface.h 11 KB

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