CCastleInterface.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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(BuildingID building);//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);
  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 CWindowObject, 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<CGStatusBar> statusbar;
  171. std::shared_ptr<CTownInfo> hall;
  172. std::shared_ptr<CTownInfo> fort;
  173. std::shared_ptr<CButton> exit;
  174. std::shared_ptr<CButton> split;
  175. std::shared_ptr<CButton> fastArmyPurhase;
  176. std::vector<std::shared_ptr<CCreaInfo>> creainfo;//small icons of creatures (bottom-left corner);
  177. public:
  178. std::shared_ptr<CTownList> townlist;
  179. //TODO: move to private
  180. const CGTownInstance * town;
  181. std::shared_ptr<HeroSlots> heroes;
  182. std::shared_ptr<CCastleBuildings> builds;
  183. std::shared_ptr<CGarrisonInt> garr;
  184. //from - previously selected castle (if any)
  185. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr);
  186. ~CCastleInterface();
  187. virtual void updateGarrisons() override;
  188. void castleTeleport(int where);
  189. void townChange();
  190. void keyPressed(const SDL_KeyboardEvent & key) override;
  191. void close();
  192. void addBuilding(BuildingID bid);
  193. void removeBuilding(BuildingID bid);
  194. void recreateIcons();
  195. };
  196. /// Hall window where you can build things
  197. class CHallInterface : public CWindowObject
  198. {
  199. class CBuildingBox : public CIntObject
  200. {
  201. const CGTownInstance * town;
  202. const CBuilding * building;
  203. ui32 state;//Buildings::EBuildStructure enum
  204. std::shared_ptr<CAnimImage> header;
  205. std::shared_ptr<CAnimImage> icon;
  206. std::shared_ptr<CAnimImage> mark;
  207. std::shared_ptr<CLabel> name;
  208. public:
  209. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  210. void hover(bool on) override;
  211. void clickLeft(tribool down, bool previousState) override;
  212. void clickRight(tribool down, bool previousState) override;
  213. };
  214. const CGTownInstance * town;
  215. std::vector<std::vector<std::shared_ptr<CBuildingBox>>> boxes;
  216. std::shared_ptr<CLabel> title;
  217. std::shared_ptr<CMinorResDataBar> resdatabar;
  218. std::shared_ptr<CGStatusBar> statusbar;
  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 CWindowObject
  225. {
  226. const CGTownInstance * town;
  227. const CBuilding * building;
  228. std::shared_ptr<CAnimImage> icon;
  229. std::shared_ptr<CGStatusBar> statusbar;
  230. std::shared_ptr<CLabel> name;
  231. std::shared_ptr<CTextBox> description;
  232. std::shared_ptr<CTextBox> stateText;
  233. std::shared_ptr<CComponentBox> cost;
  234. std::shared_ptr<CButton> buy;
  235. std::shared_ptr<CButton> cancel;
  236. std::string getTextForState(int state);
  237. void buyFunc();
  238. public:
  239. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick);
  240. };
  241. //Small class to display
  242. class LabeledValue : public CIntObject
  243. {
  244. std::string hoverText;
  245. std::shared_ptr<CLabel> name;
  246. std::shared_ptr<CLabel> value;
  247. void init(std::string name, std::string descr, int min, int max);
  248. public:
  249. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  250. LabeledValue(Rect size, std::string name, std::string descr, int val);
  251. void hover(bool on) override;
  252. };
  253. /// The fort screen where you can afford units
  254. class CFortScreen : public CWindowObject
  255. {
  256. class RecruitArea : public CIntObject
  257. {
  258. const CGTownInstance * town;
  259. int level;
  260. std::string hoverText;
  261. std::shared_ptr<CLabel> availableCount;
  262. std::vector<std::shared_ptr<LabeledValue>> values;
  263. std::shared_ptr<CPicture> icons;
  264. std::shared_ptr<CAnimImage> buildingIcon;
  265. std::shared_ptr<CLabel> buildingName;
  266. const CCreature * getMyCreature();
  267. const CBuilding * getMyBuilding();
  268. public:
  269. RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
  270. void creaturesChanged();
  271. void hover(bool on) override;
  272. void clickLeft(tribool down, bool previousState) override;
  273. void clickRight(tribool down, bool previousState) override;
  274. };
  275. std::shared_ptr<CLabel> title;
  276. std::vector<std::shared_ptr<RecruitArea>> recAreas;
  277. std::shared_ptr<CMinorResDataBar> resdatabar;
  278. std::shared_ptr<CGStatusBar> statusbar;
  279. std::shared_ptr<CButton> exit;
  280. std::string getBgName(const CGTownInstance * town);
  281. public:
  282. CFortScreen(const CGTownInstance * town);
  283. void creaturesChanged();
  284. };
  285. /// The mage guild screen where you can see which spells you have
  286. class CMageGuildScreen : public CWindowObject
  287. {
  288. class Scroll : public CIntObject
  289. {
  290. const CSpell * spell;
  291. std::shared_ptr<CAnimImage> image;
  292. public:
  293. Scroll(Point position, const CSpell *Spell);
  294. void clickLeft(tribool down, bool previousState) override;
  295. void clickRight(tribool down, bool previousState) override;
  296. void hover(bool on) override;
  297. };
  298. std::shared_ptr<CPicture> window;
  299. std::shared_ptr<CButton> exit;
  300. std::vector<std::shared_ptr<Scroll>> spells;
  301. std::vector<std::shared_ptr<CAnimImage>> emptyScrolls;
  302. std::shared_ptr<CMinorResDataBar> resdatabar;
  303. std::shared_ptr<CGStatusBar> statusbar;
  304. public:
  305. CMageGuildScreen(CCastleInterface * owner,std::string image);
  306. };
  307. /// The blacksmith window where you can buy available in town war machine
  308. class CBlacksmithDialog : public CWindowObject
  309. {
  310. std::shared_ptr<CButton> buy;
  311. std::shared_ptr<CButton> cancel;
  312. std::shared_ptr<CPicture> animBG;
  313. std::shared_ptr<CCreatureAnim> anim;
  314. std::shared_ptr<CLabel> title;
  315. std::shared_ptr<CAnimImage> costIcon;
  316. std::shared_ptr<CLabel> costText;
  317. std::shared_ptr<CLabel> costValue;
  318. std::shared_ptr<CGStatusBar> statusbar;
  319. public:
  320. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  321. };