CCastleInterface.h 12 KB

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